From 8c3f900fc99d77e478766a6b0fa34c23253cc79e Mon Sep 17 00:00:00 2001 From: Mike Buland Date: Thu, 20 Jan 2011 19:31:44 +0000 Subject: Fixed a really strang, really hard to nail down corner case in String --- src/string.h | 11 ++++++++--- src/unit/string.unit | 28 ++++++++++++++++++++++++++++ 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 for(;;) { Chunk *n = i->pNext; - aChr.deallocate( i->pData, i->nLength+1 ); + aChr.deallocate( i->pData, + (i->nLengthnLength)+1 ); aChunk.deallocate( i, 1 ); if( n == NULL ) break; @@ -169,7 +170,8 @@ namespace Bu Chunk *pNew = aChunk.allocate( 1 ); pNew->pNext = pSrc->pNext; pNew->nLength = pSrc->nLength; - pNew->pData = aChr.allocate( pSrc->nLength+1 ); + pNew->pData = aChr.allocate( + (pNew->nLengthnLength)+1 ); memcpy( pNew->pData, pSrc->pData, pSrc->nLength ); pNew->pData[pNew->nLength] = (chr)0; return pNew; @@ -1142,12 +1144,15 @@ namespace Bu flatten(); _hardCopy(); + // TODO: This is bad + Chunk *pNew = core->newChunk( nNewSize ); long nNewLen = (nNewSizenLength)?(nNewSize):(core->nLength); if( core->nLength > 0 ) { memcpy( pNew->pData, core->pFirst->pData, nNewLen ); - core->aChr.deallocate( core->pFirst->pData, core->pFirst->nLength+1 ); + core->aChr.deallocate( core->pFirst->pData, + (core->pFirst->nLengthpFirst->nLength)+1 ); core->aChunk.deallocate( core->pFirst, 1 ); } 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 b = a; b.getStr(); } + + test padding1 + { + Bu::String a; + a.append('a'); + a.append('b'); + a.append('c'); + a.append("hello"); + a.clear(); + } + + test padding2 + { + Bu::String src("It's all sorts of things"); + Bu::String::const_iterator i = src.find('a'); + Bu::String::const_iterator j = src.find('f'); + Bu::String a, b; + a.append( i ); + i += 2; + a.append( i, j ); + a.append('a'); + a.append('b'); + a.append('c'); + a.append("hello"); + a.append( src ); + b = a; + a.clear(); + } } -- cgit v1.2.3