Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!zaphod.mps.ohio-state.edu!unix.cis.pitt.edu!dsinc!bagate!cbmvax!cbmehq!cbmdeo!jsmami!jsmoller From: jsmoller@jsmami.UUCP (Jesper Steen Moller) Newsgroups: comp.sys.amiga.programmer Subject: Re: Compiler code (was a flame fest) Message-ID: <18f264ed.ARN1294@jsmami.UUCP> Date: 7 Apr 91 04:44:33 GMT References: <1991Apr2.100807.13471@ux1.cso.uiuc.edu> <1991Apr3.042457.3703@mintaka.lcs.mit.edu> <2923@wn1.sci.kun.nl> Reply-To: cbmehq!cbmdeo!jsmami!jsmoller (Jesper S. Moller) Followup-To: comp.sys.amiga.programmer Organization: Danish SofTech Lines: 49 In article <2923@wn1.sci.kun.nl>, Olaf'Rhialto'Seibert writes: > In article <1991Apr3.042457.3703@mintaka.lcs.mit.edu> someone writes: > >>CopyString(s,d) > >>char *s,*d; > >>{ > >> while(*s) { *d++=*s++; } > >>} > > Note that this function has an incorrect name. In C, a string is 0-terminated. > This does not copy the 0, so the copy is not a string. > > This bug was already present in the very first program that started this > discussion, and I doubt the author was aware of this subtle but > dangerous bug. Hmm, I think it was in order to fool the reader (and esp. the not C minded...) - the produced code (commented by the poster cut it out in cardboard, actually. The function is useful, actually, if concatenating a lot of strings into one, and you don't want the \0-pad overhead. char *stradd(d,s) /* All the good names are taken */ /* please note that dst, src is far more standard */ /* than src,dst */ { while(*s) { *d++=*s++; } return d; /* return updated destination pointer */ } The caller should use d=stradd(d,s); and finish off with a *d="\0"; /* or d[0]=0; to be cryptic ;-) */ But on the other hand, I might be mistaken. ;) Jesper > Olaf 'Rhialto' Seibert rhialto@cs.kun.nl -- __ Jesper Steen Moller /// VOICE: +45 31 62 46 45 Maglemosevej 52 __ /// USENET: cbmehq!cbmdeo!jsmoller DK-2920 Charl \\\/// FIDONET: 2:231/84.45 Denmark \XX/