Skip to content

Commit 706965f

Browse files
mkustermanncommit-bot@chromium.org
authored andcommitted
[gardening] Fix string_overflow_test.dart
The test was originally introduced in [0]. This restores its state to how it was written back then with some small adjustements. [0] d8ef2ae https://codereview.chromium.org//16783003 TEST=standalone{,_2}/string_overflow_test Fixes #46225 Change-Id: I255f676481f2ab6e906ebfe4612d394c29663dd0 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/202482 Reviewed-by: Clement Skau <cskau@google.com> Commit-Queue: Martin Kustermann <kustermann@google.com>
1 parent 05e5427 commit 706965f

File tree

2 files changed

+22
-6
lines changed

2 files changed

+22
-6
lines changed

tests/standalone/string_overflow_test.dart

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,21 @@
44

55
// Test to ensure that the VM does not have an integer overflow issue
66
// when concatenating strings.
7+
// See https://github.com/dart-lang/sdk/issues/11214
78

89
import "package:expect/expect.dart";
910

1011
main() {
1112
String a = "a";
12-
for (; a.length < 256 * 1024 * 1024;) a = a + a;
1313

14-
var concat = "$a$a$a$a$a$a$a$a";
15-
Expect.equals(concat.length, 2147483648);
14+
var caughtOutOfMemoryException = false;
15+
try {
16+
while (true) {
17+
a = "$a$a$a$a$a$a$a$a";
18+
}
19+
} on OutOfMemoryError {
20+
caughtOutOfMemoryException = true;
21+
}
22+
Expect.isTrue(caughtOutOfMemoryException);
23+
Expect.isTrue(a.startsWith('aaaaa') && a.length > 1024);
1624
}

tests/standalone_2/string_overflow_test.dart

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,21 @@
66

77
// Test to ensure that the VM does not have an integer overflow issue
88
// when concatenating strings.
9+
// See https://github.com/dart-lang/sdk/issues/11214
910

1011
import "package:expect/expect.dart";
1112

1213
main() {
1314
String a = "a";
14-
for (; a.length < 256 * 1024 * 1024;) a = a + a;
1515

16-
var concat = "$a$a$a$a$a$a$a$a";
17-
Expect.equals(concat.length, 2147483648);
16+
var caughtOutOfMemoryException = false;
17+
try {
18+
while (true) {
19+
a = "$a$a$a$a$a$a$a$a";
20+
}
21+
} on OutOfMemoryError {
22+
caughtOutOfMemoryException = true;
23+
}
24+
Expect.isTrue(caughtOutOfMemoryException);
25+
Expect.isTrue(a.startsWith('aaaaa') && a.length > 1024);
1826
}

0 commit comments

Comments
 (0)