[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] d8ef2ae7 https://codereview.chromium.org//16783003

TEST=standalone{,_2}/string_overflow_test

Fixes https://github.com/dart-lang/sdk/issues/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>
This commit is contained in:
Martin Kustermann 2021-06-04 14:38:16 +00:00 committed by commit-bot@chromium.org
parent 05e5427800
commit 706965fd2c
2 changed files with 22 additions and 6 deletions

View file

@ -4,13 +4,21 @@
// Test to ensure that the VM does not have an integer overflow issue
// when concatenating strings.
// See https://github.com/dart-lang/sdk/issues/11214
import "package:expect/expect.dart";
main() {
String a = "a";
for (; a.length < 256 * 1024 * 1024;) a = a + a;
var concat = "$a$a$a$a$a$a$a$a";
Expect.equals(concat.length, 2147483648);
var caughtOutOfMemoryException = false;
try {
while (true) {
a = "$a$a$a$a$a$a$a$a";
}
} on OutOfMemoryError {
caughtOutOfMemoryException = true;
}
Expect.isTrue(caughtOutOfMemoryException);
Expect.isTrue(a.startsWith('aaaaa') && a.length > 1024);
}

View file

@ -6,13 +6,21 @@
// Test to ensure that the VM does not have an integer overflow issue
// when concatenating strings.
// See https://github.com/dart-lang/sdk/issues/11214
import "package:expect/expect.dart";
main() {
String a = "a";
for (; a.length < 256 * 1024 * 1024;) a = a + a;
var concat = "$a$a$a$a$a$a$a$a";
Expect.equals(concat.length, 2147483648);
var caughtOutOfMemoryException = false;
try {
while (true) {
a = "$a$a$a$a$a$a$a$a";
}
} on OutOfMemoryError {
caughtOutOfMemoryException = true;
}
Expect.isTrue(caughtOutOfMemoryException);
Expect.isTrue(a.startsWith('aaaaa') && a.length > 1024);
}