[LTP] [PATCH v1] execl(), execlp() and execle() require proper termination of argument list
Petr Vorel
pvorel@suse.cz
Mon Nov 28 12:11:08 CET 2022
Hi Michael,
sorry to bother you, could you please comment our discussion about execl{,e,p}()
termination of argument list being NULL vs. (char *)NULL vs. (void*)0?
Martin reported [2] that man page suggests (char*)NULL, his view of reason [3]:
NULL may be defined as simple integer 0. When int is 32bit and pointers
64bit, this will cause trouble in variadic functions such as execlp().
Cyril pointed out [4]: NULL is required to be 0 cast to void* in POSIX. [5]
Therefore what should be really used?
Kind regards,
Petr
[2] https://lore.kernel.org/ltp/8587b908-a035-a96a-7233-2863b7bc30ca@suse.cz/
[3] https://lore.kernel.org/ltp/af63ed9a-7108-fd19-fe2c-4b56be85d068@suse.cz/
[4] https://lore.kernel.org/ltp/Y4DSmk7uY9zUUQsV@yuki/
[5] https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/stddef.h.html
> On 25.11.22 15:06, Petr Vorel wrote:
> > Hi David,
> > thanks for fixing this!
> > Reviewed-by: Petr Vorel <pvorel@suse.cz>
> This seems to be quite a controversial topic :)
> I stumbled over [1], which still left me confused regarding what to do and
> what to not do.
> Interestingly, the problem doesn't seem to be that NULL is defined in a
> strange way, but that the representation of (void *)NULL and (char *)NULL
> might be (weirdly enough) different, and that no explicit cast could result
> in undefined behavior.
> IIUC, the second answer indicates that with C99 it might be fine, because
> that case is defined behavior ("one type is pointer to void and the other is
> a pointer to a character type.").
> Having that said, I have cannot really tell if this change must be
> performed. :)
> [1] https://stackoverflow.com/questions/52195275/can-the-compiler-cast-void-0-in-execlprog-arg-void-0-to-a-null-po
More information about the ltp
mailing list