This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug c/67093] incorrect -Wnonnull text for execl family of functions


https://gcc.gnu.org/bugzilla/show_bug.cgi?id=67093

--- Comment #4 from Martin Sebor <msebor at gcc dot gnu.org> ---
The requirements on execl() and main() are specified in sufficient detail to
guarantee that a program that call execl("/some/other/program", (char*)0) is
portable across all conforming implementations so long as /some/other/program
doesn't assume that argv[0] is non-null.

Issuing a warning in this case is useful because programs often do make this
assumption (including some utilities that are part of an implementation --
e.g., /bin/echo on Linux, see below).  That is why applications that assume
that it's safe to pass null as arg0 is safe "cannot be assured to be portable
across conforming implementations."  (I.e., the utilities themselves aren't
strictly conforming C programs.)

What this issue points out is not that the warning is wrong but that its text
isn't strictly speaking correct: passing a non-null arg0 is not required, only
recommended.

$ cat t.c && gcc t.c && ./a.out 
#include <unistd.h>

int main (void) {
    return execl ("/bin/echo", (char*)0);
}
A NULL argv[0] was passed through an exec system call.
Aborted (core dumped)

This is a C conformance bug in /bin/echo since there is no requirement that
argv[0] be non-null.

Why do I point this out?  Because the use of the word "required" in the text of
the warning perpetuates the widespread misconception that argv[0] is guaranteed
to be non-null.  The programs that should be fixed are those that make this
assumption.   Calling execl with a non-null arg0 just works around the bug.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]