how can i solve this warning?
Code:
void socket_dontroute(socket_t s)
{
int set;
if (setsockopt(s, SOL_SOCKET, SO_DONTROUTE, (const char *) &set, sizeof(int)) < 0) {
sys_err("setsockopt: dontroute: %s", strerror(errno));
socket_close(s);
return;
}
}
int set; I know it's because of the statement, but I don't know how to solve it.
CodePudding user response:
You are passing set
as a pointer to setsockopt
, but are only declaring the variable and not initializing it. That means that the content of set could be anything that is present at its memory address, and the compiler is warning you of it. As the comments rightfully stated, choose a value for set according to your functions requirement.