mirror of
https://github.com/dart-lang/sdk
synced 2024-11-05 18:22:09 +00:00
[dart2wasm] Fix off-by-one error in List.insert()
Closes https://github.com/dart-lang/sdk/issues/54845 TEST=lib/collection/regress_54845_test Change-Id: I1af7f59a57c70ef5ec724b089555ebbcbd88a484 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/351120 Commit-Queue: Martin Kustermann <kustermann@google.com> Reviewed-by: Slava Egorov <vegorov@google.com>
This commit is contained in:
parent
0ab9f53744
commit
26aa50fdbf
2 changed files with 14 additions and 1 deletions
|
@ -97,7 +97,7 @@ class _GrowableList<E> extends _ModifiableList<E> {
|
|||
data = WasmArray<Object?>(_nextCapacity(_capacity));
|
||||
if (index != 0) {
|
||||
// Copy elements before the insertion point.
|
||||
data.copy(0, _data, 0, index - 1);
|
||||
data.copy(0, _data, 0, index);
|
||||
}
|
||||
} else {
|
||||
data = _data;
|
||||
|
|
13
tests/lib/collection/regress_54845_test.dart
Normal file
13
tests/lib/collection/regress_54845_test.dart
Normal file
|
@ -0,0 +1,13 @@
|
|||
// Copyright (c) 2024, the Dart project authors. Please see the AUTHORS file
|
||||
// for details. All rights reserved. Use of this source code is governed by a
|
||||
// BSD-style license that can be found in the LICENSE file.
|
||||
|
||||
import 'package:expect/expect.dart';
|
||||
|
||||
main() {
|
||||
final l = [10, 20, 30];
|
||||
for (int i = l.length; i-- > 0;) {
|
||||
if (i > 0) l.insert(i, -1);
|
||||
}
|
||||
Expect.deepEquals([10, -1, 20, -1, 30], l);
|
||||
}
|
Loading…
Reference in a new issue