Changeset 42988 in webkit for trunk/JavaScriptCore/runtime/UString.cpp
- Timestamp:
- Apr 28, 2009, 10:56:18 PM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/JavaScriptCore/runtime/UString.cpp
r42644 r42988 492 492 } 493 493 494 static ALWAYS_INLINE int newCapacityWithOverflowCheck(const int currentCapacity, const int extendLength, const bool plusOne = false) 495 { 496 ASSERT_WITH_MESSAGE(extendLength >= 0, "extendedLength = %d", extendLength); 497 498 const int plusLength = plusOne ? 1 : 0; 499 if (currentCapacity > std::numeric_limits<int>::max() - extendLength - plusLength) 500 CRASH(); 501 502 return currentCapacity + extendLength + plusLength; 503 } 504 494 505 static ALWAYS_INLINE PassRefPtr<UString::Rep> concatenate(PassRefPtr<UString::Rep> r, const UChar* tData, int tSize) 495 506 { … … 511 522 } else if (rep == base && !base->isShared()) { 512 523 // this is direct and has refcount of 1 (so we can just alter it directly) 513 int newCapacity = thisOffset + length; 514 if (newCapacity < thisOffset) 515 CRASH(); 516 if (!expandCapacity(rep.get(), newCapacity)) 524 if (!expandCapacity(rep.get(), newCapacityWithOverflowCheck(thisOffset, length))) 517 525 rep = &UString::Rep::null(); 518 526 if (rep->data()) { … … 523 531 } else if (thisOffset + thisSize == base->usedCapacity && thisSize >= minShareSize) { 524 532 // this reaches the end of the buffer - extend it if it's long enough to append to 525 int newCapacity = thisOffset + length; 526 if (newCapacity < thisOffset) 527 CRASH(); 528 if (!expandCapacity(rep.get(), newCapacity)) 533 if (!expandCapacity(rep.get(), newCapacityWithOverflowCheck(thisOffset, length))) 529 534 rep = &UString::Rep::null(); 530 535 if (rep->data()) { … … 571 576 } else if (rep == base && !base->isShared()) { 572 577 // this is direct and has refcount of 1 (so we can just alter it directly) 573 int newCapacity = thisOffset + length; 574 if (newCapacity < thisOffset) 575 CRASH(); 576 expandCapacity(rep.get(), newCapacity); 578 expandCapacity(rep.get(), newCapacityWithOverflowCheck(thisOffset, length)); 577 579 UChar* d = rep->data(); 578 580 if (d) { … … 584 586 } else if (thisOffset + thisSize == base->usedCapacity && thisSize >= minShareSize) { 585 587 // this string reaches the end of the buffer - extend it 586 int newCapacity = thisOffset + length; 587 if (newCapacity < thisOffset) 588 CRASH(); 589 expandCapacity(rep.get(), newCapacity); 588 expandCapacity(rep.get(), newCapacityWithOverflowCheck(thisOffset, length)); 590 589 UChar* d = rep->data(); 591 590 if (d) { … … 651 650 652 651 UString x(a); 653 int capacity = aOffset + length; 654 if (capacity < aOffset) 655 CRASH(); 656 x.expandCapacity(capacity); 652 x.expandCapacity(newCapacityWithOverflowCheck(aOffset, length)); 657 653 if (!a->data() || !x.data()) 658 654 return 0; … … 1004 1000 } else if (m_rep == base && !base->isShared()) { 1005 1001 // this is direct and has refcount of 1 (so we can just alter it directly) 1006 int newCapacity = thisOffset + length; 1007 if (newCapacity < thisOffset) 1008 CRASH(); 1009 expandCapacity(newCapacity); 1002 expandCapacity(newCapacityWithOverflowCheck(thisOffset, length)); 1010 1003 if (data()) { 1011 1004 copyChars(m_rep->data() + thisSize, t.data(), tSize); … … 1015 1008 } else if (thisOffset + thisSize == base->usedCapacity && thisSize >= minShareSize) { 1016 1009 // this reaches the end of the buffer - extend it if it's long enough to append to 1017 int newCapacity = thisOffset + length; 1018 if (newCapacity < thisOffset) 1019 CRASH(); 1020 expandCapacity(newCapacity); 1010 expandCapacity(newCapacityWithOverflowCheck(thisOffset, length)); 1021 1011 if (data()) { 1022 1012 copyChars(m_rep->data() + thisSize, t.data(), tSize); … … 1077 1067 } else if (m_rep == base && !base->isShared()) { 1078 1068 // this is direct and has refcount of 1 (so we can just alter it directly) 1079 int newCapacity = thisOffset + length + 1; 1080 if (newCapacity < thisOffset) 1081 CRASH(); 1082 expandCapacity(newCapacity); 1069 expandCapacity(newCapacityWithOverflowCheck(thisOffset, length, true)); 1083 1070 UChar* d = m_rep->data(); 1084 1071 if (d) { … … 1089 1076 } else if (thisOffset + length == base->usedCapacity && length >= minShareSize) { 1090 1077 // this reaches the end of the string - extend it and share 1091 int newCapacity = thisOffset + length + 1; 1092 if (newCapacity < thisOffset) 1093 CRASH(); 1094 expandCapacity(newCapacity); 1078 expandCapacity(newCapacityWithOverflowCheck(thisOffset, length, true)); 1095 1079 UChar* d = m_rep->data(); 1096 1080 if (d) {
Note:
See TracChangeset
for help on using the changeset viewer.