Browse Source

[3443] Minor changes after review.

Stephen Morris 9 years ago
parent
commit
24b35b847c
2 changed files with 10 additions and 9 deletions
  1. 6 6
      src/lib/util/buffer.h
  2. 4 3
      src/lib/util/tests/buffer_unittest.cc

+ 6 - 6
src/lib/util/buffer.h

@@ -196,7 +196,7 @@ public:
             throwError("read beyond end of buffer");
         }
 
-        std::memcpy(data, &data_[position_], len);
+        static_cast<void>(std::memmove(data, &data_[position_], len));
         position_ += len;
     }
     //@}
@@ -340,7 +340,7 @@ public:
             if (buffer_ == NULL) {
                 throw std::bad_alloc();
             }
-            std::memcpy(buffer_, other.buffer_, other.size_);
+            static_cast<void>(std::memmove(buffer_, other.buffer_, other.size_));
         }
     }
 
@@ -376,7 +376,7 @@ public:
                 // across.
                 free(buffer_);
                 buffer_ = newbuff;
-                static_cast<void>(std::memcpy(buffer_, other.buffer_, other.size_));
+                static_cast<void>(std::memmove(buffer_, other.buffer_, other.size_));
 
             } else {
 
@@ -460,7 +460,7 @@ public:
     /// This method is the destructive alternative to clear().
     void wipe() {
         if (buffer_ != NULL) {
-            memset(buffer_, 0, allocated_);
+            static_cast<void>(std::memset(buffer_, 0, allocated_));
         }
         size_ = 0;
     }
@@ -538,7 +538,7 @@ public:
     /// \param len The length of the data in bytes.
     void writeData(const void *data, size_t len) {
         ensureAllocated(size_ + len);
-        std::memcpy(buffer_ + size_, data, len);
+        static_cast<void>(std::memmove(buffer_ + size_, data, len));
         size_ += len;
     }
     //@}
@@ -553,7 +553,7 @@ private:
 
     /// \brief Ensure buffer is appropriate size
     ///
-    /// Checks that the buffer is at least equal to the size passed in as the
+    /// Checks that the buffer equal to or larger than the size given as
     /// argument and extends it to at least that size if not.
     ///
     /// \param needed_size The number of bytes required in the buffer

+ 4 - 3
src/lib/util/tests/buffer_unittest.cc

@@ -279,11 +279,12 @@ TEST_F(BufferTest, outputBufferAssign) {
 }
 
 TEST_F(BufferTest, outputEmptyBufferAssign) {
-    EXPECT_NO_THROW({
-        OutputBuffer copy(0);
+    OutputBuffer copy(0);
+    ASSERT_NO_THROW({
         copy = obuffer;
-        ASSERT_EQ(0, copy.getLength());
     });
+    ASSERT_EQ(0, copy.getLength());
+    EXPECT_EQ(NULL, copy.getData());
 }
 
 // Check assign to self doesn't break stuff