<div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote">On Tue, Jun 2, 2015 at 2:12 AM, David Chisnall <span dir="ltr"><<a href="mailto:David.Chisnall@cl.cam.ac.uk" target="_blank">David.Chisnall@cl.cam.ac.uk</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><span class="">On 1 Jun 2015, at 18:52, Marshall Clow <<a href="mailto:mclow.lists@gmail.com">mclow.lists@gmail.com</a>> wrote:<br>
><br>
>> The generic entry text of the standard section. IMO this is a standard<br>
>> bug and someone should *please* get it fixed. It is ridiculous that zero<br>
>> sized operations are considered UB.<br>
><br>
> That would require a change to the C standard, and, as far as I know, there are no current plans to issue a revised C standard.<br>
<br>
</span>Not necessarily.  Other standards, such as POSIX, are free to define behaviour that is undefined or implementation defined in C.  POSIX mandates that a char is exactly 8 bits, for example, which is IB in C.  The goal of UB is to give freedom to implementors.  Saying that NULL arguments to memcpy are UB does not mean that we are compelled to disallow them, it just means that:<br>
<br>
- We don’t have to accept them.<br>
- We don’t have to be consistent in whether we accept or reject them.<br>
- We can choose to do whatever makes implementation easiest.<br>
<br>
If the easiest thing is to permit them as long as the length is zero (it seems to be), then that’s a perfectly valid implementation of undefined behaviour.<br></blockquote><div><br></div><div>Heh. There are no "invalid implementations" of undefined behavior.</div><div><br></div><div>The reason I proposed this change was to allow UBSAN to detect undefined behavior, and report it to users - rather than having their code (potentially) fail in hard-to-diagnose ways when they change *something* (refactor code, change compilers, change optimization level, etc).</div><div><br></div><div><br></div><div>-- Marshall</div><div><br></div></div></div></div>