Changeset 167548 in webkit
- Timestamp:
- Apr 19, 2014, 2:13:46 PM (12 years ago)
- Location:
- trunk/Source
- Files:
-
- 5 edited
-
JavaScriptCore/ChangeLog (modified) (1 diff)
-
JavaScriptCore/dfg/DFGOperations.cpp (modified) (2 diffs)
-
JavaScriptCore/runtime/Operations.h (modified) (2 diffs)
-
WTF/ChangeLog (modified) (1 diff)
-
WTF/wtf/CheckedArithmetic.h (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/JavaScriptCore/ChangeLog
r167544 r167548 1 2014-04-19 Filip Pizlo <fpizlo@apple.com> 2 3 Make it easier to check if an integer sum would overflow 4 https://bugs.webkit.org/show_bug.cgi?id=131900 5 6 Reviewed by Darin Adler. 7 8 * dfg/DFGOperations.cpp: 9 * runtime/Operations.h: 10 (JSC::jsString): 11 1 12 2014-04-19 Filip Pizlo <fpizlo@apple.com> 2 13 -
trunk/Source/JavaScriptCore/dfg/DFGOperations.cpp
r167544 r167548 969 969 VM& vm = exec->vm(); 970 970 NativeCallFrameTracer tracer(&vm, exec); 971 972 if (s tatic_cast<int32_t>(left->length() + right->length()) < 0) {971 972 if (sumOverflows<int32_t>(left->length(), right->length())) { 973 973 throwOutOfMemoryError(exec); 974 974 return nullptr; … … 983 983 NativeCallFrameTracer tracer(&vm, exec); 984 984 985 Checked<int32_t, RecordOverflow> length = a->length(); 986 length += b->length(); 987 length += c->length(); 988 if (length.hasOverflowed()) { 985 if (sumOverflows<int32_t>(a->length(), b->length(), c->length())) { 989 986 throwOutOfMemoryError(exec); 990 987 return nullptr; -
trunk/Source/JavaScriptCore/runtime/Operations.h
r167336 r167548 45 45 if (!length2) 46 46 return s1; 47 if ( (length1 + length2) < 0)47 if (sumOverflows<int32_t>(length1, length2)) 48 48 return throwOutOfMemoryError(exec); 49 49 … … 69 69 return jsString(exec, jsString(vm, u1), jsString(vm, u2)); 70 70 71 if ((length1 + length2) < 0) 72 return throwOutOfMemoryError(exec); 73 if ((length1 + length2 + length3) < 0) 71 if (sumOverflows<int32_t>(length1, length2, length3)) 74 72 return throwOutOfMemoryError(exec); 75 73 -
trunk/Source/WTF/ChangeLog
r167528 r167548 1 2014-04-19 Filip Pizlo <fpizlo@apple.com> 2 3 Make it easier to check if an integer sum would overflow 4 https://bugs.webkit.org/show_bug.cgi?id=131900 5 6 Reviewed by Darin Adler. 7 8 * wtf/CheckedArithmetic.h: 9 (WTF::checkedSum): 10 (WTF::sumOverflows): 11 1 12 2014-04-18 Commit Queue <commit-queue@webkit.org> 2 13 -
trunk/Source/WTF/wtf/CheckedArithmetic.h
r160687 r167548 717 717 typedef Checked<size_t, RecordOverflow> CheckedSize; 718 718 719 template<typename T, typename U> 720 Checked<T, RecordOverflow> checkedSum(U value) 721 { 722 return Checked<T, RecordOverflow>(value); 723 } 724 template<typename T, typename U, typename... Args> 725 Checked<T, RecordOverflow> checkedSum(U value, Args... args) 726 { 727 return Checked<T, RecordOverflow>(value) + checkedSum<T>(args...); 728 } 729 730 // Sometimes, you just want to check if some math would overflow - the code to do the math is 731 // already in place, and you want to guard it. 732 733 template<typename T, typename... Args> bool sumOverflows(Args... args) 734 { 735 return checkedSum<T>(args...).hasOverflowed(); 736 } 737 719 738 } 720 739 … … 731 750 using WTF::CheckedUint64; 732 751 using WTF::CheckedSize; 752 using WTF::checkedSum; 753 using WTF::sumOverflows; 733 754 734 755 #endif
Note:
See TracChangeset
for help on using the changeset viewer.