From 0fbcc3a0c7ef4835c77c5d8b87cc8732cc3f90df Mon Sep 17 00:00:00 2001 From: Mike Buland Date: Fri, 30 Jul 2021 09:16:27 -0700 Subject: Fixed uninitializsed bug in Bu::Array::setSize. When setCapacity was used before setSize some elements were not being properly initialized in the array. --- src/stable/array.h | 33 +++++++++++++++++++++++++++------ 1 file changed, 27 insertions(+), 6 deletions(-) (limited to 'src/stable') diff --git a/src/stable/array.h b/src/stable/array.h index ecffc6a..b089bda 100644 --- a/src/stable/array.h +++ b/src/stable/array.h @@ -297,7 +297,7 @@ namespace Bu return core->iSize; } - void setSize( long iNewLen, const value &initTo=value() ) + void setSize( long iNewLen ) { if( core->iSize == iNewLen ) return; @@ -306,19 +306,40 @@ namespace Bu if( iNewLen > core->iCapacity ) { core->setCapacity( iNewLen ); + } + if( iNewLen > core->iSize ) + { for( int j = core->iSize; j < iNewLen; j++ ) { core->va.construct( - &core->pData[j], - initTo + &core->pData[j] ); } - core->iSize = iNewLen; } - else + core->iSize = iNewLen; + } + + void setSize( long iNewLen, const value &initTo ) + { + if( core->iSize == iNewLen ) + return; + + _hardCopy(); + if( iNewLen > core->iCapacity ) + { + core->setCapacity( iNewLen ); + } + if( iNewLen > core->iSize ) { - core->iSize = iNewLen; + for( int j = core->iSize; j < iNewLen; j++ ) + { + core->va.construct( + &core->pData[j], + initTo + ); + } } + core->iSize = iNewLen; } /** -- cgit v1.2.3