diff options
author | Mike Buland <eichlan@xagasoft.com> | 2011-01-20 19:31:44 +0000 |
---|---|---|
committer | Mike Buland <eichlan@xagasoft.com> | 2011-01-20 19:31:44 +0000 |
commit | 8c3f900fc99d77e478766a6b0fa34c23253cc79e (patch) | |
tree | 7af5fbcf01a15c6cc76c6a10e85e61ae931d32fe /src/string.h | |
parent | a9243f2c4e5cecfc0564f7951de92fd267510408 (diff) | |
download | libbu++-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 'src/string.h')
-rw-r--r-- | src/string.h | 11 |
1 files changed, 8 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; |