• R/O
  • SSH
  • HTTPS

eirrepo: Commit


Commit MetaInfo

Revision198 (tree)
Time2019-03-04 00:28:04
Authorquiret

Log Message

- fixed a bug in eir::String where resizing did not zero-terminate

Change Summary

Incremental Difference

--- common/sdk/String.h (revision 197)
+++ common/sdk/String.h (revision 198)
@@ -337,7 +337,7 @@
337337 FSDataUtil::copy_impl( charsToAppend, charsToAppend + charsToAppendCount, useBuf + num_chars );
338338
339339 // We must re-put the null-terminator.
340- *( useBuf + newCharCount ) = charType();
340+ *( useBuf + newCharCount ) = (charType)0;
341341
342342 // Take over the new buffer.
343343 free_old_buffer( this, oldCharBuf, num_chars, isBufNew );
@@ -387,7 +387,7 @@
387387 FSDataUtil::copy_impl( charsToInsert, charsToInsert + charsToInsertCount, useBuf + insertPos );
388388
389389 // Put the zero terminator at the end.
390- *( useBuf + newCharCount ) = charType();
390+ *( useBuf + newCharCount ) = (charType)0;
391391
392392 // Take over the new stuff.
393393 free_old_buffer( this, oldCharBuf, oldCharCount, isBufNew );
@@ -461,9 +461,14 @@
461461 // If the string grows then it is padded with zeroes.
462462 inline void Resize( size_t numCodePoints )
463463 {
464- charType *oldCharBuf = this->data.char_data;
465464 size_t oldCharCount = this->data.num_chars;
466465
466+ // Nothing to do?
467+ if ( oldCharCount == numCodePoints )
468+ return;
469+
470+ charType *oldCharBuf = this->data.char_data;
471+
467472 charType *useBuf;
468473 bool isBufNew;
469474
@@ -475,6 +480,9 @@
475480 useBuf[ idx ] = (charType)0;
476481 }
477482
483+ // Zero-terminate.
484+ *( useBuf + numCodePoints ) = (charType)0;
485+
478486 // Destroy any previous buffer.
479487 free_old_buffer( this, oldCharBuf, oldCharCount, isBufNew );
480488
Show on old repository browser