Skip to content
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

Merged
merged 1 commit into from Jan 5, 2017

Conversation

xiexingguo
Copy link
Member

Signed-off-by: xie xingguo xie.xingguo@zte.com.cn

@@ -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));
Copy link
Contributor

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?

Copy link
Contributor

@tchaikov tchaikov Jan 4, 2017

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.

Copy link
Member Author

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));
   ^

@xiexingguo
Copy link
Member Author

@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__)
Copy link
Contributor

@tchaikov tchaikov Jan 4, 2017

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__.

Copy link
Contributor

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

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Upgraded. Thanks!

@xiexingguo xiexingguo force-pushed the xxg-wip-shutup-warning branch 2 times, most recently from 470eef4 to 3bd8422 Compare January 4, 2017 05:48
Signed-off-by: xie xingguo <xie.xingguo@zte.com.cn>
@tchaikov tchaikov self-assigned this Jan 4, 2017
@tchaikov tchaikov merged commit 14d8d5d into ceph:master Jan 5, 2017
@xiexingguo xiexingguo deleted the xxg-wip-shutup-warning branch January 5, 2017 14:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants