aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMike Buland <eichlan@xagasoft.com>2011-01-20 19:31:44 +0000
committerMike Buland <eichlan@xagasoft.com>2011-01-20 19:31:44 +0000
commit8c3f900fc99d77e478766a6b0fa34c23253cc79e (patch)
tree7af5fbcf01a15c6cc76c6a10e85e61ae931d32fe
parenta9243f2c4e5cecfc0564f7951de92fd267510408 (diff)
downloadlibbu++-8c3f900fc99d77e478766a6b0fa34c23253cc79e.tar.gz
libbu++-8c3f900fc99d77e478766a6b0fa34c23253cc79e.tar.bz2
libbu++-8c3f900fc99d77e478766a6b0fa34c23253cc79e.tar.xz
libbu++-8c3f900fc99d77e478766a6b0fa34c23253cc79e.zip
Fixed a really strang, really hard to nail down corner case in String
Diffstat (limited to '')
-rw-r--r--src/string.h11
-rw-r--r--src/unit/string.unit28
2 files changed, 36 insertions, 3 deletions
diff --git a/src/string.h b/src/string.h
index 22db827..8583558 100644
--- a/src/string.h
+++ b/src/string.h
@@ -137,7 +137,8 @@ namespace Bu
137 for(;;) 137 for(;;)
138 { 138 {
139 Chunk *n = i->pNext; 139 Chunk *n = i->pNext;
140 aChr.deallocate( i->pData, i->nLength+1 ); 140 aChr.deallocate( i->pData,
141 (i->nLength<nMinSize)?(nMinSize):(i->nLength)+1 );
141 aChunk.deallocate( i, 1 ); 142 aChunk.deallocate( i, 1 );
142 if( n == NULL ) 143 if( n == NULL )
143 break; 144 break;
@@ -169,7 +170,8 @@ namespace Bu
169 Chunk *pNew = aChunk.allocate( 1 ); 170 Chunk *pNew = aChunk.allocate( 1 );
170 pNew->pNext = pSrc->pNext; 171 pNew->pNext = pSrc->pNext;
171 pNew->nLength = pSrc->nLength; 172 pNew->nLength = pSrc->nLength;
172 pNew->pData = aChr.allocate( pSrc->nLength+1 ); 173 pNew->pData = aChr.allocate(
174 (pNew->nLength<nMinSize)?(nMinSize):(pNew->nLength)+1 );
173 memcpy( pNew->pData, pSrc->pData, pSrc->nLength ); 175 memcpy( pNew->pData, pSrc->pData, pSrc->nLength );
174 pNew->pData[pNew->nLength] = (chr)0; 176 pNew->pData[pNew->nLength] = (chr)0;
175 return pNew; 177 return pNew;
@@ -1142,12 +1144,15 @@ namespace Bu
1142 flatten(); 1144 flatten();
1143 _hardCopy(); 1145 _hardCopy();
1144 1146
1147 // TODO: This is bad
1148
1145 Chunk *pNew = core->newChunk( nNewSize ); 1149 Chunk *pNew = core->newChunk( nNewSize );
1146 long nNewLen = (nNewSize<core->nLength)?(nNewSize):(core->nLength); 1150 long nNewLen = (nNewSize<core->nLength)?(nNewSize):(core->nLength);
1147 if( core->nLength > 0 ) 1151 if( core->nLength > 0 )
1148 { 1152 {
1149 memcpy( pNew->pData, core->pFirst->pData, nNewLen ); 1153 memcpy( pNew->pData, core->pFirst->pData, nNewLen );
1150 core->aChr.deallocate( core->pFirst->pData, core->pFirst->nLength+1 ); 1154 core->aChr.deallocate( core->pFirst->pData,
1155 (core->pFirst->nLength<nMinSize)?(nMinSize):(core->pFirst->nLength)+1 );
1151 core->aChunk.deallocate( core->pFirst, 1 ); 1156 core->aChunk.deallocate( core->pFirst, 1 );
1152 } 1157 }
1153 pNew->pData[nNewLen] = (chr)0; 1158 pNew->pData[nNewLen] = (chr)0;
diff --git a/src/unit/string.unit b/src/unit/string.unit
index f51e4de..872dbed 100644
--- a/src/unit/string.unit
+++ b/src/unit/string.unit
@@ -348,4 +348,32 @@ suite String
348 b = a; 348 b = a;
349 b.getStr(); 349 b.getStr();
350 } 350 }
351
352 test padding1
353 {
354 Bu::String a;
355 a.append('a');
356 a.append('b');
357 a.append('c');
358 a.append("hello");
359 a.clear();
360 }
361
362 test padding2
363 {
364 Bu::String src("It's all sorts of things");
365 Bu::String::const_iterator i = src.find('a');
366 Bu::String::const_iterator j = src.find('f');
367 Bu::String a, b;
368 a.append( i );
369 i += 2;
370 a.append( i, j );
371 a.append('a');
372 a.append('b');
373 a.append('c');
374 a.append("hello");
375 a.append( src );
376 b = a;
377 a.clear();
378 }
351} 379}