]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[1602] use vector for offsets
authorJelte Jansen <jelte@isc.org>
Tue, 28 Feb 2012 11:30:04 +0000 (12:30 +0100)
committerJelte Jansen <jelte@isc.org>
Tue, 28 Feb 2012 11:30:04 +0000 (12:30 +0100)
src/lib/dns/labelsequence.cc
src/lib/dns/labelsequence.h

index bf80c360f49cc2944fc26ba043846de91b770077..10ee45ed9e9c26fac252f91baf1709bb659885eb 100644 (file)
 #include <dns/labelsequence.h>
 #include <exceptions/exceptions.h>
 
+#include <iostream>
 namespace isc {
 namespace dns {
 
 LabelSequence::LabelSequence(const Name& name) : name_(name),
-                             first_label_(0) {
-    size_t label_count_ = name.getLabelCount();
-    last_label_ = label_count_ - 1;
-    offsets_ = new size_t[label_count_];
+                             first_label_(0), offsets_(name.getLabelCount()) {
     offsets_[0] = 0;
-    for (size_t i = 1; i < label_count_; ++i) {
+    last_label_ = name.getLabelCount() - 1;
+    // Walk through the wire format data and store all offsets
+    for (size_t i = 1; i < offsets_.size(); ++i) {
+        // Each offset is the previous offset plus the length of the
+        // label plus 1 (for the label length octet)
         offsets_[i] = offsets_[i - 1] + name.at(offsets_[i - 1]) + 1;
     }
 }
 
-LabelSequence::~LabelSequence() {
-    delete[] offsets_;
-}
-
 const char*
 LabelSequence::getData(size_t *len) const {
     *len = offsets_[last_label_] - offsets_[first_label_];
@@ -57,20 +55,14 @@ LabelSequence::equals(const LabelSequence& other, bool case_sensitive) const {
 
 void
 LabelSequence::split(int i) {
+    if (abs(i) > getLabelCount()) {
+        isc_throw(OutOfRange, "Label " << i << " out of range (" <<
+                              getLabelCount() << ")");
+    }
     if (i > 0) {
-        if (i > getLabelCount()) {
-            isc_throw(OutOfRange, "Label " << i << " out of range (" <<
-                                  getLabelCount() << ")");
-        } else {
-            first_label_ += i;
-        }
+        first_label_ += i;
     } else if (i < 0) {
-        if (-i > getLabelCount()) {
-            isc_throw(OutOfRange, "Label " << i << " out of range (" <<
-                                  getLabelCount() << ")");
-        } else {
-            last_label_ += i;
-        }
+        last_label_ += i;
     }
 }
 
index 45af27471fade7f42c2a0dc45ce79632c20a4cd7..557dc1749d21f87b0c3890b1b7d2acd0fa45dc4a 100644 (file)
@@ -58,9 +58,6 @@ public:
     /// \param name The Name to construct a LabelSequence for
     LabelSequence(const Name& name);
 
-    /// \brief Destructor
-    ~LabelSequence();
-
     /// \brief Return the wire-format data for this LabelSequence
     ///
     /// The data, is returned as a pointer to the original wireformat
@@ -128,7 +125,7 @@ private:
     const Name& name_;
     size_t first_label_;
     size_t last_label_;
-    size_t* offsets_;
+    std::vector<size_t> offsets_;
 };