From d3ad533dd601574902fe8992ec5e011112ff0830 Mon Sep 17 00:00:00 2001 From: Christoffer Lerno Date: Tue, 11 Feb 2025 00:13:04 +0100 Subject: [PATCH] Fix issue in List with sanitizers. --- lib/std/collections/list.c3 | 7 ++++--- releasenotes.md | 1 + 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/lib/std/collections/list.c3 b/lib/std/collections/list.c3 index 8863ad748..5db7a4bab 100644 --- a/lib/std/collections/list.c3 +++ b/lib/std/collections/list.c3 @@ -234,11 +234,11 @@ fn void List.push_front(&self, Type type) @inline fn void List.insert_at(&self, usz index, Type type) { self.reserve(1); - for (usz i = self.size; i > index; i--) + self.set_size(self.size + 1); + for (isz i = self.size - 1; i > index; i--) { self.entries[i] = self.entries[i - 1]; } - self.set_size(self.size + 1); self.entries[index] = type; } @@ -342,7 +342,8 @@ fn usz List.retain_if(&self, ElementPredicate selection) fn usz List.remove_using_test(&self, ElementTest filter, any context) { usz old_size = self.size; - defer { + defer + { if (old_size != self.size) self._update_size_change(old_size, self.size); } return list_common::list_remove_using_test(self, filter, false, context); diff --git a/releasenotes.md b/releasenotes.md index 1ff7965de..08569fba5 100644 --- a/releasenotes.md +++ b/releasenotes.md @@ -62,6 +62,7 @@ - `set_env` would leak memory. - Fix issue where aligned bitstructs did not store/load with the given alignment. - Fix issue in GrowableBitSet with sanitizers. +- Fix issue in List with sanitizers. ### Stdlib changes - Added '%h' and '%H' for printing out binary data in hexadecimal using the formatter.