Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C warning Missing sentinel in function call

Tags:

c

warnings

This is my warning.

Missing sentinel in function call

How i can remove it.

i am using linux & gcc compiler.

like image 206
ambika Avatar asked Mar 09 '10 08:03

ambika


2 Answers

It looks like you may not have terminated an array declaration with NULL. Without the null you may have some memory weirdness as the runtime won't know where the array ends and the next bit of memory starts.

like image 200
Michael Gaylord Avatar answered Nov 07 '22 11:11

Michael Gaylord


I just came across the same issue. The code which was causing it for me was...

execl("/bin/bash", "/bin/bash", fname, '\0');

but it should be...

execl("/bin/bash", "/bin/bash", fname, (char *)0);

The problem with the first version is that the list of parameters is meant to end with a null pointer. But '\0' is not a null pointer, it's a null character. So the value (0) is correct, it's just the type is wrong.

The (char *)0 is also zero, but cast as a char pointer, which is a null pointer (ie it points to address 0). This is needed so the system can tell where the parameter list ends so that it doesn't keep scanning for parameters after the last one. Doing that would get it invalid pointers which could point to any memory - which likely would cause a segmentation fault.

That (char *)0 is called the sentinel, and it's what was missing from the first example.

Finally note that NULL is defined as (void *)0, so

execl("/bin/bash", "/bin/bash", fname, NULL);

Works just as well, and is a little more convenient. (Thanks to @mah for that).

like image 55
Peter Bagnall Avatar answered Nov 07 '22 10:11

Peter Bagnall