On Sun, 17 Nov 2013, Florian Weimer wrote:

* Jonathan Wakely:

On 17 November 2013 18:25, Dominic News wrote:
In the following code (from xorg-server)

    if (a == 0)
        addr = 0;
    (...)
    memset(addr, '\0', a);

the path for a==0 is turned into a trap by -fisolate-erroneous-paths. (Is
calling memset like this undefined behaviour?)

Yes. 7.23.1 in the C standard says that even with a zero size the
pointer argument must be valid.

Is this new in C11?  Does it apply to functions such as strnlen as well?

It was already in C99 (I don't have anything older at hand), a paragraph at the beginning of the description of string.h. It does not apply to strnlen_s. For strnlen, which is only in posix, I am not sure, but glibc has the nonnull attribute.

--
Marc Glisse

Reply via email to