libct/nsenter: ignore unused return value of write#3154
libct/nsenter: ignore unused return value of write#3154kailun-qin wants to merge 1 commit intoopencontainers:masterfrom
Conversation
libcontainer/nsenter/nsexec.c
Outdated
| if (write(logfd, json, ret) != ret) | ||
| goto out; |
There was a problem hiding this comment.
this is useless...
A way to suppress a warning is (void)write(...)
There was a problem hiding this comment.
Simply casting to (void) won't work. See https://gcc.gnu.org/bugzilla/show_bug.cgi?id=25509 for detailed info.
Alternatives below if we really don't want to check the return value, which may however lose kind of readability:
- (void)!write(...)
- if (write(...));
What's the preference? Thanks! @kolyshkin
There was a problem hiding this comment.
Oh my...
Frankly, I don't know. What's the best way from the readability point of view?
Perhaps something like
if (write(logfd, json, ret) < 0)
; // nothing we can do hereThere was a problem hiding this comment.
I guess that if stmt may break another linter.
Isn't there an gcc __attribute__ to ignore the warning? (I'm googling around...)
There was a problem hiding this comment.
#pragma GCC diagnostic ignored "-Wunused-result" may work (untested)
There was a problem hiding this comment.
@AkihiroSuda Thanks for the comment!
emm yes, I agree this may break another linter. But #pragma GCC diagnostic ignored "-Wunused-result" won't work for older gcc versions before Diagnostic Pragmas was introduced.
Do you think adding braces to avoid linters checking empty bodies for if statements work for you?
if (write(logfd, json, ret) < 0) {
; // nothing we can do here
}
There was a problem hiding this comment.
Updated. PTAL thanks! @kolyshkin @AkihiroSuda
There was a problem hiding this comment.
Even gcc4 seems supporting that pragma https://stackoverflow.com/questions/63229590/enabling-long-long-in-c89-at-gcc-3-2-4-4-and-5-4
So we can safely use the pragma
There was a problem hiding this comment.
@AkihiroSuda Thanks for checking this!
Updated using pragmas, PTAL. Thanks!
229cdd0 to
ec1aba1
Compare
|
@AkihiroSuda @cyphar Would you please kindly take a look when you get a chance? Thanks! |
|
The alternative is #3165. |
6bfafea to
29afabd
Compare
| #pragma GCC diagnostic push | ||
| #pragma GCC diagnostic ignored "-Wunused-result" | ||
| write(logfd, json, ret); | ||
| #pragma GCC diagnostic pop |
There was a problem hiding this comment.
This looks way too heavy to silent a single warning.
I think something like #3168 looks more elegant; PTAL.
A warning (warn_unused_result) may show up during compilation if a function returns a result that is never used. This patch explicitly disables/ignores this "-Wunused-result" warning for write() by using gcc diagnostic pragmas. Signed-off-by: Kailun Qin <kailun.qin@intel.com>
|
Fixed in #3168 Thanks anyway for contribution |
A warning (warn_unused_result) may show up during compilation if a
function returns a result that is never used.
This patch explicitly disables/ignores this "-Wunused-result" warning
for write() by using gcc diagnostic pragmas.
Signed-off-by: Kailun Qin kailun.qin@intel.com