]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[3430] Changes in a bid to avoid a Coverity warning
authorStephen Morris <stephen@isc.org>
Mon, 28 Jul 2014 13:16:08 +0000 (14:16 +0100)
committerStephen Morris <stephen@isc.org>
Mon, 28 Jul 2014 13:16:08 +0000 (14:16 +0100)
Coverity picked up that a construct like "&array[ARRAY_LENGTH]" is
an access to an invalid element, although it is a valid marker
as the end of an STL range.  This change alters that construct
to "array + ARRAY_LENGTH".

src/lib/dhcp/pkt4.cc
src/lib/dhcp/tests/pkt4_unittest.cc

index 08107a512c18dec7253bdb3a15704a1b969726dc..d844d3ce0185367661fc1bfccd4643c1639d0bc7 100644 (file)
@@ -366,8 +366,8 @@ Pkt4::setSname(const uint8_t* sname, size_t snameLen /*= MAX_SNAME_LEN*/) {
         isc_throw(InvalidParameter, "Invalid sname specified");
     }
 
-    std::copy(&sname[0], &sname[snameLen], &sname_[0]);
-    std::fill(&sname_[snameLen], &sname_[MAX_SNAME_LEN], 0);
+    std::copy(sname, (sname + snameLen), sname_);
+    std::fill((sname_ + snameLen), (sname_ + MAX_SNAME_LEN), 0);
 
     // No need to store snameLen as any empty space is filled with 0s
 }
@@ -382,8 +382,8 @@ Pkt4::setFile(const uint8_t* file, size_t fileLen /*= MAX_FILE_LEN*/) {
         isc_throw(InvalidParameter, "Invalid file name specified");
     }
 
-    std::copy(&file[0], &file[fileLen], &file_[0]);
-    std::fill(&file_[fileLen], &file_[MAX_FILE_LEN], 0);
+    std::copy(file, (file + fileLen), file_);
+    std::fill((file_ + fileLen), (file_ + MAX_FILE_LEN), 0);
 
     // No need to store fileLen as any empty space is filled with 0s
 }
index bfebe77dae48c751b6f7dca3271d93608a2b0905..1f081370424b8e7f65293ee24dfce8b7085c76e7 100644 (file)
@@ -491,12 +491,12 @@ TEST_F(Pkt4Test, sname) {
 
     scoped_ptr<Pkt4> pkt;
     // Let's test each sname length, from 0 till 64
-    for (int snameLen = 0; snameLen < Pkt4::MAX_SNAME_LEN; snameLen++) {
-        for (int i = 0; i < Pkt4::MAX_SNAME_LEN; i++) {
-            sname[i] = 0;
+    for (int snameLen = 0; snameLen < Pkt4::MAX_SNAME_LEN; ++snameLen) {
+        for (int i = 0; i < snameLen; ++i) {
+            sname[i] = i + 1;
         }
-        for (int i = 0; i < snameLen; i++) {
-            sname[i] = i;
+        for (int i = snameLen; i < Pkt4::MAX_SNAME_LEN; ++i) {
+            sname[i] = 0;
         }
 
         // Type and transaction doesn't matter in this test
@@ -529,12 +529,12 @@ TEST_F(Pkt4Test, file) {
 
     scoped_ptr<Pkt4> pkt;
     // Let's test each file length, from 0 till 128.
-    for (int fileLen = 0; fileLen < Pkt4::MAX_FILE_LEN; fileLen++) {
-        for (int i = 0; i < Pkt4::MAX_FILE_LEN; i++) {
-            file[i] = 0;
+    for (int fileLen = 0; fileLen < Pkt4::MAX_FILE_LEN; ++fileLen) {
+        for (int i = 0; i < fileLen; ++i) {
+            file[i] = i + 1;
         }
-        for (int i = 0; i < fileLen; i++) {
-            file[i] = i;
+        for (int i = fileLen; i < Pkt4::MAX_FILE_LEN; ++i) {
+            file[i] = 0;
         }
 
         // Type and transaction doesn't matter in this test.