Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

not enough variables to fit a sentinel

According to exec reference, calls to exec (or stack checking vararg functions in general) requires a (char*)NULL aka 0 at the end of the parameter list. GCC, however, is complaining about the following code

char cmdFullPath[4096]; //yes this 4096 thing is bad coding practice 
...
execl(cmdFullPath, (char*)NULL);

//warning: not enough variable arguments to fit a sentinel

Anyone know what's wrong?

like image 421
jameszhao00 Avatar asked Sep 28 '10 20:09

jameszhao00


1 Answers

That reference says that the prototype is

execl(const char * path, const char * arg, ...)

I read that as 2 parameters + (char*)NULL

something like :

execl(cmdFullPath, (const char*)NULL, (char*)NULL);

from the page:

#include <unistd.h>

int main() {
    execl("/bin/ls", "ls", "-l", (char *)NULL);
    return 0;
}
like image 59
Preet Sangha Avatar answered Sep 19 '22 22:09

Preet Sangha