Changeset 45696 in webkit for trunk/JavaScriptCore
- Timestamp:
- Jul 9, 2009, 8:45:23 PM (16 years ago)
- Location:
- trunk/JavaScriptCore
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/JavaScriptCore/ChangeLog
r45695 r45696 1 2009-07-09 Maciej Stachowiak <[email protected]> 2 3 Reviewed by Darin Adler. 4 5 REGRESSION: crash in edge cases of floating point parsing. 6 https://bugs.webkit.org/show_bug.cgi?id=27110 7 <rdar://problem/7044458> 8 9 Tests: fast/css/number-parsing-crash.html 10 fast/css/number-parsing-crash.html 11 fast/js/number-parsing-crash.html 12 13 * wtf/dtoa.cpp: 14 (WTF::BigInt::BigInt): Converted this to more a proper class, using a Vector 15 with inline capacity 16 17 (WTF::lshift): Rearranged logic somewhat nontrivially to deal with the new way of sizing BigInts. 18 Added an assertion to verify that invariants are maintained. 19 20 All other functions are adapted fairly mechanically to the above changes. 21 (WTF::BigInt::clear): 22 (WTF::BigInt::size): 23 (WTF::BigInt::resize): 24 (WTF::BigInt::words): 25 (WTF::BigInt::append): 26 (WTF::multadd): 27 (WTF::s2b): 28 (WTF::i2b): 29 (WTF::mult): 30 (WTF::cmp): 31 (WTF::diff): 32 (WTF::b2d): 33 (WTF::d2b): 34 (WTF::ratio): 35 (WTF::strtod): 36 (WTF::quorem): 37 (WTF::dtoa): 38 1 39 2009-07-09 Drew Wilson <[email protected]> 2 40 -
trunk/JavaScriptCore/wtf/dtoa.cpp
r44224 r45696 256 256 #define Big1 0xffffffff 257 257 258 259 // FIXME: we should remove non-Pack_32 mode since it is unused and unmaintained 258 260 #ifndef Pack_32 259 261 #define Pack_32 … … 279 281 280 282 struct BigInt { 281 BigInt() : sign(0), wds(0) { } 282 BigInt(const BigInt& other) : sign(other.sign), wds(other.wds) 283 BigInt() : sign(0) { } 284 int sign; 285 286 void clear() 283 287 { 284 for (int i = 0; i < 64; ++i)285 x[i] = other.x[i];286 } 287 288 BigInt& operator=(const BigInt& other)288 sign = 0; 289 m_words.clear(); 290 } 291 292 size_t size() const 289 293 { 290 sign = other.sign; 291 wds = other.wds; 292 for (int i = 0; i < 64; ++i) 293 x[i] = other.x[i]; 294 return *this; 294 return m_words.size(); 295 } 296 297 void resize(size_t s) 298 { 299 m_words.resize(s); 300 } 301 302 uint32_t* words() 303 { 304 return m_words.data(); 305 } 306 307 const uint32_t* words() const 308 { 309 return m_words.data(); 295 310 } 296 311 297 int sign; 298 int wds; 299 uint32_t x[64]; 312 void append(uint32_t w) 313 { 314 m_words.append(w); 315 } 316 317 Vector<uint32_t, 16> m_words; 300 318 }; 301 319 … … 308 326 #endif 309 327 310 int wds = b. wds;311 uint32_t* x = b. x;328 int wds = b.size(); 329 uint32_t* x = b.words(); 312 330 int i = 0; 313 331 carry = a; … … 332 350 } while (++i < wds); 333 351 334 if (carry) { 335 b.x[wds++] = (uint32_t)carry; 336 b.wds = wds; 337 } 352 if (carry) 353 b.append((uint32_t)carry); 338 354 } 339 355 … … 347 363 #ifdef Pack_32 348 364 b.sign = 0; 349 b. x[0] = y9;350 b.w ds = 1;365 b.resize(1); 366 b.words()[0] = y9; 351 367 #else 352 368 b.sign = 0; 353 b. x[0] = y9 & 0xffff;354 b.w ds = (b->x[1] = y9 >> 16) ? 2 : 1;369 b.resize((b->x[1] = y9 >> 16) ? 2 : 1); 370 b.words()[0] = y9 & 0xffff; 355 371 #endif 356 372 … … 441 457 { 442 458 b.sign = 0; 443 b. x[0] = i;444 b.w ds = 1;459 b.resize(1); 460 b.words()[0] = i; 445 461 } 446 462 … … 460 476 #endif 461 477 462 if (a-> wds < b->wds) {478 if (a->size() < b->size()) { 463 479 const BigInt* tmp = a; 464 480 a = b; … … 466 482 } 467 483 468 wa = a-> wds;469 wb = b-> wds;484 wa = a->size(); 485 wb = b->size(); 470 486 wc = wa + wb; 471 472 for (xc = c.x, xa = xc + wc; xc < xa; xc++) 487 c.resize(wc); 488 489 for (xc = c.words(), xa = xc + wc; xc < xa; xc++) 473 490 *xc = 0; 474 xa = a-> x;491 xa = a->words(); 475 492 xae = xa + wa; 476 xb = b-> x;493 xb = b->words(); 477 494 xbe = xb + wb; 478 xc0 = c. x;495 xc0 = c.words(); 479 496 #ifdef USE_LONG_LONG 480 497 for (; xb < xbe; xc0++) { … … 538 555 #endif 539 556 #endif 540 for (xc0 = c. x, xc = xc0 + wc; wc > 0 && !*--xc; --wc) { }541 c. wds = wc;557 for (xc0 = c.words(), xc = xc0 + wc; wc > 0 && !*--xc; --wc) { } 558 c.resize(wc); 542 559 aRef = c; 543 560 } … … 618 635 #endif 619 636 620 int n1 = n + b.wds + 1; 621 622 const uint32_t* srcStart = b.x; 623 uint32_t* dstStart = b.x; 624 const uint32_t* src = srcStart + b.wds - 1; 637 int origSize = b.size(); 638 int n1 = n + origSize + 1; 639 640 if (k &= 0x1f) 641 b.resize(b.size() + n + 1); 642 else 643 b.resize(b.size() + n); 644 645 const uint32_t* srcStart = b.words(); 646 uint32_t* dstStart = b.words(); 647 const uint32_t* src = srcStart + origSize - 1; 625 648 uint32_t* dst = dstStart + n1 - 1; 626 649 #ifdef Pack_32 627 if (k &= 0x1f) {650 if (k) { 628 651 uint32_t hiSubword = 0; 629 652 int s = 32 - k; … … 634 657 *dst = hiSubword; 635 658 ASSERT(dst == dstStart + n); 636 b.wds = b.wds + n + (b.x[n1 - 1] != 0); 659 660 b.resize(origSize + n + (b.words()[n1 - 1] != 0)); 637 661 } 638 662 #else … … 653 677 *--dst = *src--; 654 678 } while (src >= srcStart); 655 b.wds = b.wds + n;656 679 } 657 680 for (dst = dstStart + n; dst != dstStart; ) 658 681 *--dst = 0; 682 683 ASSERT(b.size() <= 1 || b.words()[b.size() - 1]); 659 684 } 660 685 … … 664 689 int i, j; 665 690 666 i = a. wds;667 j = b. wds;668 ASSERT(i <= 1 || a. x[i - 1]);669 ASSERT(j <= 1 || b. x[j - 1]);691 i = a.size(); 692 j = b.size(); 693 ASSERT(i <= 1 || a.words()[i - 1]); 694 ASSERT(j <= 1 || b.words()[j - 1]); 670 695 if (i -= j) 671 696 return i; 672 xa0 = a. x;697 xa0 = a.words(); 673 698 xa = xa0 + j; 674 xb0 = b. x;699 xb0 = b.words(); 675 700 xb = xb0 + j; 676 701 for (;;) { … … 693 718 if (!i) { 694 719 c.sign = 0; 695 c. wds = 1;696 c. x[0] = 0;720 c.resize(1); 721 c.words()[0] = 0; 697 722 return; 698 723 } … … 705 730 i = 0; 706 731 707 c.wds = 0; 732 wa = a->size(); 733 const uint32_t* xa = a->words(); 734 const uint32_t* xae = xa + wa; 735 wb = b->size(); 736 const uint32_t* xb = b->words(); 737 const uint32_t* xbe = xb + wb; 738 739 c.resize(wa); 708 740 c.sign = i; 709 wa = a->wds; 710 const uint32_t* xa = a->x; 711 const uint32_t* xae = xa + wa; 712 wb = b->wds; 713 const uint32_t* xb = b->x; 714 const uint32_t* xbe = xb + wb; 715 xc = c.x; 741 xc = c.words(); 716 742 #ifdef USE_LONG_LONG 717 743 unsigned long long borrow = 0; … … 758 784 while (!*--xc) 759 785 wa--; 760 c. wds = wa;786 c.resize(wa); 761 787 } 762 788 … … 805 831 #define d1 word1(&d) 806 832 807 xa0 = a. x;808 xa = xa0 + a. wds;833 xa0 = a.words(); 834 xa = xa0 + a.size(); 809 835 y = *--xa; 810 836 ASSERT(y); … … 861 887 b.sign = 0; 862 888 #ifdef Pack_32 863 b. wds = 1;864 #else 865 b. wds = 2;866 #endif 867 x = b. x;889 b.resize(1); 890 #else 891 b.resize(2); 892 #endif 893 x = b.words(); 868 894 869 895 z = d0 & Frac_mask; … … 882 908 } else 883 909 x[0] = y; 910 if (z) { 911 b.resize(2); 912 x[1] = z; 913 } 914 884 915 #ifndef Sudden_Underflow 885 i = 886 #endif 887 b.wds = (x[1] = z) ? 2 : 1; 916 i = b.size(); 917 #endif 888 918 } else { 889 919 k = lo0bits(&z); 890 920 x[0] = z; 891 921 #ifndef Sudden_Underflow 892 i = 893 #endif 894 b.wds = 1;922 i = 1; 923 #endif 924 b.resize(1); 895 925 k += 32; 896 926 } … … 930 960 } while (!x[i]) 931 961 --i; 932 b-> wds = i + 1;962 b->resize(i + 1); 933 963 #endif 934 964 #ifndef Sudden_Underflow … … 959 989 dval(&db) = b2d(b, &kb); 960 990 #ifdef Pack_32 961 k = ka - kb + 32 * (a. wds - b.wds);962 #else 963 k = ka - kb + 16 * (a. wds - b.wds);991 k = ka - kb + 32 * (a.size() - b.size()); 992 #else 993 k = ka - kb + 16 * (a.size() - b.size()); 964 994 #endif 965 995 if (k > 0) … … 1453 1483 ) { 1454 1484 #ifdef SET_INEXACT 1455 if (!delta-> x[0] && delta->wds<= 1)1485 if (!delta->words()[0] && delta->size() <= 1) 1456 1486 inexact = 0; 1457 1487 #endif 1458 1488 break; 1459 1489 } 1460 if (!delta. x[0] && delta.wds<= 1) {1490 if (!delta.words()[0] && delta.size() <= 1) { 1461 1491 /* exact result */ 1462 1492 #ifdef SET_INEXACT … … 1701 1731 static ALWAYS_INLINE int quorem(BigInt& b, BigInt& S) 1702 1732 { 1703 int n;1733 size_t n; 1704 1734 uint32_t *bx, *bxe, q, *sx, *sxe; 1705 1735 #ifdef USE_LONG_LONG … … 1711 1741 #endif 1712 1742 #endif 1713 1714 n = S.wds; 1715 ASSERT_WITH_MESSAGE(b.wds <= n, "oversize b in quorem"); 1716 if (b.wds < n) 1743 ASSERT(b.size() <= 1 || b.words()[b.size() - 1]); 1744 ASSERT(S.size() <= 1 || S.words()[S.size() - 1]); 1745 1746 n = S.size(); 1747 ASSERT_WITH_MESSAGE(b.size() <= n, "oversize b in quorem"); 1748 if (b.size() < n) 1717 1749 return 0; 1718 sx = S. x;1750 sx = S.words(); 1719 1751 sxe = sx + --n; 1720 bx = b. x;1752 bx = b.words(); 1721 1753 bxe = bx + n; 1722 1754 q = *bxe / (*sxe + 1); /* ensure q <= true quotient */ … … 1753 1785 } while (sx <= sxe); 1754 1786 if (!*bxe) { 1755 bx = b. x;1787 bx = b.words(); 1756 1788 while (--bxe > bx && !*bxe) 1757 1789 --n; 1758 b. wds = n;1790 b.resize(n); 1759 1791 } 1760 1792 } … … 1763 1795 borrow = 0; 1764 1796 carry = 0; 1765 bx = b. x;1766 sx = S. x;1797 bx = b.words(); 1798 sx = S.words(); 1767 1799 do { 1768 1800 #ifdef USE_LONG_LONG … … 1792 1824 #endif 1793 1825 } while (sx <= sxe); 1794 bx = b. x;1826 bx = b.words(); 1795 1827 bxe = bx + n; 1796 1828 if (!*bxe) { 1797 1829 while (--bxe > bx && !*bxe) 1798 1830 --n; 1799 b. wds = n;1831 b.resize(n); 1800 1832 } 1801 1833 } … … 2028 2060 word0(&eps) -= (P - 1) * Exp_msk1; 2029 2061 if (ilim == 0) { 2030 S = mhi = BigInt(); 2062 S.clear(); 2063 mhi.clear(); 2031 2064 dval(&u) -= 5.; 2032 2065 if (dval(&u) > dval(&eps)) … … 2091 2124 ds = tens[k]; 2092 2125 if (ndigits < 0 && ilim <= 0) { 2093 S = mhi = BigInt(); 2126 S.clear(); 2127 mhi.clear(); 2094 2128 if (ilim < 0 || dval(&u) <= 5 * ds) 2095 2129 goto no_digits; … … 2133 2167 m2 = b2; 2134 2168 m5 = b5; 2135 mhi = mlo = BigInt(); 2169 mhi.clear(); 2170 mlo.clear(); 2136 2171 if (leftright) { 2137 2172 i = … … 2187 2222 */ 2188 2223 #ifdef Pack_32 2189 if ((i = ((s5 ? 32 - hi0bits(S. x[S.wds- 1]) : 1) + s2) & 0x1f))2224 if ((i = ((s5 ? 32 - hi0bits(S.words()[S.size() - 1]) : 1) + s2) & 0x1f)) 2190 2225 i = 32 - i; 2191 2226 #else 2192 if ((i = ((s5 ? 32 - hi0bits(S. x[S.wds- 1]) : 1) + s2) & 0xf))2227 if ((i = ((s5 ? 32 - hi0bits(S.words()[S.size() - 1]) : 1) + s2) & 0xf)) 2193 2228 i = 16 - i; 2194 2229 #endif … … 2253 2288 } 2254 2289 if (j < 0 || (j == 0 && !(word1(&u) & 1))) { 2255 if (!b. x[0] && b.wds<= 1) {2290 if (!b.words()[0] && b.size() <= 1) { 2256 2291 #ifdef SET_INEXACT 2257 2292 inexact = 0; … … 2288 2323 for (i = 1;; i++) { 2289 2324 *s++ = dig = quorem(b,S) + '0'; 2290 if (!b. x[0] && b.wds<= 1) {2325 if (!b.words()[0] && b.size() <= 1) { 2291 2326 #ifdef SET_INEXACT 2292 2327 inexact = 0;
Note:
See TracChangeset
for help on using the changeset viewer.