clang's -Wtautological-constant-out-of-range-compare warns on prnetdb.c

RESOLVED FIXED in 4.9.3

Status

defect
P2
trivial
RESOLVED FIXED
7 years ago
7 years ago

People

(Reporter: thakis, Assigned: thakis)

Tracking

other
4.9.3

Firefox Tracking Flags

(Not tracked)

Details

Attachments

(1 attachment)

Assignee

Description

7 years ago
Posted patch nspr.patchSplinter Review
User Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_8_2) AppleWebKit/537.11 (KHTML, like Gecko) Chrome/23.0.1271.6 Safari/537.11

Steps to reproduce:

I built nspr with a very recent version of clang (r164143 or newer).


Actual results:

../../third_party/nss/mozilla/nsprpub/pr/src/misc/prnetdb.c:2081:16: error: comparison of constant 3 with expression of type 'PRStatus' is always false [-Werror,-Wtautological-constant-out-of-range-compare]
        if (rv == EAI_BADFLAGS && (hints.ai_flags & AI_ADDRCONFIG)) {
            ~~ ^  ~~~~~~~~~~~~
1 error generated.


Expected results:

No warning.

The warning is correct, GETADDRINFO(), which is declared further up in the file and returns int, not PRStatus. Since rv is currently PRStatus, it can only be PR_FAILURE = -1 or PR_SUCCESS = 0, never EAI_BADFLAGS = 3.

rv is only used for the return value of GETADDRINFO(), so the fix is to change it to int (see attached patch).

Comment 1

7 years ago
Thank you for the patch!

Patch checked in on the NSPR trunk (NSPR 4.9.3).

Checking in prnetdb.c;
/cvsroot/mozilla/nsprpub/pr/src/misc/prnetdb.c,v  <--  prnetdb.c
new revision: 3.68; previous revision: 3.67
done
Assignee: wtc → thakis
Severity: normal → trivial
Status: UNCONFIRMED → RESOLVED
Closed: 7 years ago
Priority: -- → P2
Resolution: --- → FIXED
Target Milestone: --- → 4.9.3
Attachment #665785 - Attachment is patch: true
You need to log in before you can comment on or make changes to this bug.