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

Lennart Poettering lennart at poettering.net
Mon Dec 16 10:36:09 PST 2013


On Mon, 16.12.13 09:20, Shawn Landden (shawn at churchofgit.com) wrote:

> While all the libc implementations I know return NULL when memchr's size
> parameter is 0:
> 
> 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.
> 
> see http://llvm.org/bugs/show_bug.cgi?id=18247

Hmm? But what does that have to do with the requirements we make on our
own internal functions?

> ---
>  src/journal/journal-file.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/src/journal/journal-file.c b/src/journal/journal-file.c
> index 4009b29..59b2829 100644
> --- a/src/journal/journal-file.c
> +++ b/src/journal/journal-file.c
> @@ -956,7 +956,7 @@ static int journal_file_append_data(
>          const void *eq;
>  
>          assert(f);
> -        assert(data || size == 0);
> +        assert(data);
>  
>          hash = hash64(data, size);
>  


Lennart

-- 
Lennart Poettering, Red Hat


More information about the systemd-devel mailing list