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

再次编译解决。

参考文献

目录
相关文章
|
3月前
|
网络协议 C++
解决MASM32代码汇编出错: error A2181: initializer must be a string or single item
解决MASM32代码汇编出错: error A2181: initializer must be a string or single item
|
7月前
|
JavaScript 安全 网络安全
Node: opensslErrorStack: [ ‘error:03000086:digital envelope routines::initialization error‘ ]异常处理
Node: opensslErrorStack: [ ‘error:03000086:digital envelope routines::initialization error‘ ]异常处理
3312 1
|
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()函数的声明。
111 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
382 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)
440 0
|
PHP Docker 容器
ThinkPHP5 运行Workerman报错:Fatal error: Call to undefined function pcntl_signal()
ThinkPHP5 运行Workerman报错:Fatal error: Call to undefined function pcntl_signal()
376 0
ThinkPHP5 运行Workerman报错:Fatal error: Call to undefined function pcntl_signal()
|
Java Android开发
Bad method handle type 7异常解决
在利用androidx版本写demo时,在添加了一些依赖后,遇到了`java.lang.ClassNotFoundException`bug,这就很奇怪了,我就添加rxjava3的依赖,就给我报这个错误。
error: static assertion failed: Signal and slot arguments are not compatible.
error: static assertion failed: Signal and slot arguments are not compatible.
error: static assertion failed: Signal and slot arguments are not compatible.