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

RESOLVED FIXED in mozilla27

Status

()

Toolkit
Application Update
RESOLVED FIXED
5 years ago
5 years ago

People

(Reporter: dholbert, Assigned: dholbert)

Tracking

(Blocks: 1 bug)

unspecified
mozilla27
x86_64
Linux
Points:
---
Dependency tree / graph
Bug Flags:
in-testsuite -

Firefox Tracking Flags

(Not tracked)

Details

Attachments

(1 attachment)

(Assignee)

Description

5 years ago
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?)
(Assignee)

Comment 1

5 years ago
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.)
(Assignee)

Comment 2

5 years ago
Created attachment 820335 [details] [diff] [review]
fix v1

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
Last Resolved: 5 years ago
Resolution: --- → FIXED
Target Milestone: --- → mozilla27
You need to log in before you can comment on or make changes to this bug.