chris@mimsy.umd.edu (Chris Torek) (02/18/90)
In article <497@thirdi.UUCP> peter@thirdi.UUCP (Peter Rowell) writes: >WARNING! memcpy is NOT the same as bcopy!!!! >This is the source of an *amazing* array of hard-to-find bugs! >bcopy correctly handles overlapping memory moves; memcpy does not. Beware: some versions of bcopy() do, some do not. (4.2BSD VAX bcopy() handled overlap when copying 65535 bytes or less or when forward block moves were correct. 4.3BSD VAX bcopy() always handles overlap.) For absolute safety, use memmove() (a feature of ANSI X3.159 C). Followups directed to comp.lang.c (put them somewhere else if not talking about the C aspects of overlapping moves, please). -- In-Real-Life: Chris Torek, Univ of MD Comp Sci Dept (+1 301 454 7163) Domain: chris@cs.umd.edu Path: uunet!mimsy!chris
konath@sj.ate.slb.com (Kannan Konath) (02/24/90)
In article <22599@mimsy.umd.edu> chris@mimsy.umd.edu (Chris Torek) writes: >In article <497@thirdi.UUCP> peter@thirdi.UUCP (Peter Rowell) writes: >>WARNING! memcpy is NOT the same as bcopy!!!! >>This is the source of an *amazing* array of hard-to-find bugs! >>bcopy correctly handles overlapping memory moves; memcpy does not. > >Beware: some versions of bcopy() do, some do not. (4.2BSD VAX bcopy() >handled overlap when copying 65535 bytes or less or when forward block >moves were correct. 4.3BSD VAX bcopy() always handles overlap.) > >For absolute safety, use memmove() (a feature of ANSI X3.159 C). In the VAX-VMS-C manual, it states that memmove() has exactly the same functionality as memcpy(). Does that mean memmove() does not handle overlapped moves or does that mean memcpy() handles overlapped moves. This problem arose when bcopy() was used in a program that was being ported to the VMS environemnt. I am not involved in the porting directly but when going through the semantics of the different block copy and block move instructions in the Harbison-Steele manual and the VMS-C manual I noticed this was not stated explicitly in the latter. >In-Real-Life: Chris Torek, Univ of MD Comp Sci Dept (+1 301 454 7163) >Domain: chris@cs.umd.edu Path: uunet!mimsy!chris kannan konath@sj.ate.slb.com
henry@utzoo.uucp (Henry Spencer) (02/25/90)
In article <1990Feb23.225358.375@sj.ate.slb.com> konath@sj.ate.slb.com (Kannan Konath) writes: >In the VAX-VMS-C manual, it states that memmove() has exactly the same >functionality as memcpy(). Does that mean memmove() does not handle >overlapped moves or does that mean memcpy() handles overlapped moves. ANSI C memcpy must not be handed overlapping arguments, whereas ANSI C memmove is required to handle them correctly. How this corresponds to VAX VMS C is another question entirely. -- "The N in NFS stands for Not, | Henry Spencer at U of Toronto Zoology or Need, or perhaps Nightmare"| uunet!attcan!utzoo!henry henry@zoo.toronto.edu
scjones@sdrc.UUCP (Larry Jones) (03/02/90)
In article <1990Feb23.225358.375@sj.ate.slb.com>, konath@sj.ate.slb.com (Kannan Konath) writes: > In the VAX-VMS-C manual, it states that memmove() has exactly the same > functionality as memcpy(). Does that mean memmove() does not handle > overlapped moves or does that mean memcpy() handles overlapped moves. Both handle overlapped moves correctly. The documentation doesn't come right out and say it like it should, but it implies it by saying "Programs that require portability should use memmove if the area pointed at by s1 could overlap the area pointed at by s2." (At least this is the intent -- the original implementation was defective for moves over 64k bytes, but I'm pretty sure that has been fixed for quite awhile now.) ---- Larry Jones UUCP: uunet!sdrc!scjones SDRC scjones@SDRC.UU.NET 2000 Eastman Dr. BIX: ltl Milford, OH 45150-2789 AT&T: (513) 576-2070 "You know how Einstein got bad grades as a kid? Well MINE are even WORSE!" -Calvin
scott@stl.stc.co.uk (Mike Scott) (03/03/90)
In article <1990Feb24.233833.14129@utzoo.uucp> henry@utzoo.uucp (Henry Spencer) writes: >In article <1990Feb23.225358.375@sj.ate.slb.com> konath@sj.ate.slb.com (Kannan Konath) writes: >>In the VAX-VMS-C manual, it states that memmove() has exactly the same >>functionality as memcpy(). Does that mean memmove() does not handle >>overlapped moves or does that mean memcpy() handles overlapped moves. > >ANSI C memcpy must not be handed overlapping arguments, whereas ANSI C >memmove is required to handle them correctly. How this corresponds to >VAX VMS C is another question entirely. from the VAXC 3.0 manual: " In VAXC, memmove and memcpy perform the same function. Programs that require portability should use memmove if the area pointed at by ... could overlap the area pointed at by..." So the implication is that both functions cope 'properly' with overlapping objects on VMS. -- Regards. Mike Scott STL, London Road, Harlow, Essex CM17 9NA, UK scott@stl.stc.co.uk <or> ...uunet!mcsun!ukc!stl!scott <or> PSI%234237100122::SCOTT phone +44-279-29531 xtn 3133.