-
Notifications
You must be signed in to change notification settings - Fork 112
[housekeeping] Integer-related compiler warnings #159
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
Conversation
Address always false warning ([-Wtype-limits]):
../vip.c:430:15: warning: comparison of unsigned expression in ‘< 0’ is
always false [-Wtype-limits]
430 | if (n < 0) {
| ^
../vip.c:437:15: warning: comparison of unsigned expression in ‘< 0’
is always false [-Wtype-limits]
437 | if (n < 0) {
Signed-off-by: Igor Opaniuk <[email protected]>
Address warnings for comparisons of integer expressions of different
signedness, for example:
../firehose.c:384:31: warning: comparison of integer expressions of
different signedness: ‘int’ and ‘long unsigned int’ [-Wsign-compare]
384 | for (i = 0; i < ARRAY_SIZE(sector_sizes); i++) {
In all places, where signed value is casted to unsigned (size_t for
instance), there is always explicitly handling of possible negative
value beforehand
Signed-off-by: Igor Opaniuk <[email protected]>
| } | ||
|
|
||
| if (n < qdl->max_payload_size) | ||
| if ((size_t)n < qdl->max_payload_size) |
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 check of n < 0 is above, so safe to cast here
| } else if (expect_empty) { | ||
| err(1, "expected empty transfer but received non-empty transfer during read"); | ||
| } else if (n != chunk_size * sector_size) { | ||
| } else if ((size_t)n != chunk_size * sector_size) { |
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 check of n < 0 is above, so safe to cast here
|
|
||
| if (out_buf) { | ||
| if (n > out_len - out_offset) | ||
| if ((size_t)n > out_len - out_offset) |
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 check of n < 0 is already above, so safe to cast here
|
|
||
| pkt = (struct sahara_pkt *)buf; | ||
| if (n != pkt->length) { | ||
| if ((uint32_t)n != pkt->length) { |
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 check of n < 0 is already above, so safe to cast here
No description provided.