Closed
Bug 221289
Opened 22 years ago
Closed 22 years ago
Test for unsigned >= 0 in content/base/src/nsGenericElement.cpp
Categories
(Core :: DOM: Core & HTML, defect)
Tracking
()
RESOLVED
FIXED
People
(Reporter: tenthumbs, Unassigned)
Details
Attachments
(1 file)
|
634 bytes,
patch
|
bzbarsky
:
review+
bzbarsky
:
superreview+
|
Details | Diff | Splinter Review |
Gcc says:
nsGenericElement.cpp:294: warning: \
comparison of unsigned expression >= 0 is always true
Code is:
294 for (PRUint32 i = childCount; i-- != 0; ) {
295 aContent->RemoveChildAt(i, PR_TRUE);
The loop never terminates. Surprising this hasn't bitten someone. Patch upcoming.
Comment 2•22 years ago
|
||
Comment on attachment 132682 [details] [diff] [review]
simple patch
r+sr=bzbarsky. It's not bitten anyone because it's a recent change, and
because DOM3 is rarely used... ;)
Attachment #132682 -
Flags: superreview+
Attachment #132682 -
Flags: review+
Comment 3•22 years ago
|
||
Checeked in. Thanks for the patch!
In general, though, please ask for reviews to get people to notice the patch...
Status: NEW → RESOLVED
Closed: 22 years ago
Resolution: --- → FIXED
Comment 4•22 years ago
|
||
Note that this was caused by jst's patch for bug 215981.
Also note that this patch causes the loop to run one too many times each pass.
Please be more careful when fixing simple things like this.
> PRUint32 childCount = aContent->GetChildCount();
>
>- for (PRUint32 i = childCount - 1; i >= 0; --i) {
>+ for (PRUint32 i = childCount; i-- != 0; ) {
> aContent->RemoveChildAt(i, PR_TRUE);
> }
We really don't want to remove the child at the |aContent->GetChildCount()|th
index since there isn't one. The loop should be
while (childCount-- > 0) {
aContent->RemoveChildAt(childCount, PR_TRUE);
}
Comment 5•22 years ago
|
||
caillon,
>+ for (PRUint32 i = childCount; i-- != 0; ) {
and
while (childCount-- > 0) {
are actually completely equivalent...
Comment 6•22 years ago
|
||
bz: except the second one is about 10 times easier to read. :-P
Comment 7•22 years ago
|
||
the difference is that the second one will modify childCount, so they are not
_completely_ equivalent
Comment 8•22 years ago
|
||
Hm, misread that. Yes, of course they are equal. I'll just make the change
though to make it 10 times easier to read as Hixie notes, and get rid of the
extra variable.
Comment 9•22 years ago
|
||
Yeah, since we never use childCount after that the switch can be made (and is
more readable)...
I was just defending myself and tenthumbs against charges of illogic. ;)
| Reporter | ||
Comment 10•22 years ago
|
||
> Also note that this patch causes the loop to run one too many times
> each pass.
> Please be more careful when fixing simple things like this.
If you had asked I would have told you that I tested for this and the
loop enumerated the same values either way. I may be sloppy but not that
sloppy.
Updated•6 years ago
|
Component: DOM → DOM: Core & HTML
You need to log in
before you can comment on or make changes to this bug.
Description
•