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: Sat, 22 Oct 2016 16:33:23 -0700 Organization: None to speak of Lines: 40 Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit Injection-Info: mx02.eternal-september.org; posting-host="81aeb6e1d8cfc6206f4b7e00ede7a09e"; logging-data="11046"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19pZAP8W38L8zELm/u5QXMx" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1 (gnu/linux) Cancel-Lock: sha1:thLiebVcGFIFeCX1CKu3tIidaKM= sha1:iWLY+EbUS9Lkkuaz+iuIB4CUl9Y= Xref: csiph.com comp.lang.c:95154 Lőrinczy Zsigmond writes: > That might be very true, but not really relevant > when talking about the standard describing > function 'memcpy' What might be very true? Please quote some context from the article you're replying to. > IMHO it could mention that reading from unreadable address, > or writing into unwriteable address is UB, > but that is true for every function dealing with pointers. > > I think, important points would be these: > > * if len==0, memcpy should do nothing That would have been a reasonable definition, but it's not what the standard says. Your opinion that it *should* do nothing in that case is a perfectly valid one, but it's not one that everyone shares. Personally, I have no particular problem with memcpy(NULL, NULL, 0) having undefined behavior. I've never written non-contrived code that would be affected by it, and if I needed to I'd simply add an if statement and move on. > * if the from-area and to-area overlap, it is UB Already specified. > * if from+len 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"