summaryrefslogtreecommitdiff
path: root/src/string.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/string.h')
-rw-r--r--src/string.h11
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;