I wrote a simple code (part of it below) and use splint to check for any warnings. But Splint is complaining. What might be the issue I am missing?
Splint Warning
malloctest.c:24:3: Return value (type char *) ignored: gets(p)
Result returned by function call is not used. If this is intended, can cast
result to (void) to eliminate message. (Use -retvalother to inhibit warning)
Code part
p= (char*)malloc(BUFFER*sizeof(char));
if(p==NULL)
{
printf("the memory could not be allocated");
}
else
{
gets(p); //line 24
printf("the name entered is \n%s\n",p);
}
Thanks in Advance!
gets()returns achar*to indicate success or failure, which the code is ignoring hence the warning.However, with
gets()there is no way to prevent buffer overrun. Instead, you can usescanf()with"%Ns"format specifier (orfgets()if the string can contain spaces):