BIND 10 trac536, updated. aac391dda57b88507b8b10ac4bd1b068d3701b2d [trac536] Handle empty buffers

BIND 10 source code commits bind10-changes at lists.isc.org
Thu Apr 7 10:43:04 UTC 2011


The branch, trac536 has been updated
       via  aac391dda57b88507b8b10ac4bd1b068d3701b2d (commit)
      from  501462d7b9850ddca6a3d0a2c7043e3fa0923759 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
commit aac391dda57b88507b8b10ac4bd1b068d3701b2d
Author: Michal 'vorner' Vaner <michal.vaner at nic.cz>
Date:   Thu Apr 7 12:39:00 2011 +0200

    [trac536] Handle empty buffers

-----------------------------------------------------------------------

Summary of changes:
 src/lib/dns/buffer.h                 |    4 ++--
 src/lib/dns/tests/buffer_unittest.cc |    8 ++++++++
 2 files changed, 10 insertions(+), 2 deletions(-)

-----------------------------------------------------------------------
diff --git a/src/lib/dns/buffer.h b/src/lib/dns/buffer.h
index 39ca00b..1739d9d 100644
--- a/src/lib/dns/buffer.h
+++ b/src/lib/dns/buffer.h
@@ -296,7 +296,7 @@ public:
         // We use malloc and free instead of C++ new[] and delete[].
         // This way we can use realloc, which may in fact do it without a copy.
         buffer_ = static_cast<uint8_t*>(malloc(allocated_));
-        if (buffer_ == NULL) {
+        if (buffer_ == NULL && len != 0) {
             throw std::bad_alloc();
         }
     }
@@ -308,7 +308,7 @@ public:
         allocated_(other.allocated_)
     {
         buffer_ = static_cast<uint8_t*>(malloc(allocated_));
-        if (buffer_ == NULL) {
+        if (buffer_ == NULL && allocated_ != 0) {
             throw std::bad_alloc();
         }
         memcpy(buffer_, other.buffer_, size_);
diff --git a/src/lib/dns/tests/buffer_unittest.cc b/src/lib/dns/tests/buffer_unittest.cc
index 2d6ffcb..bb6c366 100644
--- a/src/lib/dns/tests/buffer_unittest.cc
+++ b/src/lib/dns/tests/buffer_unittest.cc
@@ -219,4 +219,12 @@ TEST_F(BufferTest, outputBufferAssign) {
     });
 }
 
+TEST_F(BufferTest, outputBufferZeroSize) {
+    // Some OSes might return NULL on malloc for 0 size, so check it works
+    EXPECT_NO_THROW({
+        OutputBuffer first(0);
+        OutputBuffer copy(first);
+    });
+}
+
 }




More information about the bind10-changes mailing list