This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Re: Can argv be NULL in C?
- From: Mason <slash dot tmp at free dot fr>
- To: Yao Qi <qiyaoltc at gmail dot com>
- Cc: Martin Sebor <msebor at gmail dot com>, Luis Machado <lgustavo at codesourcery dot com>, GCC help <gcc-help at gcc dot gnu dot org>
- Date: Tue, 11 Oct 2016 10:26:15 +0200
- Subject: Re: Can argv be NULL in C?
- Authentication-results: sourceware.org; auth=none
- References: <CAH=s-POoZ39MKkbXK8GKYDMc8bfP-=VUKEi34FYSev3hTP9qHw@mail.gmail.com> <e260fa74-4705-030a-0d34-8682bf1f5a57@gmail.com> <CAH=s-PO-193jZNBp-6WQkY+tHCQK=Ft2+QqGYMHqF21eWhE=eg@mail.gmail.com>
On 11/10/2016 10:14, Yao Qi wrote:
> On Fri, Oct 7, 2016 at 6:27 PM, Martin Sebor <msebor@gmail.com> wrote:
>
>> Right. In a hosted environment argv must not be null. It's
>> up to the implementation to guarantee that for all conforming
>> programs. If a program is non-conforming (e.g., it calls exceve
>> or its equivalent to start a program with a null argv) it's still
>> up to the implementation to decide what to do with it (it could
>> simply punt and pass the null through or it could substitute
>> an array of pointers for it with the first one set to null).
>
> Thanks for your answer, Martin. Looks like the argv can be NULL
> in reality.
Sounds like saying "strlen's argument can be NULL in reality".
(Which is true, as nothing stops one from writing strlen(NULL)
in their code.)
Passing NULL to strlen has undefined behavior, thus (most)
libc implementations won't check for NULL.
Regards.