cpuinfo icon indicating copy to clipboard operation
cpuinfo copied to clipboard

Fix warning in clog.c about ignoring return value of ‘write’

Open WilliamTambellini opened this issue 3 years ago • 4 comments

Dozens of warnings in clog.c:

[  2%] Linking CXX shared library libonnxruntime_providers_shared.so
/home/wtambellini/repos/onnxruntime/cmake/external/pytorch_cpuinfo/deps/clog/src/clog.c:112:4: warning: ignoring return value of ‘write’, declared with attribute warn_unused_result [-Wunused-result]
    write(STDERR_FILENO, out_buffer, prefix_chars + format_chars + CLOG_SUFFIX_LENGTH);
    ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/home/wtambellini/repos/onnxruntime/cmake/external/pytorch_cpuinfo/deps/clog/src/clog.c: In function ‘clog_vlog_error’:
/home/wtambellini/repos/onnxruntime/cmake/external/pytorch_cpuinfo/deps/clog/src/clog.c:188:4: warning: ignoring return value of ‘write’, declared with attribute warn_unused_result [-Wunused-result]
    write(STDERR_FILENO, out_buffer, prefix_chars + format_chars + CLOG_SUFFIX_LENGTH);
    ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/home/wtambellini/repos/onnxruntime/cmake/external/pytorch_cpuinfo/deps/clog/src/clog.c: In function ‘clog_vlog_warning’:
/home/wtambellini/repos/onnxruntime/cmake/external/pytorch_cpuinfo/deps/clog/src/clog.c:264:4: warning: ignoring return value of ‘write’, declared with attribute warn_unused_result [-Wunused-result]
    write(STDERR_FILENO, out_buffer, prefix_chars + format_chars + CLOG_SUFFIX_LENGTH);
    ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/home/wtambellini/repos/onnxruntime/cmake/external/pytorch_cpuinfo/deps/clog/src/clog.c: In function ‘clog_vlog_info’:
/home/wtambellini/repos/onnxruntime/cmake/external/pytorch_cpuinfo/deps/clog/src/clog.c:340:4: warning: ignoring return value of ‘write’, declared with attribute warn_unused_result [-Wunused-result]
    write(STDOUT_FILENO, out_buffer, prefix_chars + format_chars + CLOG_SUFFIX_LENGTH);
    ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
....

line 112 https://github.com/pytorch/cpuinfo/blob/728f3e909fa5c57e0123c4658e234f6b1941385d/deps/clog/src/clog.c#L112

write() indeed returns a size_t : https://linux.die.net/man/2/write Would you mind if I add a check ? eg:

ssize_t rv =  write(STDOUT_FILENO, out_buffer, prefix_chars + format_chars + CLOG_SUFFIX_LENGTH);
asert(rv != -1);

WilliamTambellini avatar Jan 19 '22 03:01 WilliamTambellini

It would be good to suppress the warning, but assert is not the right way to do it. assert may crash the whole program because of failed logging write.

Maratyszcza avatar Jan 19 '22 15:01 Maratyszcza

Hi @Maratyszcza
Sure, what about logging (warning ?error ?) if the rv == -1 ?

WilliamTambellini avatar Jan 19 '22 17:01 WilliamTambellini

rv == -1 indicates that we've had an error during logging. I don't expect anything good attempting to log the error about the logging error. The best option IMO is to ignore the error, and silence the compiler warning about it.

Maratyszcza avatar Jan 19 '22 18:01 Maratyszcza

Well, totally ignoring write() errors would make debugging even harder but nevermind. So would you accept a PR if I add target_compile_options(... "-Wno-unused-result") to the main CMakeList.txt, only for gcc builds ?

WilliamTambellini avatar Feb 05 '22 03:02 WilliamTambellini

Fixed in #129

Maratyszcza avatar Jul 18 '23 22:07 Maratyszcza