Path: utzoo!utgpu!water!watmath!clyde!bellcore!faline!sabre!gamma!pyuxp!pyuxe!pyuxf!robf2 From: robf2@pyuxf.UUCP (robert fair) Newsgroups: comp.sys.ibm.pc Subject: Re: bug in Turbo C 1.5 Summary: Its ANSI s[draft] standard... Message-ID: <247@pyuxf.UUCP> Date: 26 Jan 88 20:15:24 GMT References: <5298@cit-vax.Caltech.Edu> Organization: Bell Communications Research Lines: 53 In article <5298@cit-vax.Caltech.Edu>, tim@cit-vax.UUCP writes: # To the best of my recollection, I don't recall having seen any bug # reports so far for Turbo C 1.5. Am I the first person to report a # bug in Turbo C 1.5? # # This program # # ---------------------------------- # #include # # void main() { # char *s = "this is a test"; # printf("%s\n", s); # memcpy(s + 1, s, strlen(s) - 1); # printf("%s\n", s); # } # ---------------------------------- # # displays # # -------------- # this is a test # tthis is a tes # -------------- # # under Turbo C 1.0, and # # -------------- # this is a test # tthhssii ee # -------------- # # under Turbo C 1.5. This is precisely correct behaviour - the action of memcpy() on overlapping regions is undefined in the draft ANSI standard. It looks like Borland took advantage of this to do memcpy() faster, but it only works on non-overlapping areas. Simply don't use memcpy() on overlapping regions. There should be a function which does what you want if Turbo is a decent compiler. Incidently MSC memcpy() changed in *exactly* the same way from 4.0 to 5.0 - but at leat Microsoft documented the change and provided a function which worked in the old way for compatibility [ memmove() ] Personally I think the entire thing sucks - the function should be able to detect overlapping areas and take special action in such cases :( - -- Robert L. Fair Bell Communications Research/CHC Piscataway, NJ {ihnp4,allegra}!pyuxww!pyuxf!robf2