根本解决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)){};

再次编译解决。

参考文献

目录
相关文章
|
2月前
|
网络协议 C++
解决MASM32代码汇编出错: error A2181: initializer must be a string or single item
解决MASM32代码汇编出错: error A2181: initializer must be a string or single item
|
Java Maven Android开发
成功解决FATAL ERROR in native method: JDWP on getting class status, jvmtiError=JVMTI_ERROR_WRONG_PHASE
成功解决FATAL ERROR in native method: JDWP on getting class status, jvmtiError=JVMTI_ERROR_WRONG_PHASE
|
Linux C++
【C++编译】C++ error:‘syscall’ was not declared in this scope
sys/syscall.h 内部表示,他封装了![[Pasted image 20220818151746.png]] 打开对应的 syscall.h 文件内部依旧没有 syscall()函数的声明。
101 0
|
Java
【Java异常】ERROR: JDWP Unable to get JNI 1.2 environment, jvm->GetEnv() return code = -2 JDWP exit erro
【Java异常】ERROR: JDWP Unable to get JNI 1.2 environment, jvm->GetEnv() return code = -2 JDWP exit erro
337 0
rsync error: some files/attrs were not transferred (see previous errors) (code 23) at main.c(1179)
rsync error: some files/attrs were not transferred (see previous errors) (code 23) at main.c(1179)
380 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错误)
370 0
|
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
705 0