警告:忽略使用属性warn_unused_result声明的’realloc’的返回值

我很好奇,我正在使用PuTTy编写C语言 ,有谁知道我怎么能摆脱这个警告?

警告:忽略’realloc’的返回值,使用属性warn_unused_result声明[-Wunused-result] realloc(strp-> data,nbytes);

^ 

它想要’警告’我的线的相关代码:

  //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); } 

提前致谢

调用realloc的正确方法是这样的:

 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;