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

再次编译解决。

参考文献

目录
相关文章
|
10月前
|
Linux C++
【C++编译】C++ error:‘syscall’ was not declared in this scope
sys/syscall.h 内部表示,他封装了![[Pasted image 20220818151746.png]] 打开对应的 syscall.h 文件内部依旧没有 syscall()函数的声明。
87 0
|
11月前
|
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
278 0
|
TensorFlow 算法框架/工具 Python
成功解决File "frozen importlib._bootstrap", line 219, in _call_with_frames_removed ImportError: DLL lo
成功解决File "frozen importlib._bootstrap", line 219, in _call_with_frames_removed ImportError: DLL lo
成功解决File "frozen importlib._bootstrap", line 219, in _call_with_frames_removed ImportError: DLL lo
|
PyTorch 算法框架/工具
THCudaCheck FAIL file=/pytorch/aten/src/THC/THCGeneral.cpp line=405 error=11 : invalid argument
THCudaCheck FAIL file=/pytorch/aten/src/THC/THCGeneral.cpp line=405 error=11 : invalid argument
195 0
THCudaCheck FAIL file=/pytorch/aten/src/THC/THCGeneral.cpp line=405 error=11 : invalid argument
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
675 0
|
安全
VS2019 error C4996: ‘scanf‘: This function or variable may be unsafe 错误
VS2019 error C4996: ‘scanf‘: This function or variable may be unsafe 错误
274 0
VS2019 error C4996: ‘scanf‘: This function or variable may be unsafe 错误