Path: csiph.com!eternal-september.org!feeder.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail From: Keith Thompson Newsgroups: comp.lang.c Subject: Re: UB of memcpy(NULL, NULL, 0) Date: Mon, 24 Oct 2016 08:38:36 -0700 Organization: None to speak of Lines: 31 Message-ID: References: <7aec2d7f-6f2d-4621-9f98-91947f461f27@googlegroups.com> <18bf4226-5b9a-4603-9809-47cdd83cc16a@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit Injection-Info: mx02.eternal-september.org; posting-host="dc97ebc10d9ee65592f107439c98c97d"; logging-data="23225"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+xAA00drabd3L7iJdofpS+" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1 (gnu/linux) Cancel-Lock: sha1:0oHEh5AoDPqC1p1zLUdIAKQGkHU= sha1:H4z8763du9HYzPZFGHgtYPdbWO0= Xref: csiph.com comp.lang.c:95227 supercat@casperkitty.com writes: > On Sunday, October 23, 2016 at 10:46:04 AM UTC-5, Lőrinczy Zsigmond wrote: >> Well, world is full of old systems; >> you can find WindowsXP's and AIX5.3's everywhere... >> So from now on (or since c99), if you want to write programs >> that run everywhere, you cannot expect memcpy to hande len==0 >> properly, even if it were to be fixed in a later version. > > There exists some date prior to which no implementation targeting the x86 > architecture would treat memcpy(any,any,0) as anything other than a NOP, > nor treat memcpy(same,same,any) as having any effects which would differ > from those of memmove. > > If the Standard were to changed to mandate such behavior, the only problem > would be compilers written in the window between when someone got the > brilliant idea to "optimize" based on the fact that it's not a guaranteed > no-op and the time the compiler was upgraded to conform to the Standard. > Since such compiler versions are most likely buggy in other ways, making > memcpy(any,any,0) behave as no-op in all cases could easily be rolled in > with other fixes. You seem to be suggesting that there are implementations where memcpy(maybe_NULL, maybe_NULL, 0) is not a no-op. Have you actually encountered such an implementation? Of course such an implementation is permitted, but does it actually exist? -- Keith Thompson (The_Other_Keith) kst-u@mib.org Working, but not speaking, for JetHead Development, Inc. "We must do something. This is something. Therefore, we must do this." -- Antony Jay and Jonathan Lynn, "Yes Minister"