]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[3959] Fixed output from OptionIntArray::toText for uint8 values.
authorMarcin Siodelski <marcin@isc.org>
Tue, 21 Jul 2015 15:50:25 +0000 (17:50 +0200)
committerMarcin Siodelski <marcin@isc.org>
Tue, 21 Jul 2015 15:50:25 +0000 (17:50 +0200)
src/lib/dhcp/option_int_array.h
src/lib/dhcp/tests/option_int_array_unittest.cc

index 8b03aa963649846542a1953768bf235b1fb1d2b0..e810bf14c3b0098a1102f14c9ee24ffdeb30fe70 100644 (file)
@@ -262,7 +262,20 @@ public:
         std::string data_type = OptionDataTypeUtil::getDataTypeName(OptionDataTypeTraits<T>::type);
         for (typename std::vector<T>::const_iterator value = values_.begin();
              value != values_.end(); ++value) {
-            output << " " << *value << "(" << data_type << ")";
+            output << " ";
+
+            // For 1 byte long data types we need to cast to the integer
+            // because they are usually implemented as "char" types, in
+            // which case the character rather than number would be printed.
+            if (OptionDataTypeTraits<T>::len == 1) {
+                output << static_cast<int>(*value);
+
+            } else {
+                output << *value;
+            }
+
+            // Append data type.
+            output << "(" << data_type << ")";
         }
 
         return (output.str());
index df18a3b47e7c1fd7259d9335b9a88f06d8135993..b60a9e896b38f6a326d018b30c7dd848f8194c30 100644 (file)
@@ -476,4 +476,18 @@ TEST_F(OptionIntArrayTest, toText) {
               option.toText());
 }
 
+// This test checks that the option holding multiple uint8 values
+// is correctly converted to the textual format.
+TEST_F(OptionIntArrayTest, toTextUint8) {
+    OptionUint8Array option(Option::V4, 128);
+    option.addValue(1);
+    option.addValue(7);
+    option.addValue(15);
+
+    EXPECT_EQ("type=128, len=003: 1(uint8) 7(uint8) 15(uint8)",
+              option.toText());
+}
+
+
+
 } // anonymous namespace