[systemd-devel] [PATCH] journal: fix against (theoretical) undefined behavior

Zbigniew Jędrzejewski-Szmek zbyszek at in.waw.pl
Mon Dec 16 20:59:29 PST 2013


On Mon, Dec 16, 2013 at 03:41:00PM -0800, Shawn Landden wrote:
> While all the libc implementations I know return NULL when memchr's size
> parameter is 0, without accessing any memory, passing NULL to memchr is
> still invalid:
> 
> C11 7.24.1p2: Where an argument declared as "size_t n" specifies the length
> of the array for a function, n can have the value zero on a call to that
> function. Unless explicitly stated otherwise in the description of a
> particular function in this subclause, pointer arguments on such a call
> shall still have valid values, as described in 7.1.4. On such a call, a
> function that locates a character finds no occurrence, a function that
> compares two character sequences returns zero, and a function that copies
> characters copies zero characters.
This analysis seems correct. Applied.

Zbyszek


More information about the systemd-devel mailing list