|
1 /* |
|
2 * Any copyright is dedicated to the Public Domain. |
|
3 * http://creativecommons.org/licenses/publicdomain/ |
|
4 */ |
|
5 |
|
6 var BUGNUMBER = 805121; |
|
7 var summary = "Be more careful with string math to avoid wrong results"; |
|
8 |
|
9 print(BUGNUMBER + ": " + summary); |
|
10 |
|
11 /******************************************************************************/ |
|
12 |
|
13 function puff(x, n) |
|
14 { |
|
15 while(x.length < n) |
|
16 x += x; |
|
17 return x.substring(0, n); |
|
18 } |
|
19 |
|
20 var x = puff("1", 1 << 20); |
|
21 var rep = puff("$1", 1 << 16); |
|
22 |
|
23 try |
|
24 { |
|
25 var y = x.replace(/(.+)/g, rep); |
|
26 assertEq(y.length, Math.pow(2, 36)); |
|
27 } |
|
28 catch (e) |
|
29 { |
|
30 // OOM also acceptable |
|
31 } |
|
32 |
|
33 /******************************************************************************/ |
|
34 |
|
35 if (typeof reportCompare === "function") |
|
36 reportCompare(true, true); |
|
37 |
|
38 print("Tests complete"); |