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: Tue, 18 Oct 2016 11:31:10 -0700 Organization: None to speak of Lines: 36 Message-ID: References: <58034cbc.2767375@news.xs4all.nl> <003e026c-0fca-40b2-ab84-2197571d165f@googlegroups.com> <3dc49e97-bb93-411f-8fe3-7cdbb6fdb70d@googlegroups.com> <1c6a99e7-93b9-4a27-9201-aa5b6e7985aa@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Injection-Info: mx02.eternal-september.org; posting-host="c0c8def25655f7556eada2283b8fecd0"; logging-data="15610"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+2NsQripNedj7/PL1NhufO" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1 (gnu/linux) Cancel-Lock: sha1:nJs5LmJy5h5TA+cl4ZpXwscD/5w= sha1:fkAoBzZZ/5rxVZj87FM1Iwxa0j0= Xref: csiph.com comp.lang.c:95073 supercat@casperkitty.com writes: > On Tuesday, October 18, 2016 at 11:14:01 AM UTC-5, Keith Thompson wrote: >> supercat writes: >> >> Consider a hypothetical implementation of memcpy() that checks its >> >> arguments, causing a segfault if either s1 or s2 is a null pointer. >> >> You would assert, I presume, that such an implementation would >> >> be non-conforming? >> >> I see you've decided to ignore that. > > The Standard does not impose any requirements upon how an implementation > processes *any* program, other than the One, which does not contain any > #error directives. So nothing memcpy could do would make an implementation > non-conforming under a literal reading of the Standard if the One Program > did not use memcpy, or did so in a way that happened to behave normally. The One Program argument is irrelevant. > I would say that treating memcpy(any,any,0) as a no-op is a behavior which > programmers should be entitled to expect from any quality implementation > which has not been specifically requested to identify ways in which a > program might fail on inferior implementations, and I would consider that > such requests are generally best handled via non-conforming modes, rendering > the question of conformance for them irrelevant. So you think the standard *should* specify that memcpy(NULL, NULL, 0) is a well defined no-op. I have no particular problem with that. And if you think the question of conformance is irrelevant, feel free not to participate in such discussions. -- 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"