Bug 49816

Summary: Remove a couple unneeded overflow checks
Product: WebKit Reporter: Darin Adler <darin>
Component: WebKit Misc.Assignee: Darin Adler <darin>
Status: RESOLVED FIXED    
Severity: Normal CC: ap, cevans, darin, kling
Priority: P2    
Version: 528+ (Nightly build)   
Hardware: All   
OS: All   
Attachments:
Description Flags
Patch kling: review+

Darin Adler
Reported 2010-11-19 11:25:39 PST
Remove a couple unneeded overflow checks
Attachments
Patch (3.26 KB, patch)
2010-11-19 11:27 PST, Darin Adler
kling: review+
Darin Adler
Comment 1 2010-11-19 11:27:31 PST
Andreas Kling
Comment 2 2010-11-19 14:58:42 PST
Comment on attachment 74408 [details] Patch r=me
Alexey Proskuryakov
Comment 3 2010-11-19 21:02:59 PST
+ // We need to be sure we can double the length without overflowing. + // Since the passed-in length is the length of an actual existing + // string, and we can guarantee that doesn't occupy the entire + // address space, we can just assert here and there's no need for + // a runtime check. + ASSERT(length <= numeric_limits<size_t>::max() / 2); This comment isn't sufficient for me to understand. If the existing string takes 51% of address space, why doesn't doubling that cause an overflow?
Andreas Kling
Comment 4 2010-11-19 23:11:35 PST
(In reply to comment #3) > This comment isn't sufficient for me to understand. If the existing string takes 51% of address space, why doesn't doubling that cause an overflow? The _existing_ string is length*2 bytes large, so we know that length*2 fits in the address space.
Darin Adler
Comment 5 2010-11-22 08:28:02 PST
(In reply to comment #3) > + // We need to be sure we can double the length without overflowing. > + // Since the passed-in length is the length of an actual existing > + // string, and we can guarantee that doesn't occupy the entire > + // address space, we can just assert here and there's no need for > + // a runtime check. > + ASSERT(length <= numeric_limits<size_t>::max() / 2); > > This comment isn't sufficient for me to understand. If the existing string takes 51% of address space, why doesn't doubling that cause an overflow? If the string’s length was the same as 51% of the address space, the string’s size would be 102% of the address space, since characters are two bytes each. I should refine the comment to make this clearer.
Darin Adler
Comment 6 2010-11-29 14:06:53 PST
Note You need to log in before you can comment on or make changes to this bug.