checked the no-buffer condition in some string functions

This commit is contained in:
hyung-hwan 2017-08-31 11:20:50 +00:00
parent 5846d6c1a8
commit eb5e5c10d3

View File

@ -186,9 +186,11 @@ public:
if (capacity <= -1) if (capacity <= -1)
{ {
// this is a special constructor to instanatiate a string with no buffer. // this is a special constructor to instanatiate a string with no buffer.
// it is intended to be followed by truncate() for actual buffer allocation. // it is designed to be followed by truncate() immediately for actual buffer
// all other functions except the destructor and the truncation() function // allocation. all other functions except the copy/move constructors, some
// are not aware of this special condition. // assignment operators, the destructor and the truncation() function are
// not aware of this special condition. if you call other functions without
// truncate(), your program will end with a crash.
// //
// String x(0); // String x(0);
// try { x.truncate(10); } catch (...) { return -1; } // try { x.truncate(10); } catch (...) { return -1; }
@ -270,7 +272,9 @@ public:
StrBase (const SelfType& str): Mmged(str) StrBase (const SelfType& str): Mmged(str)
{ {
this->_item = str._item; this->_item = str._item;
this->ref_item ();
// check if this->_item is null or not to cater for a no buffer string
if (this->_item) this->ref_item ();
} }
#if defined(QSE_CPP_ENABLE_CPP11_MOVE) #if defined(QSE_CPP_ENABLE_CPP11_MOVE)
@ -291,7 +295,8 @@ public:
{ {
if (this->_item != str._item) if (this->_item != str._item)
{ {
this->deref_item (); // check if this->_item is null or not to cater for a no buffer string
if (this->_item) this->deref_item ();
// the data to be reference could be allocated using the // the data to be reference could be allocated using the
// memory manager of str. and it may be freed or resized by // memory manager of str. and it may be freed or resized by
@ -309,7 +314,8 @@ public:
{ {
if (this->_item != str._item) if (this->_item != str._item)
{ {
this->deref_item (); // check if this->_item is null or not to cater for a no buffer string
if (this->_item) this->deref_item ();
// the data to be reference could be allocated using the // the data to be reference could be allocated using the
// memory manager of str. and it may be freed or resized by // memory manager of str. and it may be freed or resized by