Browse Source

Added check for another malloc() that might try to allocate 0 bytes.

Shane Kerr 14 years ago
parent
commit
865d62e9e5
2 changed files with 3 additions and 1 deletions
  1. 1 1
      src/lib/dns/buffer.h
  2. 2 0
      src/lib/dns/tests/buffer_unittest.cc

+ 1 - 1
src/lib/dns/buffer.h

@@ -323,7 +323,7 @@ public:
     /// \brief Assignment operator
     OutputBuffer& operator =(const OutputBuffer& other) {
         uint8_t* newbuff(static_cast<uint8_t*>(malloc(other.allocated_)));
-        if (newbuff == NULL) {
+        if (newbuff == NULL && other.allocated_ != 0) {
             throw std::bad_alloc();
         }
         free(buffer_);

+ 2 - 0
src/lib/dns/tests/buffer_unittest.cc

@@ -224,6 +224,8 @@ TEST_F(BufferTest, outputBufferZeroSize) {
     EXPECT_NO_THROW({
         OutputBuffer first(0);
         OutputBuffer copy(first);
+        OutputBuffer second(0);
+        second = first;
     });
 }