Closed Bug 845429 Opened 12 years ago Closed 12 years ago

nsDocShell.cpp:3601:42: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]

Categories

(Core Graveyard :: DOM: Apps, defect)

x86_64
Linux
defect
Not set
normal

Tracking

(Not tracked)

RESOLVED FIXED
mozilla22

People

(Reporter: dholbert, Assigned: dholbert)

References

(Blocks 1 open bug)

Details

(Whiteboard: [qa-])

Attachments

(1 file)

New build warning: { docshell/base/nsDocShell.cpp:3601:42: warning: comparison between signed and unsigned integer expressions [-Wsign-compare] } from this code: 3592 NS_IMETHODIMP 3593 nsDocShell::GetChildAt(int32_t aIndex, nsIDocShellTreeItem ** aChild) 3594 { 3595 NS_ENSURE_ARG_POINTER(aChild); 3596 3597 #ifdef DEBUG 3598 if (aIndex < 0) { 3599 NS_WARNING("Negative index passed to GetChildAt"); 3600 } 3601 else if (aIndex >= mChildList.Length()) { 3602 NS_WARNING("Too large an index passed to GetChildAt"); 3603 } 3604 #endif https://mxr.mozilla.org/mozilla-central/source/docshell/base/nsDocShell.cpp#3593 The warning started when we changed mChildList from a nsVoidArray (with a signed Count() method) to a nsTArray (with an unsigned Length() method), in this cset: https://hg.mozilla.org/mozilla-central/diff/8ddc33231c6f/docshell/base/nsDocShell.cpp#l1.211
If we hit this clause, we're guaranteed that aIndex is non-negative. (If it were negative, we would've entered the "if (aIndex < 0)" clause, and we wouldn't be touching this "else if" stuff.) So, we're guaranteed that static_cast<uint32_t> will be a valid cast. This patch adds that cast.
Assignee: nobody → dholbert
Status: NEW → ASSIGNED
Attachment #718507 - Flags: review?(trev.saunders)
Comment on attachment 718507 [details] [diff] [review] fix v1: static_cast<uint32_t> > } >- else if (aIndex >= mChildList.Length()) { >+ else if (static_cast<uint32_t>(aIndex) >= mChildList.Length()) { } else if (x) { while your here please
Attachment #718507 - Flags: review?(trev.saunders) → review+
Sounds good, thanks!
Status: ASSIGNED → RESOLVED
Closed: 12 years ago
Resolution: --- → FIXED
Target Milestone: --- → mozilla22
Whiteboard: [qa-]
Product: Core → Core Graveyard
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: