BIND 10 trac2726, updated. 797308ff2aedadc0281c8ca9c84daaa3c6d6d42c [2726] Initialize variables

BIND 10 source code commits bind10-changes at lists.isc.org
Wed Jun 12 09:22:09 UTC 2013


The branch, trac2726 has been updated
       via  797308ff2aedadc0281c8ca9c84daaa3c6d6d42c (commit)
       via  74625ee6146a2b28c4caaacef2fb9c9ba9876dd6 (commit)
      from  dc488cb9679c44617fdac1aebb6a821bddd39736 (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 797308ff2aedadc0281c8ca9c84daaa3c6d6d42c
Author: Michal 'vorner' Vaner <vorner at vorner.cz>
Date:   Wed Jun 12 11:21:56 2013 +0200

    [2726] Initialize variables

commit 74625ee6146a2b28c4caaacef2fb9c9ba9876dd6
Author: Michal 'vorner' Vaner <vorner at vorner.cz>
Date:   Wed Jun 12 11:05:39 2013 +0200

    [2726] Assign-to-self check

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

Summary of changes:
 src/lib/util/buffer.h                       |   18 ++++++++++--------
 src/lib/util/tests/buffer_unittest.cc       |    5 +++++
 src/lib/util/unittests/mock_socketsession.h |    7 ++++++-
 3 files changed, 21 insertions(+), 9 deletions(-)

-----------------------------------------------------------------------
diff --git a/src/lib/util/buffer.h b/src/lib/util/buffer.h
index 4800e99..4aac11e 100644
--- a/src/lib/util/buffer.h
+++ b/src/lib/util/buffer.h
@@ -342,15 +342,17 @@ public:
 
     /// \brief Assignment operator
     OutputBuffer& operator =(const OutputBuffer& other) {
-        uint8_t* newbuff(static_cast<uint8_t*>(malloc(other.allocated_)));
-        if (newbuff == NULL && other.allocated_ != 0) {
-            throw std::bad_alloc();
+        if (this != &other) {
+            uint8_t* newbuff(static_cast<uint8_t*>(malloc(other.allocated_)));
+            if (newbuff == NULL && other.allocated_ != 0) {
+                throw std::bad_alloc();
+            }
+            free(buffer_);
+            buffer_ = newbuff;
+            size_ = other.size_;
+            allocated_ = other.allocated_;
+            std::memcpy(buffer_, other.buffer_, size_);
         }
-        free(buffer_);
-        buffer_ = newbuff;
-        size_ = other.size_;
-        allocated_ = other.allocated_;
-        std::memcpy(buffer_, other.buffer_, size_);
         return (*this);
     }
 
diff --git a/src/lib/util/tests/buffer_unittest.cc b/src/lib/util/tests/buffer_unittest.cc
index 02ca83d..76b884c 100644
--- a/src/lib/util/tests/buffer_unittest.cc
+++ b/src/lib/util/tests/buffer_unittest.cc
@@ -248,6 +248,11 @@ TEST_F(BufferTest, outputBufferAssign) {
     });
 }
 
+// Check assign to self doesn't break stuff
+TEST_F(BufferTest, outputBufferAssignSelf) {
+    EXPECT_NO_THROW(obuffer = obuffer);
+}
+
 TEST_F(BufferTest, outputBufferZeroSize) {
     // Some OSes might return NULL on malloc for 0 size, so check it works
     EXPECT_NO_THROW({
diff --git a/src/lib/util/unittests/mock_socketsession.h b/src/lib/util/unittests/mock_socketsession.h
index 01ca34f..fb155a2 100644
--- a/src/lib/util/unittests/mock_socketsession.h
+++ b/src/lib/util/unittests/mock_socketsession.h
@@ -42,7 +42,12 @@ class MockSocketSessionForwarder :
 public:
     MockSocketSessionForwarder() :
         is_connected_(false), connect_ok_(true), push_ok_(true),
-        close_ok_(true)
+        close_ok_(true),
+        // These are not used until set, but we set them anyway here,
+        // partly to silence cppcheck, and partly to be cleaner. Put some
+        // invalid values in.
+        pushed_sock_(-1), pushed_family_(-1), pushed_type_(-1),
+        pushed_protocol_(-1)
     {}
 
     virtual void connectToReceiver() {



More information about the bind10-changes mailing list