根本解决C程序 ignoring return value of ‘***’

简介: 去源码找到出问题的地方,处理一下返回值

最近在移植一个 C 项目时出现如下报错:

xxxxxx.c:990:4: error: ignoring return value of ‘chroot’, declared with attribute warn_unused_result [-Werror=unused-result]
  990 |    chroot("/");

之所以报错等级为 Error ,是因为 GCC 编译具有参数 -Werror,将警告当作错误:

gcc -std=gnu99 -Wall -Werror -Wno-unknown-pragmas -Wno-strict-aliasing -Wpedantic -g -O2 -Wl,-z,relro -I. -D_FILE_OFFSET_BITS=64 -I/usr/include/glib-2.0 -I/usr/lib/x86_64-linux-gnu/glib-2.0/include -I/usr/include/fuse -c -o xxxxxx.o xxxxxx.c -MMD -MT pmxcfs.o -MF xxxxxx.o.d

去掉这一编译参数治标不治本。最根本的解决办法是去源码找到出问题的地方,处理一下返回值,或者这样手动忽略错误,并辅以注释:

- chown(RUNDIR, 0, cfs.gid);
+ # TODO 临时处理,忽略返回值
+ # 后期需根据实际情况处理错误码
+ if(chown(RUNDIR, 0, cfs.gid)){};

再次编译解决。

参考文献

目录
相关文章
|
8月前
|
Linux C++
【C++编译】C++ error:‘syscall’ was not declared in this scope
sys/syscall.h 内部表示,他封装了![[Pasted image 20220818151746.png]] 打开对应的 syscall.h 文件内部依旧没有 syscall()函数的声明。
69 0
|
安全
Pyrsgis:执行imageChipsFromFile报错NameError: name ‘copy‘ is not defined
Pyrsgis:执行imageChipsFromFile报错NameError: name ‘copy‘ is not defined
194 0
解决:Oops internal error 40343 occured.Further work is not possible and IDA will close (打开文件出现40343错误)
解决:Oops internal error 40343 occured.Further work is not possible and IDA will close (打开文件出现40343错误)
271 0
collect1:error:ld returned 1 exit status 解决办法
collect1:error:ld returned 1 exit status 解决办法
collect1:error:ld returned 1 exit status 解决办法
|
Perl
ld: symbol(s) not found for architecture x86_64 clang: error: linker command failed with exit code 1
ld: symbol(s) not found for architecture x86_64 clang: error: linker command failed with exit code 1
638 0
解决:Oops! internal error 40343 occured.Further work is not possible and IDA will close(打开文件出现40343错误)
解决:Oops! internal error 40343 occured.Further work is not possible and IDA will close(打开文件出现40343错误)
610 0
解决:Oops! internal error 40343 occured.Further work is not possible and IDA will close(打开文件出现40343错误)