[systemd-devel] [bug] (char*)NULL should be used in variadic functions

Jan Engelhardt jengelh at inai.de
Wed Jan 30 04:36:48 PST 2013


On Wednesday 2013-01-30 08:07, Vasily Kulikov wrote:

>Hi,
>
>systemd uses plain NULL as an argument of variadic functions, which is a
>UB in C.

The mere use of NULL in variadic functions is not UB.
If anything, calling va_arg(argp, char *) for something that is actually 
not a char * might, though.

>  (char*)NULL should be used instead.  Plain NULL may be defined
>as "0" or smth.

It's ugly, and almost everybody expects, and is programming that way, 
that sizeof(char *) == sizeof(void *) and that C is forgiving the 
apparent type-mismatch. So far, it has worked.

>NULL is wrongly used e.g. in sd_journal_send() in
>src/journal/test-journal-send.c.


More information about the systemd-devel mailing list