X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/df04f800b84a71e6f1f5020fa03c2831fa87e6f2..8e77fd8bca165aab9709649d79a7cbc6a172d4e1:/include/wx/buffer.h diff --git a/include/wx/buffer.h b/include/wx/buffer.h index 254605edf7..951777a13c 100644 --- a/include/wx/buffer.h +++ b/include/wx/buffer.h @@ -15,9 +15,7 @@ #include "wx/chartype.h" #include "wx/wxcrtbase.h" -#ifndef __WXPALMOS5__ #include // malloc() and free() -#endif // ! __WXPALMOS5__ class WXDLLIMPEXP_FWD_BASE wxCStrData; @@ -232,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; } @@ -314,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); @@ -436,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) @@ -537,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) { @@ -544,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) {