aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMike Buland <mbuland@penny-arcade.com>2021-07-30 09:16:27 -0700
committerMike Buland <mbuland@penny-arcade.com>2021-07-30 09:16:27 -0700
commit0fbcc3a0c7ef4835c77c5d8b87cc8732cc3f90df (patch)
treed214ecd864bbef469a9378ac5f3c05f6cd74f4da /src
parent2745b2811b03e83c165b07801704f32fc5bc588d (diff)
downloadlibbu++-0fbcc3a0c7ef4835c77c5d8b87cc8732cc3f90df.tar.gz
libbu++-0fbcc3a0c7ef4835c77c5d8b87cc8732cc3f90df.tar.bz2
libbu++-0fbcc3a0c7ef4835c77c5d8b87cc8732cc3f90df.tar.xz
libbu++-0fbcc3a0c7ef4835c77c5d8b87cc8732cc3f90df.zip
Fixed uninitializsed bug in Bu::Array::setSize.
When setCapacity was used before setSize some elements were not being properly initialized in the array.
Diffstat (limited to 'src')
-rw-r--r--src/stable/array.h33
-rw-r--r--src/unit/array.unit8
-rw-r--r--src/unit/string.unit6
3 files changed, 41 insertions, 6 deletions
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
297 return core->iSize; 297 return core->iSize;
298 } 298 }
299 299
300 void setSize( long iNewLen, const value &initTo=value() ) 300 void setSize( long iNewLen )
301 { 301 {
302 if( core->iSize == iNewLen ) 302 if( core->iSize == iNewLen )
303 return; 303 return;
@@ -306,19 +306,40 @@ namespace Bu
306 if( iNewLen > core->iCapacity ) 306 if( iNewLen > core->iCapacity )
307 { 307 {
308 core->setCapacity( iNewLen ); 308 core->setCapacity( iNewLen );
309 }
310 if( iNewLen > core->iSize )
311 {
309 for( int j = core->iSize; j < iNewLen; j++ ) 312 for( int j = core->iSize; j < iNewLen; j++ )
310 { 313 {
311 core->va.construct( 314 core->va.construct(
312 &core->pData[j], 315 &core->pData[j]
313 initTo
314 ); 316 );
315 } 317 }
316 core->iSize = iNewLen;
317 } 318 }
318 else 319 core->iSize = iNewLen;
320 }
321
322 void setSize( long iNewLen, const value &initTo )
323 {
324 if( core->iSize == iNewLen )
325 return;
326
327 _hardCopy();
328 if( iNewLen > core->iCapacity )
329 {
330 core->setCapacity( iNewLen );
331 }
332 if( iNewLen > core->iSize )
319 { 333 {
320 core->iSize = iNewLen; 334 for( int j = core->iSize; j < iNewLen; j++ )
335 {
336 core->va.construct(
337 &core->pData[j],
338 initTo
339 );
340 }
321 } 341 }
342 core->iSize = iNewLen;
322 } 343 }
323 344
324 /** 345 /**
diff --git a/src/unit/array.unit b/src/unit/array.unit
index 83401c1..e9f2bdf 100644
--- a/src/unit/array.unit
+++ b/src/unit/array.unit
@@ -101,4 +101,12 @@ suite Array
101 unitTest( aInts[j] == j ); 101 unitTest( aInts[j] == j );
102 } 102 }
103 } 103 }
104
105 test setSize
106 {
107 Bu::Array<Bu::String> aStr( 3 );
108 aStr.setSize( 3 );
109 aStr[1] = "Hello";
110 aStr[0] = aStr[1].clone();
111 }
104} 112}
diff --git a/src/unit/string.unit b/src/unit/string.unit
index 1f4ca7e..6242eff 100644
--- a/src/unit/string.unit
+++ b/src/unit/string.unit
@@ -586,6 +586,12 @@ suite String
586 { 586 {
587 unitTest( Bu::String("0x%{1}00").arg( 75, Bu::Fmt::hex() ).end() == "0x4b00" ); 587 unitTest( Bu::String("0x%{1}00").arg( 75, Bu::Fmt::hex() ).end() == "0x4b00" );
588 } 588 }
589
590 test sharedEmpty1
591 {
592 Bu::String a;
593 Bu::String b = a.clone();
594 }
589} 595}
590// 03F09CA4F58AC8CA0E80F0D9D409D0A60700A192270004BC3A99E91D0001034F544603362E35013103313130019CA4F58AC8CA0E0002830800002C4200008AC200EBF7D9D4090127BB010000E3 596// 03F09CA4F58AC8CA0E80F0D9D409D0A60700A192270004BC3A99E91D0001034F544603362E35013103313130019CA4F58AC8CA0E0002830800002C4200008AC200EBF7D9D4090127BB010000E3
591// 597//