-
Notifications
You must be signed in to change notification settings - Fork 68
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
libdm: fix -Wparentheses warning. #56
Conversation
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.
Did you test this? Isn't it the wrong way around? Number of policy arguments plus an extra one if the migration_threshold option will also be included, all times 2.
@@ -2489,7 +2489,7 @@ static int _cache_emit_segment_line(struct dm_task *dmt, | |||
EMIT_PARAMS(pos, " %s", name); | |||
|
|||
/* Do not pass migration_threshold 2048 which is default */ | |||
EMIT_PARAMS(pos, " %u", (seg->policy_argc + (seg->migration_threshold != 2048) ? 1 : 0) * 2); |
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.
should it be ((seg->migration_threshold != 2048) ? 1 : 0))
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.
The current implementation is to appease -Wparentheses
without changing program semantics, as you pointed out in #56 (comment). :)
Yep patch looks patch - it's been nicely covering itself due to test nature |
Here is the warning log: lvm2-2.02.187-r3: libdm-deptree.c:2467:81: warning: operator '?:' has lower precedence than '+'; '+' will be evaluated first [-Wparentheses] Based on the warning, the existing code was already evaluating "+" before "?" because of C operator precedence. |
Here is a small snipppet showing the predence of "+" and "?" : int main() { Expected result is 16 So, the current code is buggy if "?" was expected to be evaluated first by the initial author. |
Thanks @m-gupta for the experiments. The reason I make the patch the way it is is indeed to appease the warning without changing the program semantics, since addition has higher precedence over ternary conditional. Changing it based on the comment from #56 (review) would change the program semantics, or is that expected @kergon? |
When you get a compiler warning, the idea is not to unthinkingly suppress the warning, but to check what the code was supposed to do, understand it, and then resolve the warning accordingly. There are two possible patches here. Look at each option in the context of the lines around it then decide which of the two is the one that makes sense. |
Thanks for the comment. I've updated the code accordingly. |
This fixes a C operator precedence-related issue exposed by the warning. Link: #55
This fixes a C operator precedence-related issue exposed by the warning.
Link:
#55