Fix some compiler warning (#2047)
* Allow unused return value in cc source With llvm-7.0.0, some annoying warning messeges are raised: /home/lecopzer/workspace/bcc/src/cc/libbpf.c:456:3: warning: ignoring return value of ‘fgets’, declared with attribute warn_unused_result [-Wunused-result] fgets(fmt, sizeof(fmt), f); // pos ^~~~~~~~~~~~~~~~~~~~~~~~~~ /home/lecopzer/workspace/bcc/src/cc/libbpf.c: In function ‘bpf_prog_get_tag’: /home/lecopzer/workspace/bcc/src/cc/libbpf.c:456:3: warning: ignoring return value of ‘fgets’, declared with attribute warn_unused_result [-Wunused-result] fgets(fmt, sizeof(fmt), f); // pos ^~~~~~~~~~~~~~~~~~~~~~~~~~ ... /home/lecopzer/workspace/bcc/tests/cc/utils.cc: In function ‘int cmd_scanf(const char*, const char*, ...)’: /home/lecopzer/workspace/bcc/tests/cc/utils.cc:30:10: warning: ignoring return value of ‘int vfscanf(FILE*, const char*, __va_list_tag*)’, declared with attribute warn_unused_result [-Wunused-result] vfscanf(pipe, fmt, args); ~~~~~~~^~~~~~~~~~~~~~~~~ Let get rid of them by adding -Wno-unused-result. * cc: Fix comparison between signed and unsigned value With llvm-7.0.0: /home/lecopzer/workspace/bcc/src/cc/common.cc: In function ‘std::__cxx11::string ebpf::get_pid_exe(pid_t)’: /home/lecopzer/workspace/bcc/src/cc/common.cc:60:11: warning: comparison between signed and unsigned integer expressions [-Wsign-compare] if (res >= sizeof(exe_path)) ~~~~^~~~~~~~~~ As the declaration of `exe_path` is `char exe_path[4096]`, the `sizeof(exe_path)` would always return 4096 (unsigned), so it's safe to static cast to `int` unless it's larger than 2^31 - 1.
Showing
Please register or sign in to comment