mirror of
https://github.com/pocoproject/poco.git
synced 2025-10-16 18:56:52 +02:00
added zero-size check
This commit is contained in:
@@ -136,6 +136,7 @@ public:
|
|||||||
void append(const T* buf, std::size_t sz)
|
void append(const T* buf, std::size_t sz)
|
||||||
/// Resizes this buffer and appends the argument buffer.
|
/// Resizes this buffer and appends the argument buffer.
|
||||||
{
|
{
|
||||||
|
if (0 == sz) return;
|
||||||
std::size_t oldSize = _size;
|
std::size_t oldSize = _size;
|
||||||
resize(_size + sz, true);
|
resize(_size + sz, true);
|
||||||
std::memcpy(_ptr + oldSize, buf, sz);
|
std::memcpy(_ptr + oldSize, buf, sz);
|
||||||
@@ -177,6 +178,12 @@ public:
|
|||||||
return _ptr + _size;
|
return _ptr + _size;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool isEmpty() const
|
||||||
|
/// Return true if buffer is empty.
|
||||||
|
{
|
||||||
|
return 0 == _size;
|
||||||
|
}
|
||||||
|
|
||||||
T& operator [] (std::size_t index)
|
T& operator [] (std::size_t index)
|
||||||
{
|
{
|
||||||
poco_assert (index < _size);
|
poco_assert (index < _size);
|
||||||
@@ -196,7 +203,11 @@ private:
|
|||||||
void recreate(std::size_t newSize)
|
void recreate(std::size_t newSize)
|
||||||
{
|
{
|
||||||
delete [] _ptr;
|
delete [] _ptr;
|
||||||
_ptr = new T[newSize];
|
if (0 == newSize)
|
||||||
|
_ptr = 0;
|
||||||
|
else
|
||||||
|
_ptr = new T[newSize];
|
||||||
|
|
||||||
_size = newSize;
|
_size = newSize;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -216,6 +216,9 @@ void CoreTest::testBuffer()
|
|||||||
for (int j = 0; i < s; ++i, ++j)
|
for (int j = 0; i < s; ++i, ++j)
|
||||||
assert (b1[i] == j);
|
assert (b1[i] == j);
|
||||||
|
|
||||||
|
b1.resize(0);
|
||||||
|
assert (b1.isEmpty());
|
||||||
|
|
||||||
#if ENABLE_BUGCHECK_TEST
|
#if ENABLE_BUGCHECK_TEST
|
||||||
try { int i = b[s]; fail ("must fail"); }
|
try { int i = b[s]; fail ("must fail"); }
|
||||||
catch (Exception&) { }
|
catch (Exception&) { }
|
||||||
|
Reference in New Issue
Block a user