I'm curious, I'm programming in C on PuTTy, does anyone know how I can get rid of this warning?
warning: ignoring return value of ‘realloc’, declared with attribute warn_unused_result [-Wunused-result] realloc(strp->data, nbytes);
^
Relevant code to the line it wants to 'warn' me about:
//If the previously allocated size is > 0 then we can reallocate
//otherwise we have to make a new allocation in memory
if(strp->length > 0)
{
realloc(strp->data, nbytes);
}
else
{
*strp = kstralloc(nbytes);
}
Thanks in advance
The correct way to call realloc is something like this:
tmp = realloc(strp->data, nbytes);
if (tmp == NULL) {
// your realloc didn't work and strp->data still points to the
// the original location
return EMEMORY;
}
strp->data = tmp;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With