From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,86fd56abf3579c34 X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 1995-03-23 01:52:35 PST Newsgroups: comp.lang.ada Path: nntp.gmd.de!news.rwth-aachen.de!news.rhrz.uni-bonn.de!RRZ.Uni-Koeln.DE!uni-duisburg.de!zib-berlin.de!news.mathworks.com!zombie.ncsc.mil!news.duke.edu!godot.cc.duq.edu!newsfeed.pitt.edu!gatech!howland.reston.ans.net!news.sprintlink.net!crash!telesoft!kst From: kst@thomsoft.com (Keith Thompson) Subject: Re: Should internet support software be written in Ada? X-Nntp-Posting-Host: pulsar Message-ID: Originator: kst@pulsar Sender: news@thomsoft.com (USENET News Admin @flash) Organization: Thomson Software Products, San Diego, CA, USA References: <3kaksj$iur@isnews.calpoly.edu> Distribution: usa Date: Wed, 22 Mar 1995 23:08:26 GMT Date: 1995-03-22T23:08:26+00:00 List-Id: Bill Brooks wrote: > */ > if (strchr(mapname,'/')) { > strcpy(conf,getenv("PATH_TRANSLATED")); > goto openconf; > } > > if ((fp = fopen(CONF_FILE, "r")) == NULL) > servererr(strcat("Couldn't open configuration file:", CONF_FILE)); > > while(!(getline(input,MAXLINE,fp))) { > char confname[MAXLINE]; > if((input[0] == '#') || (!input[0])) > continue; > for(i=0;isname(input[i]) && (input[i] != ':');i++) > confname[i] = input[i]; > confname[i] = '\0'; > if(!strcmp(confname,mapname)) > goto found; > } > ----------------------- end paste --------------------------- > In the rich tradition of discussing good software engineering practices in > c.l.a(regardless of language) I'll ask: is this good coding style? > Keep in mind that this code was written under the auspices of one of > the top 5 schools in CS in the United States. Whether it's good style or not, it's incorrect. The strcat() function modifies its first parameter (more precisely, its first parameter is a pointer and it modifies what it points to). In the statement > servererr(strcat("Couldn't open configuration file:", CONF_FILE)); the first parameter is a string literal. Result: the statement writes the value of CONF_FILE immediately after wherever the compiler decided to store the value for the string literal. As it happens, this is unlikely to cause the program to fail visibly (the line is executed only when the configuration file can't be opened, and the program probably terminates immediately afterward). Perhaps someone who knows where this code came from (I've lost the original article) should notify the authors. -- Keith Thompson (The_Other_Keith) kst@thomsoft.com (kst@alsys.com still works) TeleSoft^H^H^H^H^H^H^H^H Alsys^H^H^H^H^H Thomson Software Products 10251 Vista Sorrento Parkway, Suite 300, San Diego, CA, USA, 92121-2718 That's Keith Thompson *with* a 'p', Thomson Software Products *without* a 'p'.