New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
common: get rid of "warning: ignoring return value of ‘strerror_r’" #12775
Conversation
@@ -40,7 +40,8 @@ static int run_command(const char *command) | |||
|
|||
if (status < 0) { | |||
char error_buf[80]; | |||
strerror_r(errno, error_buf, sizeof(error_buf)); | |||
char* dummy = strerror_r(errno, error_buf, sizeof(error_buf)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it seems that freeBSD will compile error. strerror_r returns int in freeBSD。 ref: https://linux.die.net/man/3/strerror_r
is auto
better?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
could also put
(void) strerror_r(errno, error_buf, sizeof(error_buf));
to silence the warning.
wondering why the strerror_r()
call in errno.cc didn't pop up.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually I've tried both before posting this pr but none of them worked.
By applying @liuchang0812 change, I get:
/home/xxg/dev/ceph-dev/src/common/module.c: In function ‘run_command’:
/home/xxg/dev/ceph-dev/src/common/module.c:43:8: warning: type defaults to ‘int’ in declaration of ‘dummy’ [enabled by default]
auto dummy = strerror_r(errno, error_buf, sizeof(error_buf));
^
/home/xxg/dev/ceph-dev/src/common/module.c:43:16: warning: initialization makes integer from pointer without a cast [enabled by default]
auto dummy = strerror_r(errno, error_buf, sizeof(error_buf));
^
and by applying @tchaikov change instead I get:
/home/xxg/dev/ceph-dev/src/common/module.c: In function ‘run_command’:
/home/xxg/dev/ceph-dev/src/common/module.c:44:3: warning: ignoring return value of ‘strerror_r’, declared with attribute warn_unused_result [-Wunused-result]
(void)strerror_r(errno, error_buf, sizeof(error_buf));
^
6a41d58
to
ac9df34
Compare
@tchaikov Check again? |
@@ -40,7 +40,12 @@ static int run_command(const char *command) | |||
|
|||
if (status < 0) { | |||
char error_buf[80]; | |||
strerror_r(errno, error_buf, sizeof(error_buf)); | |||
#if defined(__FreeBSD__) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@xiexingguo if you want to differentiate the XSI and GNU strerror_r()
, better off using STRERROR_R_CHAR_P
instead of __FreeBSD__
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
and please do not indent #if
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Upgraded. Thanks!
470eef4
to
3bd8422
Compare
Signed-off-by: xie xingguo <xie.xingguo@zte.com.cn>
Signed-off-by: xie xingguo xie.xingguo@zte.com.cn