X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/bd362275b853cc0308bbde6a60bb2525d659f709..8e77fd8bca165aab9709649d79a7cbc6a172d4e1:/include/wx/buffer.h?ds=sidebyside diff --git a/include/wx/buffer.h b/include/wx/buffer.h index e0644474e8..951777a13c 100644 --- a/include/wx/buffer.h +++ b/include/wx/buffer.h @@ -230,7 +230,8 @@ protected: static CharType *StrCopy(const CharType *src, size_t len) { CharType *dst = (CharType*)malloc(sizeof(CharType) * (len + 1)); - memcpy(dst, src, sizeof(CharType) * (len + 1)); + if ( dst ) + memcpy(dst, src, sizeof(CharType) * (len + 1)); return dst; } @@ -312,6 +313,10 @@ public: if ( !str ) return false; + // For consistency with the ctor taking just the length, NUL-terminate + // the buffer. + str[len] = (CharType)0; + if ( this->m_data == this->GetNullData() ) { this->m_data = new Data(str, len); @@ -434,7 +439,7 @@ public: friend class wxMemoryBuffer; - // everyting is private as it can only be used by wxMemoryBuffer + // everything is private as it can only be used by wxMemoryBuffer private: wxMemoryBufferData(size_t size = wxMemoryBufferData::DefBufSize) : m_data(size ? malloc(size) : NULL), m_size(size), m_len(0), m_ref(0) @@ -535,6 +540,8 @@ public: size_t GetBufSize() const { return m_bufdata->m_size; } size_t GetDataLen() const { return m_bufdata->m_len; } + bool IsEmpty() const { return GetDataLen() == 0; } + void SetBufSize(size_t size) { m_bufdata->ResizeIfNeeded(size); } void SetDataLen(size_t len) { @@ -542,6 +549,8 @@ public: m_bufdata->m_len = len; } + void Clear() { SetDataLen(0); } + // Ensure the buffer is big enough and return a pointer to it void *GetWriteBuf(size_t sizeNeeded) {