Closed Bug 929466 Opened 11 years ago Closed 11 years ago

mar.c:177:28: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]

Categories

(Toolkit :: Application Update, defect)

x86_64
Linux
defect
Not set
normal

Tracking

()

RESOLVED FIXED
mozilla27

People

(Reporter: dholbert, Assigned: dholbert)

References

(Blocks 1 open bug)

Details

Attachments

(1 file)

Build warning:
{
modules/libmar/tool/mar.c: In function ‘main’:
modules/libmar/tool/mar.c:177:28: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
                (argv[1][2] == '0' + certCount ||
                            ^
}

argv is a char**, so argv[1][2] is of type "char". (signed)

certCount is of type uint32_t, so ('0' + certCount) is of type uint32_t. ('0' gets promoted for the purpose of the addition)

So we end up comparing a signed expression on the left to an unsigned expression on the right.

We can fix this by making certCount a signed variable (possibly type "char", so that the two sides of this equality-check actually match?)
Alternately, we can just cast '0' + certCount to be a char. Slightly hackier, but cleaner / more targeted, and it looks like that's essentially what the code is expecting to happen.

(Note that the surrounding code prevents certCount from exceeding MAX_SIGNATURES, which is 8, so we're in no danger of actually wrapping past CHAR_MAX.)
Attached patch fix v1Splinter Review
This just adds a (char) cast, per prev comment.
Assignee: nobody → dholbert
Status: NEW → ASSIGNED
Attachment #820335 - Flags: review?(netzen)
Comment on attachment 820335 [details] [diff] [review]
fix v1

Review of attachment 820335 [details] [diff] [review]:
-----------------------------------------------------------------

Thanks!
Attachment #820335 - Flags: review?(netzen) → review+
https://hg.mozilla.org/mozilla-central/rev/f87879d36aef
Status: ASSIGNED → RESOLVED
Closed: 11 years ago
Resolution: --- → FIXED
Target Milestone: --- → mozilla27
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: