From 0526e0e04e26331840123b4c3f650b3e77cd7009 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Sat, 17 Oct 2020 11:40:51 +0200 Subject: [PATCH] - fixed: Array.Insert must zero all elements before the new one if something gets inserted outside the existing range. --- src/common/scripting/core/dynarrays.cpp | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/common/scripting/core/dynarrays.cpp b/src/common/scripting/core/dynarrays.cpp index eebb97da8..82dd8e774 100644 --- a/src/common/scripting/core/dynarrays.cpp +++ b/src/common/scripting/core/dynarrays.cpp @@ -87,11 +87,12 @@ template void ArrayDelete(T *self, int index, int count) template void ArrayInsert(T *self, int index, U val) { - //int oldSize = self->Size(); + int oldSize = self->Size(); self->Insert(index, static_cast(val)); - // Is this even necessary? All Insert does is inserting one defined element into the array and moving the rest. - // It never creates empty tailing entries. fillcount in the macro will always be 0 - //if (fill) { DYNARRAY_FILL_ITEMS_SKIP(1); } + if constexpr (fill) + { + for (unsigned i = oldSize; i < self->Size() - 1; i++) (*self)[i] = 0; + } } template void ArrayShrinkToFit(T *self)