1
0
mirror of https://github.com/dart-lang/sdk synced 2024-07-03 08:19:13 +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:
Martin Kustermann 2024-02-08 14:05:44 +00:00
parent 0ab9f53744
commit 26aa50fdbf
2 changed files with 14 additions and 1 deletions

View File

@ -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;

View 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);
}