]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[#3211] Almost done
authorFrancis Dupont <fdupont@isc.org>
Tue, 5 Mar 2024 17:44:51 +0000 (18:44 +0100)
committerFrancis Dupont <fdupont@isc.org>
Tue, 19 Mar 2024 23:18:24 +0000 (00:18 +0100)
43 files changed:
src/bin/dhcp4/tests/config_parser_unittest.cc
src/bin/dhcp4/tests/dhcp4_test_utils.cc
src/bin/dhcp4/tests/dhcp4to6_ipc_unittest.cc
src/bin/dhcp6/dhcp6_srv.cc
src/bin/dhcp6/tests/config_parser_unittest.cc
src/bin/dhcp6/tests/dhcp6to4_ipc_unittest.cc
src/bin/perfdhcp/localized_option.h
src/bin/perfdhcp/pkt_transform.cc
src/bin/perfdhcp/test_control.cc
src/bin/perfdhcp/tests/perf_pkt4_unittest.cc
src/hooks/dhcp/mysql_cb/mysql_cb_impl.cc
src/hooks/dhcp/pgsql_cb/pgsql_cb_impl.cc
src/lib/asiodns/tests/io_fetch_unittest.cc
src/lib/asiolink/tests/tcp_socket_unittest.cc
src/lib/asiolink/tests/tls_socket_unittest.cc
src/lib/asiolink/tests/udp_socket_unittest.cc
src/lib/cryptolink/tests/hash_unittests.cc
src/lib/cryptolink/tests/hmac_unittests.cc
src/lib/dhcp/libdhcp++.cc
src/lib/dhcp/opaque_data_tuple.h
src/lib/dhcp/option4_dnr.cc
src/lib/dhcp/pkt4o6.cc
src/lib/dhcp/pkt_filter_inet.cc
src/lib/dhcp/pkt_filter_inet6.cc
src/lib/dhcp/protocol_util.cc
src/lib/dhcp/tests/opaque_data_tuple_unittest.cc
src/lib/dhcp/tests/option6_iaprefix_unittest.cc
src/lib/dhcp/tests/option6_pdexclude_unittest.cc
src/lib/dhcp/tests/option_opaque_data_tuples_unittest.cc
src/lib/dhcp/tests/option_unittest.cc
src/lib/dhcp/tests/option_vendor_class_unittest.cc
src/lib/dhcp/tests/pkt4_unittest.cc
src/lib/dhcp/tests/pkt_filter6_test_utils.cc
src/lib/dhcp_ddns/ncr_udp.cc
src/lib/dhcpsrv/alloc_engine.cc
src/lib/dhcpsrv/mysql_host_data_source.cc
src/lib/dhcpsrv/pgsql_host_data_source.cc
src/lib/dhcpsrv/tests/dhcp4o6_ipc_unittest.cc
src/lib/dns/tests/labelsequence_unittest.cc
src/lib/util/buffer.h
src/lib/util/io/socketsession.cc
src/lib/util/tests/buffer_unittest.cc
src/lib/util/tests/io_utilities_unittest.cc

index e3954e08ed851263acfd978f33a972ed0112f142..4da0834c84baf7ef64c23446a6cc907fc4b59c54 100644 (file)
@@ -594,7 +594,7 @@ public:
                       expected_data_len);
         }
         // Verify that the data is correct. Do not verify suboptions and a header.
-        const uint8_t* data = static_cast<const uint8_t*>(buf.getData());
+        const uint8_t* data = buf.getData();
         EXPECT_EQ(0, memcmp(expected_data, data + option_desc.option_->getHeaderLen(),
                             expected_data_len));
     }
index fa304f3cc1e6edd89f46c191e35a2de41d8d7dbe..94dfe6f48f92109d155258bd839f876e0849a1ea 100644 (file)
@@ -585,8 +585,7 @@ Dhcpv4SrvTest::createPacketFromBuffer(const Pkt4Ptr& src_pkt,
     // Create a copy of the packet using the output buffer from the source
     // packet.
     try {
-        dst_pkt.reset(new Pkt4(static_cast<const uint8_t*>(buf.getData()),
-                               buf.getLength()));
+        dst_pkt.reset(new Pkt4(buf.getData(), buf.getLength()));
     } catch (const Exception& ex) {
         return (::testing::AssertionFailure(::testing::Message()
                                             << "Failed to create a"
index b586d286d6ea03f359eb24713696161a1ec749d3..713ccb8fe6140f83755db091f8deb09f1583e6ca 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2015-2023 Internet Systems Consortium, Inc. ("ISC")
+// Copyright (C) 2015-2024 Internet Systems Consortium, Inc. ("ISC")
 //
 // This Source Code Form is subject to the terms of the Mozilla Public
 // License, v. 2.0. If a copy of the MPL was not distributed with this
@@ -181,7 +181,7 @@ Dhcp4to6IpcTest::createDHCPv4MsgOption() const {
     // Make a wire representation of the DHCPv4 message.
     pkt->pack();
     OutputBuffer& output_buffer = pkt->getBuffer();
-    const uint8_t* data = static_cast<const uint8_t*>(output_buffer.getData());
+    const uint8_t* data = output_buffer.getData();
     OptionBuffer option_buffer(data, data + output_buffer.getLength());
 
     // Create the DHCPv4 Message option holding the created message.
@@ -335,7 +335,7 @@ TEST_F(Dhcp4to6IpcTest, process) {
     // Make a wire representation of the DHCPv4 message.
     infreq->pack();
     OutputBuffer& output_buffer = infreq->getBuffer();
-    const uint8_t* data = static_cast<const uint8_t*>(output_buffer.getData());
+    const uint8_t* data = output_buffer.getData();
     OptionBuffer option_buffer(data, data + output_buffer.getLength());
 
     // Create the DHCPv4 Message option holding the created message.
index 1e9468e46b156050e5a29abcf27e8ee79de3a455..58fb5c9b836de1914dbaaf65eb5afc3021aeb349 100644 (file)
@@ -2345,7 +2345,7 @@ Dhcpv6Srv::createNameChangeRequests(const Pkt6Ptr& answer,
     // DHCID.
     OutputBuffer name_buf(1);
     opt_fqdn->packDomainName(name_buf);
-    const uint8_t* name_data = static_cast<const uint8_t*>(name_buf.getData());
+    const uint8_t* name_data = name_buf.getData();
     // @todo currently D2Dhcid accepts a vector holding FQDN.
     // However, it will be faster if we used a pointer name_data.
     std::vector<uint8_t> buf_vec(name_data, name_data + name_buf.getLength());
index 7d5cc854aae34a238944e983cd6c591d35a3fb88..1a0161b41b2088adf68469a1710f17eabe6dd42b 100644 (file)
@@ -874,8 +874,9 @@ public:
                       expected_data_len);
         }
         // Verify that the data is correct. Do not verify suboptions and a header.
-        const uint8_t* data = static_cast<const uint8_t*>(buf.getData());
-        EXPECT_EQ(0, memcmp(expected_data, data + option_desc.option_->getHeaderLen(),
+        const uint8_t* data = buf.getData();
+        EXPECT_EQ(0, memcmp(expected_data,
+                            data + option_desc.option_->getHeaderLen(),
                             expected_data_len));
     }
 
index 019c3c8e69beabe460a661f2e12afc298b6d40b5..42310716056db591ddc8e5baae82e6fb924c0569 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2015-2023 Internet Systems Consortium, Inc. ("ISC")
+// Copyright (C) 2015-2024 Internet Systems Consortium, Inc. ("ISC")
 //
 // This Source Code Form is subject to the terms of the Mozilla Public
 // License, v. 2.0. If a copy of the MPL was not distributed with this
@@ -127,7 +127,7 @@ Dhcp6to4IpcTest::createDHCPv4MsgOption() const {
     // Make a wire representation of the DHCPv4 message.
     pkt->pack();
     OutputBuffer& output_buffer = pkt->getBuffer();
-    const uint8_t* data = static_cast<const uint8_t*>(output_buffer.getData());
+    const uint8_t* data = output_buffer.getData();
     OptionBuffer option_buffer(data, data + output_buffer.getLength());
 
     // Create the DHCPv4 Message option holding the created message.
index 289ff7dcdc78f003027a004a87e9f703c1150f9d..d0201c8999a151fa102c9a55a658ba13577de545 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2012-2016 Internet Systems Consortium, Inc. ("ISC")
+// Copyright (C) 2012-2024 Internet Systems Consortium, Inc. ("ISC")
 //
 // This Source Code Form is subject to the terms of the Mozilla Public
 // License, v. 2.0. If a copy of the MPL was not distributed with this
@@ -100,7 +100,7 @@ public:
                 // Try to pack option data into the temporary buffer.
                 opt_ia->pack(buf);
                 if (buf.getLength() > 0) {
-                    const char* buf_data = static_cast<const char*>(buf.getData());
+                    const uint8_t* buf_data = buf.getData();
                     // Option has been packed along with option type flag
                     // and transaction id so we have to skip first 4 bytes
                     // when copying temporary buffer option buffer.
index 7801187e4a862fd73c405a6dd17808c1ef116095..fa608085b8cb5c5212f2ca340da5302cc9e99cb3 100644 (file)
@@ -139,8 +139,7 @@ PktTransform::packOptions(const OptionBuffer& in_buffer,
             // OutputBuffer class has nice functions that write
             // data at the specified position so we can use it to
             // inject contents of temporary buffer to output buffer.
-            const uint8_t *buf_data =
-                static_cast<const uint8_t*>(buf.getData());
+            const uint8_t *buf_data = buf.getData();
             for (size_t i = 0; i < buf.getLength(); ++i) {
                 out_buffer.writeUint8At(buf_data[i], offset + i);
             }
index d7d2e81ec18ec267d53eebe8c9c8620708f785f0..ef420037e860684731efc1b6ac522d68af3f40b9 100644 (file)
@@ -631,8 +631,7 @@ TestControl::printTemplate(const uint8_t packet_type) const {
         if ((pkt_it != template_packets_v4_.end()) &&
             pkt_it->second) {
             const util::OutputBuffer& out_buf(pkt_it->second->getBuffer());
-            const char* out_buf_data =
-                static_cast<const char*>(out_buf.getData());
+            const uint8_t* out_buf_data = out_buf.getData();
             std::vector<uint8_t> buf(out_buf_data, out_buf_data + out_buf.getLength());
             hex_buf = vector2Hex(buf);
         }
@@ -645,8 +644,7 @@ TestControl::printTemplate(const uint8_t packet_type) const {
         if (pkt_it != template_packets_v6_.end() &&
             pkt_it->second) {
             const util::OutputBuffer& out_buf(pkt_it->second->getBuffer());
-            const char* out_buf_data =
-                static_cast<const char*>(out_buf.getData());
+            const uint8_t* out_buf_data = out_buf.getData();
             std::vector<uint8_t> buf(out_buf_data, out_buf_data + out_buf.getLength());
             hex_buf = vector2Hex(buf);
         }
index b162051227e4690fd13256dacf1f2a877d268fdc..0a3328b49f668a47b14ca51ba8313f97ecd14867 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2012-2017 Internet Systems Consortium, Inc. ("ISC")
+// Copyright (C) 2012-2024 Internet Systems Consortium, Inc. ("ISC")
 //
 // This Source Code Form is subject to the terms of the Mozilla Public
 // License, v. 2.0. If a copy of the MPL was not distributed with this
@@ -172,8 +172,7 @@ TEST_F(PerfPkt4Test, RawPack) {
     // DHO_BOOT_SIZE options.
     util::OutputBuffer pkt_output = pkt->getBuffer();
     ASSERT_EQ(buf.size(), pkt_output.getLength());
-    const uint8_t* out_buf_data =
-        static_cast<const uint8_t*>(pkt_output.getData());
+    const uint8_t* out_buf_data = pkt_output.getData();
 
     // Check if options we read from buffer is valid.
     EXPECT_EQ(0, memcmp(buf_hostname,
@@ -321,8 +320,7 @@ TEST_F(PerfPkt4Test, PackTransactionId) {
     // Get packet's output buffer and make sure it has valid size.
     util::OutputBuffer out_buf = pkt1->getBuffer();
     ASSERT_EQ(buf.size(), out_buf.getLength());
-    const uint8_t *out_buf_data =
-        static_cast<const uint8_t*>(out_buf.getData());
+    const uint8_t *out_buf_data = out_buf.getData();
 
     // Initialize reference data for transaction id.
     const uint8_t ref_data[] = { 0, 0, 1, 2 };
@@ -398,7 +396,7 @@ TEST_F(PerfPkt4Test, Writes) {
     const util::OutputBuffer& out_buf = pkt1->getBuffer();
     ASSERT_EQ(in_data.size(), out_buf.getLength());
     // Verify that 4,5,6,7 has been written to the packet's buffer.
-    const char* out_data = static_cast<const char*>(out_buf.getData());
+    const uint8_t* out_data = out_buf.getData();
     EXPECT_TRUE(std::equal(write_buf.begin() + 3, write_buf.begin() + 7,
                           out_data + 10));
     // Write 1 octet (0x51) at position 10.
index 1f4b0a38d37415bde731b02fd31c80a8bd3ee1a1..9e8648a4310fc4534b653453a85aa9f5f8095ba1 100644 (file)
@@ -967,7 +967,7 @@ MySqlConfigBackendImpl::createOptionValueBinding(const OptionDescriptorPtr& opti
     if (option->formatted_value_.empty() && (opt->len() > opt->getHeaderLen())) {
         OutputBuffer buf(opt->len());
         opt->pack(buf);
-        const char* buf_ptr = static_cast<const char*>(buf.getData());
+        const uint8_t* buf_ptr = buf.getData();
         std::vector<uint8_t> blob(buf_ptr + opt->getHeaderLen(),
                                   buf_ptr + buf.getLength());
         return (MySqlBinding::createBlob(blob.begin(), blob.end()));
index 07f4e292942f3b13da51074a934c468fe6ef6f14..8b3746801722d510173059d13f8c3322d3aab38e 100644 (file)
@@ -1139,7 +1139,7 @@ PgSqlConfigBackendImpl::addOptionValueBinding(PsqlBindArray& bindings,
     if (option->formatted_value_.empty() && (opt->len() > opt->getHeaderLen())) {
         OutputBuffer buf(opt->len());
         opt->pack(buf);
-        const char* buf_ptr = static_cast<const char*>(buf.getData());
+        const uint8_t* buf_ptr = buf.getData();
         std::vector<uint8_t> blob(buf_ptr + opt->getHeaderLen(),
                                   buf_ptr + buf.getLength());
         bindings.addTempBinary(blob);
index 1001807ccdb4f3531e1a34cb1897596fd0ad4622..47bac7ce93abdd518af12d357acaed258eced360 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2011-2020 Internet Systems Consortium, Inc. ("ISC")
+// Copyright (C) 2011-2024 Internet Systems Consortium, Inc. ("ISC")
 //
 // This Source Code Form is subject to the terms of the Mozilla Public
 // License, v. 2.0. If a copy of the MPL was not distributed with this
@@ -200,7 +200,7 @@ public:
         // identical, then check that the data is identical as well.
         EXPECT_EQ(msgbuf_->getLength(), length);
         EXPECT_TRUE(equal(receive_buffer_, (receive_buffer_ + length - 1),
-        static_cast<const uint8_t*>(msgbuf_->getData())));
+                          msgbuf_->getData()));
 
         // Return a message back to the IOFetch object.
         if (!bad_qid) {
@@ -313,7 +313,7 @@ public:
 
         receive_buffer_[2] = receive_buffer_[3] = 0;
         EXPECT_TRUE(equal((receive_buffer_ + 2), (receive_buffer_ + cumulative_ - 2),
-            static_cast<const uint8_t*>(msgbuf_->getData())));
+                          msgbuf_->getData()));
 
         // ... and return a message back.  This has to be preceded by a two-byte
         // count field.
@@ -473,7 +473,7 @@ public:
                     result_buff_->writeUint8At(return_data_[0], 0);
                     result_buff_->writeUint8At(return_data_[1], 1);
                 }
-                const uint8_t* start = static_cast<const uint8_t*>(result_buff_->getData());
+                const uint8_t* start = result_buff_->getData();
                 EXPECT_TRUE(equal(return_data_.begin(), return_data_.end(), start));
             }
         }
index 1f2ff42b4f6a1daa9a9ab4474dfa594a6ac97564..9486b582d822e99f4dadd3a354f7b13750070101 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2011-2021 Internet Systems Consortium, Inc. ("ISC")
+// Copyright (C) 2011-2024 Internet Systems Consortium, Inc. ("ISC")
 //
 // This Source Code Form is subject to the terms of the Mozilla Public
 // License, v. 2.0. If a copy of the MPL was not distributed with this
@@ -283,7 +283,7 @@ TEST(TCPSocket, processReceivedData) {
     EXPECT_EQ(PACKET_SIZE, expected);
     EXPECT_EQ(2, outbuff->getLength());
 
-    const uint8_t* dataptr = static_cast<const uint8_t*>(outbuff->getData());
+    const uint8_t* dataptr = outbuff->getData();
     EXPECT_TRUE(equal(inbuff + 2, inbuff + cumulative, dataptr));
 
     // And add the remaining data.  Remember that "inbuff" is "PACKET_SIZE + 2"
@@ -296,7 +296,7 @@ TEST(TCPSocket, processReceivedData) {
     EXPECT_EQ(0, offset);
     EXPECT_EQ(PACKET_SIZE, expected);
     EXPECT_EQ(PACKET_SIZE, outbuff->getLength());
-    dataptr = static_cast<const uint8_t*>(outbuff->getData());
+    dataptr = outbuff->getData();
     EXPECT_TRUE(equal(inbuff + 2, inbuff + cumulative, dataptr));
 }
 
@@ -505,7 +505,7 @@ TEST(TCPSocket, sequenceTest) {
     EXPECT_EQ(sizeof(INBOUND_DATA) + 2, server_cb.length());
 
     // ... and that what was sent is what was received.
-    const uint8_t* received = static_cast<const uint8_t*>(client_buffer->getData());
+    const uint8_t* received = client_buffer->getData();
     EXPECT_TRUE(equal(INBOUND_DATA, (INBOUND_DATA + (sizeof(INBOUND_DATA) - 1)),
                       received));
 
index 57773f69cb9e1a8796d0138174be3ed10e194641..e5c21d8c14939366cef4c04da6b7b8a373fd062f 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2011-2021 Internet Systems Consortium, Inc. ("ISC")
+// Copyright (C) 2011-2024 Internet Systems Consortium, Inc. ("ISC")
 //
 // This Source Code Form is subject to the terms of the Mozilla Public
 // License, v. 2.0. If a copy of the MPL was not distributed with this
@@ -293,7 +293,7 @@ TEST(TLSSocket, processReceivedData) {
     EXPECT_EQ(PACKET_SIZE, expected);
     EXPECT_EQ(2, outbuff->getLength());
 
-    const uint8_t* dataptr = static_cast<const uint8_t*>(outbuff->getData());
+    const uint8_t* dataptr = outbuff->getData();
     EXPECT_TRUE(equal(inbuff + 2, inbuff + cumulative, dataptr));
 
     // And add the remaining data.  Remember that "inbuff" is "PACKET_SIZE + 2"
@@ -306,7 +306,7 @@ TEST(TLSSocket, processReceivedData) {
     EXPECT_EQ(0, offset);
     EXPECT_EQ(PACKET_SIZE, expected);
     EXPECT_EQ(PACKET_SIZE, outbuff->getLength());
-    dataptr = static_cast<const uint8_t*>(outbuff->getData());
+    dataptr = outbuff->getData();
     EXPECT_TRUE(equal(inbuff + 2, inbuff + cumulative, dataptr));
 }
 
@@ -550,7 +550,7 @@ TEST(TLSSocket, sequenceTest) {
     EXPECT_EQ(sizeof(INBOUND_DATA) + 2, server_cb.length());
 
     // ... and that what was sent is what was received.
-    const uint8_t* received = static_cast<const uint8_t*>(client_buffer->getData());
+    const uint8_t* received = client_buffer->getData();
     EXPECT_TRUE(equal(INBOUND_DATA, (INBOUND_DATA + (sizeof(INBOUND_DATA) - 1)),
                       received));
 
index 5ef43c167d4119c2da2a01b46821add25aea58ed..0668414ceda807877a3aef6f2cf943b8a2f4e668 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2011-2020 Internet Systems Consortium, Inc. ("ISC")
+// Copyright (C) 2011-2024 Internet Systems Consortium, Inc. ("ISC")
 //
 // This Source Code Form is subject to the terms of the Mozilla Public
 // License, v. 2.0. If a copy of the MPL was not distributed with this
@@ -194,7 +194,7 @@ TEST(UDPSocket, processReceivedData) {
         EXPECT_EQ(0, offset);
         EXPECT_EQ(sizeof(inbuff), expected);
 
-        const uint8_t* dataptr = static_cast<const uint8_t*>(outbuff->getData());
+        const uint8_t* dataptr = outbuff->getData();
         EXPECT_TRUE(equal(inbuff, inbuff + sizeof(inbuff) - 1, dataptr));
     }
 }
@@ -310,7 +310,7 @@ TEST(UDPSocket, SequenceTest) {
     EXPECT_EQ(client_cb.getLength(), client_buffer->getLength());
 
     // ...and check that the data was copied to the output client buffer.
-    const char* client_char_data = static_cast<const char*>(client_buffer->getData());
+    const uint8_t* client_char_data = client_buffer->getData();
     EXPECT_TRUE(equal(&data[0], &data[client_cb.getLength() - 1], client_char_data));
 
     // Close client and server.
index cd747b4f4df139d2ed05dd9a04148e32e4799623..a8c6ded6ab64d3254a58d1fbf44b8cc063616dd6 100644 (file)
@@ -50,8 +50,7 @@ namespace {
                      size_t len)
     {
         ASSERT_EQ(len, buf.getLength());
-        checkData(static_cast<const uint8_t*>(buf.getData()), expected,
-                  len);
+        checkData(buf.getData(), expected, len);
     }
 
     /// @brief Hash with the convenience functions
index ab133e51d43c580132638e73b143d11241ebb60d..d5c6a83ab2b1c3c4ad69a9c36b706074ffe9de53 100644 (file)
@@ -60,8 +60,7 @@ namespace {
                      size_t len)
     {
         ASSERT_EQ(len, buf.getLength());
-        checkData(static_cast<const uint8_t*>(buf.getData()), expected,
-                  len);
+        checkData(buf.getData(), expected, len);
     }
 
     /// @brief Sign and verify with the convenience functions
index 8e5b794be409f80cd6f08b75138ab8b97031aef2..ef39c58c5d797b454123750c348589a118880309 100644 (file)
@@ -1193,7 +1193,7 @@ LibDHCP::splitOptions4(OptionCollection& options,
                     }
                     // Create new option with data starting from offset and
                     // containing truncated length.
-                    const uint8_t* data = static_cast<const uint8_t*>(buf.getData());
+                    const uint8_t* data = buf.getData();
                     data += header_len;
                     OptionPtr new_option(new Option(candidate->getUniverse(),
                                                     candidate->getType(),
index 66a53dcc179172074b24abe159299600df88604d..a8f5528eea6d4e4b2ae292ca9881ee76a16103b4 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2014-2023 Internet Systems Consortium, Inc. ("ISC")
+// Copyright (C) 2014-2024 Internet Systems Consortium, Inc. ("ISC")
 //
 // This Source Code Form is subject to the terms of the Mozilla Public
 // License, v. 2.0. If a copy of the MPL was not distributed with this
@@ -104,6 +104,9 @@ public:
     void append(const char* data, const size_t len) {
         data_.insert(data_.end(), data, data + len);
     }
+    void append(const uint8_t* data, const size_t len) {
+        data_.insert(data_.end(), data, data + len);
+    }
     void append(InputIterator data, const size_t len) {
         data_.insert(data_.end(), data, data + len);
     }
index 03bcdcd1f1a4d121bf01572b12902ef251faca66..7f292913ef014f95f742d7b223d969df593bf6db 100644 (file)
@@ -808,7 +808,7 @@ DnrInstance::parseAlpnSvcParam(const std::string& svc_param_val) {
         alpn_id_tuple.pack(out_buf);
     }
 
-    svc_param_val_tuple.append(static_cast<const char*>(out_buf.getData()), out_buf.getLength());
+    svc_param_val_tuple.append(out_buf.getData(), out_buf.getLength());
     svc_params_map_.insert(std::make_pair(1, svc_param_val_tuple));
     out_buf.clear();
 }
@@ -830,7 +830,7 @@ DnrInstance::parsePortSvcParam(const std::string& svc_param_val) {
     }
 
     out_buf.writeUint16(port);
-    svc_param_val_tuple.append(static_cast<const char*>(out_buf.getData()), out_buf.getLength());
+    svc_param_val_tuple.append(out_buf.getData(), out_buf.getLength());
     out_buf.clear();
     svc_params_map_.insert(std::make_pair(3, svc_param_val_tuple));
 }
index 8374b3463a3bb2d8b9e0a70ce42556ebb1a7aa12..3c526aaf12eaee2b2392ca0b7a84e675fd922d2f 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2015-2016 Internet Systems Consortium, Inc. ("ISC")
+// Copyright (C) 2015-2024 Internet Systems Consortium, Inc. ("ISC")
 //
 // This Source Code Form is subject to the terms of the Mozilla Public
 // License, v. 2.0. If a copy of the MPL was not distributed with this
@@ -37,7 +37,7 @@ void Pkt4o6::pack() {
     // Convert wire-format Pkt4 data in the form of OptionBuffer.
     Pkt4::pack();
     OutputBuffer& buf = getBuffer();
-    const uint8_t* ptr = static_cast<const uint8_t*>(buf.getData());
+    const uint8_t* ptr = buf.getData();
     OptionBuffer msg(ptr, ptr + buf.getLength());
 
     // Build the DHCPv4 Message option for the DHCPv6 message, and pack the
index 5972a4de58167db24042065b06ad1420bfd9308f..3de58912ffe7dcef7da72120dea094a3ef906971 100644 (file)
@@ -269,7 +269,7 @@ PktFilterInet::send(const Iface&, uint16_t sockfd, const Pkt4Ptr& pkt) {
     memset(&v, 0, sizeof(v));
     // iov_base field is of void * type. We use it for packet
     // transmission, so this buffer will not be modified.
-    v.iov_base = const_cast<void *>(pkt->getBuffer().getData());
+    v.iov_base = const_cast<void *>(pkt->getBuffer().getDataAsVP());
     v.iov_len = pkt->getBuffer().getLength();
     m.msg_iov = &v;
     m.msg_iovlen = 1;
index 443e19101d05e45eb7c6c25db339079701a19d13..8328b6532058420d0b3f24c28df70072c690e95a 100644 (file)
@@ -322,7 +322,7 @@ PktFilterInet6::send(const Iface&, uint16_t sockfd, const Pkt6Ptr& pkt) {
     // to assign const void* to void*.
     struct iovec v;
     memset(&v, 0, sizeof(v));
-    v.iov_base = const_cast<void *>(pkt->getBuffer().getData());
+    v.iov_base = const_cast<void *>(pkt->getBuffer().getDataAsVP());
     v.iov_len = pkt->getBuffer().getLength();
     m.msg_iov = &v;
     m.msg_iovlen = 1;
index 9728cf4ed490458f314c410133e626b9573bdb9a..da701045c8fc8f6413dc3a01c82970cf04c5b9cb 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2013-2022 Internet Systems Consortium, Inc. ("ISC")
+// Copyright (C) 2013-2024 Internet Systems Consortium, Inc. ("ISC")
 //
 // This Source Code Form is subject to the terms of the Mozilla Public
 // License, v. 2.0. If a copy of the MPL was not distributed with this
@@ -186,11 +186,11 @@ writeIpUdpHeader(const Pkt4Ptr& pkt, util::OutputBuffer& out_buf) {
     // 4 bytes of source address and 4 bytes of destination address.
     // The IPPROTO_UDP and udp_len are also added up to the checksum.
     uint16_t pseudo_hdr_checksum =
-        calcChecksum(static_cast<const uint8_t*>(out_buf.getData()) + out_buf.getLength() - 8,
+        calcChecksum(out_buf.getData() + out_buf.getLength() - 8,
                      8, IPPROTO_UDP + udp_len);
 
     // Calculate IP header checksum.
-    uint16_t ip_checksum = ~calcChecksum(static_cast<const uint8_t*>(out_buf.getData())
+    uint16_t ip_checksum = ~calcChecksum(out_buf.getData()
                                          + out_buf.getLength() - 20, 20);
     // Write checksum in the IP header. The offset of the checksum is 10 bytes
     // back from the tail of the current buffer.
@@ -206,8 +206,8 @@ writeIpUdpHeader(const Pkt4Ptr& pkt, util::OutputBuffer& out_buf) {
     // tail of the current buffer. These 6 bytes contain source and destination port
     // as well as the length of the header.
     uint16_t udp_checksum =
-        ~calcChecksum(static_cast<const uint8_t*>(out_buf.getData()) + out_buf.getLength() - 6, 6,
-                      calcChecksum(static_cast<const uint8_t*>(pkt->getBuffer().getData()),
+        ~calcChecksum(out_buf.getData() + out_buf.getLength() - 6, 6,
+                      calcChecksum(pkt->getBuffer().getData(),
                                    pkt->getBuffer().getLength(),
                                    pseudo_hdr_checksum));
     // Write UDP checksum.
index 974a0bf27bbc97f07b39eff6cc647f12175b95c6..4b97aae7a81891915b30c9a5b61b1bb511c42646 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2014-2021 Internet Systems Consortium, Inc. ("ISC")
+// Copyright (C) 2014-2024 Internet Systems Consortium, Inc. ("ISC")
 //
 // This Source Code Form is subject to the terms of the Mozilla Public
 // License, v. 2.0. If a copy of the MPL was not distributed with this
@@ -275,7 +275,7 @@ TEST(OpaqueDataTuple, pack1Byte) {
     OutputBuffer out_buf(10);
     ASSERT_NO_THROW(tuple.pack(out_buf));
     ASSERT_EQ(1, out_buf.getLength());
-    const uint8_t* zero_len = static_cast<const uint8_t*>(out_buf.getData());
+    const uint8_t* zero_len = out_buf.getData();
     ASSERT_EQ(0, *zero_len);
     // Reset the output buffer for another test.
     out_buf.clear();
@@ -292,8 +292,7 @@ TEST(OpaqueDataTuple, pack1Byte) {
     ASSERT_EQ(101, out_buf.getLength());
     // Get the rendered data into the vector for convenience.
     std::vector<uint8_t>
-        render_data(static_cast<const uint8_t*>(out_buf.getData()),
-                    static_cast<const uint8_t*>(out_buf.getData()) + 101);
+        render_data(out_buf.getData(), out_buf.getData() + 101);
     // The first byte is a length byte. It should hold the length of 100.
     EXPECT_EQ(100, render_data[0]);
     // Verify that the rendered data is correct.
@@ -314,8 +313,7 @@ TEST(OpaqueDataTuple, pack1Byte) {
     // opaque data length, the remaining bytes hold the actual data.
     ASSERT_EQ(256, out_buf.getLength());
     // Check that the data is correct.
-    render_data.assign(static_cast<const uint8_t*>(out_buf.getData()),
-                       static_cast<const uint8_t*>(out_buf.getData()) + 256);
+    render_data.assign(out_buf.getData(), out_buf.getData() + 256);
     EXPECT_EQ(255, render_data[0]);
     EXPECT_TRUE(std::equal(render_data.begin() + 1, render_data.end(),
                            data.begin()));
@@ -339,8 +337,10 @@ TEST(OpaqueDataTuple, pack2Bytes) {
     OutputBuffer out_buf(10);
     ASSERT_NO_THROW(tuple.pack(out_buf));
     ASSERT_EQ(2, out_buf.getLength());
-    const uint16_t* zero_len = static_cast<const uint16_t*>(out_buf.getData());
-    ASSERT_EQ(0, *zero_len);
+    const uint8_t* out_data = out_buf.getData();
+    ASSERT_LE(sizeof(uint16_t), out_buf.getLength());
+    ASSERT_EQ(0, out_data[0]);
+    ASSERT_EQ(0, out_data[1]);
     // Reset the output buffer for another test.
     out_buf.clear();
     // Set the data for tuple.
@@ -356,8 +356,7 @@ TEST(OpaqueDataTuple, pack2Bytes) {
     ASSERT_EQ(514, out_buf.getLength());
     // Get the rendered data into the vector for convenience.
     std::vector<uint8_t>
-        render_data(static_cast<const uint8_t*>(out_buf.getData()),
-                    static_cast<const uint8_t*>(out_buf.getData()) + 514);
+        render_data(out_buf.getData(), out_buf.getData() + 514);
     // The first two bytes hold the length of 512.
     uint16_t len = (render_data[0] << 8) + render_data[1];
     EXPECT_EQ(512, len);
index 2bd8be39b31b83cb3be5c17dc1a503c23ba62f8b..bd2eaf83d5a9970b178855c5a28f11e40b841514 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2011-2017 Internet Systems Consortium, Inc. ("ISC")
+// Copyright (C) 2011-2024 Internet Systems Consortium, Inc. ("ISC")
 //
 // This Source Code Form is subject to the terms of the Mozilla Public
 // License, v. 2.0. If a copy of the MPL was not distributed with this
@@ -107,7 +107,7 @@ public:
     /// @param expected_type expected option type
     void checkOutputBuffer(uint16_t expected_type) {
         // Check if pack worked properly:
-        const uint8_t* out = static_cast<const uint8_t*>(out_buf_.getData());
+        const uint8_t* out = out_buf_.getData();
 
         // - if option type is correct
         EXPECT_EQ(expected_type, out[0]*256 + out[1]);
index 6b3eebca9efd9f874b72728a6b04300101454757..463fa47c7e88a2f509f63bd9e923e97cc482edf0 100644 (file)
@@ -76,7 +76,7 @@ TEST(Option6PDExcludeTest, pack) {
     ASSERT_EQ(expected_vec.size(), buf.getLength());
 
     // Check that the generated wire format is correct.
-    const uint8_t* data = static_cast<const uint8_t*>(buf.getData());
+    const uint8_t* data = buf.getData();
     std::vector<uint8_t> vec(data, data + buf.getLength());
     ASSERT_TRUE(std::equal(vec.begin(), vec.end(), expected_vec.begin()));
 }
index 01dcc1877bf0698f550fa582e7ed7418b313af3a..e19c8e92a59dc53006fcc727bf065e4480e00f01 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2015-2023 Internet Systems Consortium, Inc. ("ISC")
+// Copyright (C) 2015-2024 Internet Systems Consortium, Inc. ("ISC")
 //
 // This Source Code Form is subject to the terms of the Mozilla Public
 // License, v. 2.0. If a copy of the MPL was not distributed with this
@@ -270,9 +270,7 @@ TEST(OptionOpaqueDataTuples, pack4) {
         0x66, 0x6F, 0x6F                    // foo
     };
     // Compare the buffer with reference data.
-    EXPECT_EQ(0, memcmp(static_cast<const void*>(ref),
-                        static_cast<const void*>(buf.getData()),
-                        buf.getLength()));
+    EXPECT_EQ(0, memcmp(ref, buf.getData(), buf.getLength()));
 }
 
 // Check that the DHCPv4 option is rendered to the buffer in wire format,
@@ -304,9 +302,7 @@ TEST(OptionOpaqueDataTuples, pack4_with_ltf) {
         0x66, 0x6F, 0x6F                    // foo
     };
     // Compare the buffer with reference data.
-    EXPECT_EQ(0, memcmp(static_cast<const void*>(ref),
-                        static_cast<const void*>(buf.getData()),
-                        buf.getLength()));
+    EXPECT_EQ(0, memcmp(ref, buf.getData(), buf.getLength()));
 }
 
 // Check that the DHCPv6 option is rendered to the buffer in wire format.
@@ -336,9 +332,7 @@ TEST(OptionOpaqueDataTuples, pack6) {
         0x66, 0x6F, 0x6F                    // foo
     };
     // Compare the buffer with reference data.
-    EXPECT_EQ(0, memcmp(static_cast<const void*>(ref),
-                        static_cast<const void*>(buf.getData()),
-                        buf.getLength()));
+    EXPECT_EQ(0, memcmp(ref, buf.getData(), buf.getLength()));
 }
 
 // This function checks that the DHCPv4 option with two opaque data tuples
index b2c36d32decf64bbc8c4d28cf393442402789a45..1415d271ad3eba675642276978d8c81d33c54510 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2011-2023 Internet Systems Consortium, Inc. ("ISC")
+// Copyright (C) 2011-2024 Internet Systems Consortium, Inc. ("ISC")
 //
 // This Source Code Form is subject to the terms of the Mozilla Public
 // License, v. 2.0. If a copy of the MPL was not distributed with this
@@ -244,7 +244,7 @@ TEST_F(OptionTest, v6_data1) {
     opt->pack(outBuf_);
     EXPECT_EQ(11, outBuf_.getLength());
 
-    const uint8_t* out = static_cast<const uint8_t*>(outBuf_.getData());
+    const uint8_t* out = outBuf_.getData();
     EXPECT_EQ(out[0], 333 / 256); // Type
     EXPECT_EQ(out[1], 333 % 256);
 
@@ -280,7 +280,7 @@ TEST_F(OptionTest, v6_data2) {
 
     // Check if pack worked properly:
     // If option type is correct
-    const uint8_t* out = static_cast<const uint8_t*>(outBuf_.getData());
+    const uint8_t* out = outBuf_.getData();
 
     EXPECT_EQ(D6O_CLIENTID, out[0] * 256 + out[1]);
 
@@ -521,7 +521,7 @@ TEST_F(OptionTest, setData) {
     opt1->setData(buf_.begin(), buf_.end());
     opt1->pack(outBuf_);
     ASSERT_EQ(outBuf_.getLength() - opt1->getHeaderLen(), buf_.size());
-    const uint8_t* test_data = static_cast<const uint8_t*>(outBuf_.getData());
+    const uint8_t* test_data = outBuf_.getData();
     EXPECT_TRUE(0 == memcmp(&buf_[0], test_data + opt1->getHeaderLen(),
                             buf_.size()));
 
@@ -534,7 +534,7 @@ TEST_F(OptionTest, setData) {
     opt2->setData(buf_.begin(), buf_.end());
     opt2->pack(outBuf_);
     ASSERT_EQ(outBuf_.getLength() - opt1->getHeaderLen(), buf_.size());
-    test_data = static_cast<const uint8_t*>(outBuf_.getData());
+    test_data = outBuf_.getData();
     EXPECT_TRUE(0 == memcmp(&buf_[0], test_data + opt1->getHeaderLen(),
                             buf_.size()));
 }
index 40a36b82757908727beed53fff31f327a4cef34f..39826441ea3b320648ff236018cdff12847827ef 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2014-2023 Internet Systems Consortium, Inc. ("ISC")
+// Copyright (C) 2014-2024 Internet Systems Consortium, Inc. ("ISC")
 //
 // This Source Code Form is subject to the terms of the Mozilla Public
 // License, v. 2.0. If a copy of the MPL was not distributed with this
@@ -201,8 +201,7 @@ TEST(OptionVendorClass, pack4) {
         0x66, 0x6F, 0x6F                    // foo
     };
     // Compare the buffer with reference data.
-    EXPECT_EQ(0, memcmp(static_cast<const void*>(ref),
-                        static_cast<const void*>(buf.getData()), 26));
+    EXPECT_EQ(0, memcmp(ref, buf.getData(), 26));
 }
 
 // Check that the DHCPv6 option is rendered to the buffer in wire format.
@@ -233,9 +232,7 @@ TEST(OptionVendorClass, pack6) {
         0x66, 0x6F, 0x6F                    // foo
     };
     // Compare the buffer with reference data.
-    EXPECT_EQ(0, memcmp(static_cast<const void*>(ref),
-                        static_cast<const void*>(buf.getData()),
-                        buf.getLength()));
+    EXPECT_EQ(0, memcmp(ref, buf.getData(), buf.getLength()));
 }
 
 // This function checks that the DHCPv4 option with two opaque data tuples
index 47ca71162fdecf41d7bdb9c117357ee241cd3b66..a450ac363b2a236dac078ed855caf918967ad608 100644 (file)
@@ -317,7 +317,7 @@ TEST_F(Pkt4Test, fixedFieldsPack) {
 
     // Redundant but MUCH easier for debug in gdb
     const uint8_t* exp = &expectedFormat[0];
-    const uint8_t* got = static_cast<const uint8_t*>(pkt->getBuffer().getData());
+    const uint8_t* got = pkt->getBuffer().getData();
 
     EXPECT_EQ(0, memcmp(exp, got, Pkt4::DHCPV4_PKT_HDR_LEN));
 }
@@ -405,8 +405,7 @@ TEST_F(Pkt4Test, hwAddr) {
         );
 
         // CHADDR starts at offset 28 in DHCP packet
-        const uint8_t* ptr =
-            static_cast<const uint8_t*>(pkt->getBuffer().getData()) + 28;
+        const uint8_t* ptr = pkt->getBuffer().getData() + 28;
 
         EXPECT_EQ(0, memcmp(ptr, expectedChaddr, Pkt4::MAX_CHADDR_LEN));
 
@@ -481,8 +480,7 @@ TEST_F(Pkt4Test, sname) {
         );
 
         // SNAME starts at offset 44 in DHCP packet
-        const uint8_t* ptr =
-            static_cast<const uint8_t*>(pkt->getBuffer().getData()) + 44;
+        const uint8_t* ptr = pkt->getBuffer().getData() + 44;
         EXPECT_EQ(0, memcmp(ptr, sname, Pkt4::MAX_SNAME_LEN));
 
         pkt.reset();
@@ -526,8 +524,7 @@ TEST_F(Pkt4Test, file) {
         );
 
         // FILE starts at offset 108 in DHCP packet.
-        const uint8_t* ptr =
-            static_cast<const uint8_t*>(pkt->getBuffer().getData()) + 108;
+        const uint8_t* ptr = pkt->getBuffer().getData() + 108;
         EXPECT_EQ(0, memcmp(ptr, file, Pkt4::MAX_FILE_LEN));
 
         pkt.reset();
@@ -592,7 +589,7 @@ TEST_F(Pkt4Test, options) {
               buf.getLength());
 
     // That that this extra data actually contain our options
-    const uint8_t* ptr = static_cast<const uint8_t*>(buf.getData());
+    const uint8_t* ptr = buf.getData();
 
     // Rewind to end of fixed part.
     ptr += Pkt4::DHCPV4_PKT_HDR_LEN + sizeof(DHCP_OPTIONS_COOKIE);
@@ -1440,7 +1437,7 @@ TEST_F(Pkt4Test, nullTerminatedOptions) {
           DHO_ROOT_PATH, 4, 'n', 'o', 'n', 'e',
         };
 
-    const uint8_t* packed = static_cast<const uint8_t*>(pkt->getBuffer().getData());
+    const uint8_t* packed = pkt->getBuffer().getData();
     int packed_len = pkt->getBuffer().getLength();
 
     // Packed message options should be 3 bytes smaller than original onwire data.
index 9302b8b0d4d5dc1990806b1b52f06a360ea10d35..aa5d85c7da3253f66bcb359d06cf8b82e86f75e5 100644 (file)
@@ -119,7 +119,7 @@ PktFilter6Test::sendMessage() {
     // The iovec structure holds the packet data.
     struct iovec v;
     memset(&v, 0, sizeof(v));
-    v.iov_base = const_cast<void *>(test_message_->getBuffer().getData());
+    v.iov_base = const_cast<void *>(test_message_->getBuffer().getDataAsVP());
     v.iov_len = test_message_->getBuffer().getLength();
     // Assign the iovec to msghdr structure.
     m.msg_iov = &v;
index c6ca025db8cf21d646988c6b8722d54667c6068b..80cf4edd852705e09e7d12ed932f1faa34bfdf8d 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2013-2022 Internet Systems Consortium, Inc. ("ISC")
+// Copyright (C) 2013-2024 Internet Systems Consortium, Inc. ("ISC")
 //
 // This Source Code Form is subject to the terms of the Mozilla Public
 // License, v. 2.0. If a copy of the MPL was not distributed with this
@@ -310,8 +310,7 @@ NameChangeUDPSender::doSend(NameChangeRequestPtr& ncr) {
 
     // Copy the wire-ized request to callback.  This way we know after
     // send completes what we sent (or attempted to send).
-    send_callback_->putData(static_cast<const uint8_t*>(ncr_buffer.getData()),
-                            ncr_buffer.getLength());
+    send_callback_->putData(ncr_buffer.getData(), ncr_buffer.getLength());
 
     // Call the socket's asynchronous send, passing our callback
     socket_->asyncSend(send_callback_->getData(), send_callback_->getPutLen(),
index a10c0c54371222b9b5fec42f12c53c6fccea4802..a74eca94152bae81aa995b29747796039706d83d 100644 (file)
@@ -5066,7 +5066,7 @@ AllocEngine::updateLease6ExtendedInfo(const Lease6Ptr& lease,
             LibDHCP::packOptions6(buf, relay.options_);
 
             if (buf.getLength() > 0) {
-                const uint8_t* cp = static_cast<const uint8_t*>(buf.getData());
+                const uint8_t* cp = buf.getData();
                 std::vector<uint8_t> bytes;
                 std::stringstream ss;
 
index 9208b9b361a6009bea0729ebf7721f9ec1e45309..49c7709e1cdeb86535de8b011e4424c86d657fea 100644 (file)
@@ -1859,7 +1859,7 @@ public:
                 // option and store it in the database as a blob.
                 OutputBuffer buf(opt_desc.option_->len());
                 opt_desc.option_->pack(buf);
-                const char* buf_ptr = static_cast<const char*>(buf.getData());
+                const uint8_t* buf_ptr = buf.getData();
                 value_.assign(buf_ptr + opt_desc.option_->getHeaderLen(),
                               buf_ptr + buf.getLength());
                 value_len_ = value_.size();
index 7659b508d92e88a3b55590442ab76cf8dc3d132a..8db86ffa491415d038ed94d5c18a4f1fd8915154 100644 (file)
@@ -1240,7 +1240,7 @@ public:
                 // option and store it in the database as a BYTEA.
                 OutputBuffer buf(opt_desc.option_->len());
                 opt_desc.option_->pack(buf);
-                const char* buf_ptr = static_cast<const char*>(buf.getData());
+                const uint8_t* buf_ptr = buf.getData();
                 value_.assign(buf_ptr + opt_desc.option_->getHeaderLen(),
                               buf_ptr + buf.getLength());
                 value_len_ = value_.size();
index 4a327cde13bf5764d95df00693f02119325f3f7a..69aae2bd14a7689f632412ddbeed617cfe53b3d1 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2015-2023 Internet Systems Consortium, Inc. ("ISC")
+// Copyright (C) 2015-2024 Internet Systems Consortium, Inc. ("ISC")
 //
 // This Source Code Form is subject to the terms of the Mozilla Public
 // License, v. 2.0. If a copy of the MPL was not distributed with this
@@ -227,7 +227,7 @@ Dhcp4o6IpcBaseTest::createDHCPv4MsgOption(TestIpc::EndpointType src) {
     // Make a wire representation of the DHCPv4 message.
     pkt->pack();
     OutputBuffer& output_buffer = pkt->getBuffer();
-    const uint8_t* data = static_cast<const uint8_t*>(output_buffer.getData());
+    const uint8_t* data = output_buffer.getData();
     OptionBuffer option_buffer(data, data + output_buffer.getLength());
 
     // Create the DHCPv4 Message option holding the created message.
@@ -338,7 +338,7 @@ Dhcp4o6IpcBaseTest::testReceiveError(const Pkt6Ptr& pkt) {
     buf.clear();
     ASSERT_NO_THROW(pkt->pack());
 
-    ASSERT_NE(-1, ::send(ipc_src.getSocketFd(), buf.getData(),
+    ASSERT_NE(-1, ::send(ipc_src.getSocketFd(), buf.getDataAsVP(),
                          buf.getLength(), 0));
 
     // Call receive with a timeout. The data should appear on the socket
index 3fa0cc61a5e6fb77ad3e11a12c8a5d01cbd94481..ccc5c6e1539e6d9ce2b6946e8bd2068d370e39eb 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2012-2020 Internet Systems Consortium, Inc. ("ISC")
+// Copyright (C) 2012-2024 Internet Systems Consortium, Inc. ("ISC")
 //
 // This Source Code Form is subject to the terms of the Mozilla Public
 // License, v. 2.0. If a copy of the MPL was not distributed with this
@@ -816,10 +816,8 @@ TEST_F(LabelSequenceTest, serialize) {
     // Copy wire data of the name
     isc::util::OutputBuffer ob(0);
     n_maxlabel.toWire(ob);
-    expected_data7.insert(expected_data7.end(),
-                          static_cast<const uint8_t*>(ob.getData()),
-                          static_cast<const uint8_t*>(ob.getData()) +
-                          ob.getLength());
+    expected_data7.insert(expected_data7.end(), ob.getData(),
+                          ob.getData() + ob.getLength());
     expected.push_back(DataPair(expected_data7.size(), &expected_data7[0]));
 
     // For each data set, serialize the labels and compare the data to the
index aad629740f2911e35aec4cbe146063a9f51cc061..434448a618e840a996ca788d849fd2790ab7c974 100644 (file)
@@ -315,7 +315,7 @@ private:
 /// // pass the buffer to a DNS message object to construct a wire-format
 /// // DNS message.
 /// struct sockaddr to;
-/// sendto(s, buffer.getData(), buffer.getLength(), 0, &to, sizeof(to));
+/// sendto(s, buffer.getDataAsVP(), buffer.getLength(), 0, &to, sizeof(to));
 /// \endcode
 ///
 /// where the \c getData() method gives a reference to the internal memory
@@ -367,19 +367,11 @@ public:
     //@{
     /// \brief Constructor from the initial size of the buffer.
     ///
-    /// \param len The initial length of the buffer in bytes.
-    OutputBuffer(size_t len) :
-        buffer_(NULL),
-        size_(0),
-        allocated_(len)
+    /// \param len The initial allocated length of the buffer in bytes.
+    OutputBuffer(size_t len) : buffer_()
     {
-        // We use malloc and free instead of C++ new[] and delete[].
-        // This way we can use realloc, which may in fact do it without a copy.
-        if (allocated_ != 0) {
-            buffer_ = static_cast<uint8_t*>(malloc(allocated_));
-            if (buffer_ == NULL) {
-                throw std::bad_alloc();
-            }
+        if (len != 0) {
+            buffer_.reserve(len);
         }
     }
 
@@ -391,22 +383,17 @@ public:
     /// size_ <= allocated_, and that if allocated_ is greater than zero,
     /// buffer_ points to valid memory.
     OutputBuffer(const OutputBuffer& other) :
-        buffer_(NULL),
-        size_(other.size_),
-        allocated_(other.allocated_)
+        buffer_(other.buffer_)
     {
-        if (allocated_ != 0) {
-            buffer_ = static_cast<uint8_t*>(malloc(allocated_));
-            if (buffer_ == NULL) {
-                throw std::bad_alloc();
-            }
-            static_cast<void>(std::memmove(buffer_, other.buffer_, other.size_));
+        size_t len = other.buffer_.capacity();
+        if (len != 0) {
+            buffer_.reserve(len);
         }
     }
 
     /// \brief Destructor
     ~OutputBuffer() {
-        free(buffer_);
+        buffer_.clear();
     }
     //@}
 
@@ -420,35 +407,11 @@ public:
     OutputBuffer& operator =(const OutputBuffer& other) {
         if (this != &other) {
             // Not self-assignment.
-            if (other.allocated_ != 0) {
-
-                // There is something in the source object, so allocate memory
-                // and copy it.  The pointer to the allocated memory is placed
-                // in a temporary variable so that if the allocation fails and
-                // an exception is thrown, the destination object ("this") is
-                // unchanged.
-                uint8_t* newbuff = static_cast<uint8_t*>(malloc(other.allocated_));
-                if (newbuff == NULL) {
-                    throw std::bad_alloc();
-                }
-
-                // Memory allocated, update the source object and copy data
-                // across.
-                free(buffer_);
-                buffer_ = newbuff;
-                static_cast<void>(std::memmove(buffer_, other.buffer_, other.size_));
-
-            } else {
-
-                // Nothing allocated in the source object, so zero the buffer
-                // in the destination.
-                free(buffer_);
-                buffer_ = NULL;
+            buffer_ = other.buffer_;
+            size_t len = other.buffer_.capacity();
+            if (len != 0) {
+                buffer_.reserve(len);
             }
-
-            // Update the other member variables.
-            size_ = other.size_;
-            allocated_ = other.allocated_;
         }
         return (*this);
     }
@@ -458,7 +421,10 @@ public:
     ///
     //@{
     /// \brief Return the current capacity of the buffer.
-    size_t getCapacity() const { return (allocated_); }
+    size_t getCapacity() const {
+        return (buffer_.capacity());
+    }
+
     /// \brief Return a pointer to the head of the data stored in the buffer.
     ///
     /// The caller can assume that the subsequent \c getLength() bytes are
@@ -466,9 +432,24 @@ public:
     ///
     /// Note: The pointer returned by this method may be invalidated after a
     /// subsequent write operation.
-    const void* getData() const { return (buffer_); }
+    const uint8_t* getData() const {
+        if (!buffer_.empty()) {
+            return (&buffer_[0]);
+        } else {
+            return (0);
+        }
+    }
+
+    /// \brief Return data as a pointer to void.
+    const void* getDataAsVP() const {
+        return (static_cast<const void*>(getData()));
+    }
+
     /// \brief Return the length of data written in the buffer.
-    size_t getLength() const { return (size_); }
+    size_t getLength() const {
+        return (buffer_.size());
+    }
+
     /// \brief Return the value of the buffer at the specified position.
     ///
     /// \c pos must specify the valid position of the buffer; otherwise an
@@ -476,12 +457,17 @@ public:
     ///
     /// \param pos The position in the buffer to be returned.
     uint8_t operator[](size_t pos) const {
-        if (pos >= size_) {
+        if (pos >= buffer_.size()) {
             isc_throw(InvalidBufferPosition,
-                      "[]: pos (" << pos << ") >= size (" << size_ << ")");
+                      "[]: pos (" << pos << ") >= size (" << buffer_.size() << ")");
         }
         return (buffer_[pos]);
     }
+
+    /// \brief Return the buffer.
+    const std::vector<uint8_t>& getVector() const {
+        return (buffer_);
+    }
     //@}
 
     ///
@@ -495,8 +481,7 @@ public:
     /// that is to be filled in later, e.g, by \ref writeUint16At().
     /// \param len The length of the gap to be inserted in bytes.
     void skip(size_t len) {
-        ensureAllocated(size_ + len);
-        size_ += len;
+        buffer_.resize(buffer_.size() + len);
     }
 
     /// \brief Trim the specified length of data from the end of the buffer.
@@ -507,33 +492,22 @@ public:
     ///
     /// \param len The length of data that should be trimmed.
     void trim(size_t len) {
-        if (len > size_) {
+        if (len > buffer_.size()) {
             isc_throw(OutOfRange, "trimming too large from output buffer");
         }
-        size_ -= len;
+        buffer_.resize(buffer_.size() - len);
     }
-    /// \brief Clear buffer content.
-    ///
-    /// This method can be used to re-initialize and reuse the buffer without
-    /// constructing a new one. Note it must keep current content.
-    void clear() { size_ = 0; }
 
-    /// \brief Wipe buffer content.
-    ///
-    /// This method is the destructive alternative to clear().
-    void wipe() {
-        if (buffer_ != NULL) {
-            static_cast<void>(std::memset(buffer_, 0, allocated_));
-        }
-        size_ = 0;
+    /// \brief Clear buffer content.
+    void clear() {
+        buffer_.clear();
     }
 
     /// \brief Write an unsigned 8-bit integer into the buffer.
     ///
     /// \param data The 8-bit integer to be written into the buffer.
     void writeUint8(uint8_t data) {
-        ensureAllocated(size_ + 1);
-        buffer_[size_ ++] = data;
+        buffer_.push_back(data);
     }
 
     /// \brief Write an unsigned 8-bit integer into the buffer.
@@ -545,7 +519,7 @@ public:
     /// \param data The 8-bit integer to be written into the buffer.
     /// \param pos The position in the buffer to write the data.
     void writeUint8At(uint8_t data, size_t pos) {
-        if (pos + sizeof(data) > size_) {
+        if (pos + sizeof(data) > buffer_.size()) {
             isc_throw(InvalidBufferPosition, "write at invalid position");
         }
         buffer_[pos] = data;
@@ -556,9 +530,8 @@ public:
     ///
     /// \param data The 16-bit integer to be written into the buffer.
     void writeUint16(uint16_t data) {
-        ensureAllocated(size_ + sizeof(data));
-        buffer_[size_ ++] = static_cast<uint8_t>((data & 0xff00U) >> 8);
-        buffer_[size_ ++] = static_cast<uint8_t>(data & 0x00ffU);
+        buffer_.push_back(static_cast<uint8_t>((data & 0xff00U) >> 8));
+        buffer_.push_back(static_cast<uint8_t>(data & 0x00ffU));
     }
 
     /// \brief Write an unsigned 16-bit integer in host byte order at the
@@ -573,7 +546,7 @@ public:
     /// \param data The 16-bit integer to be written into the buffer.
     /// \param pos The beginning position in the buffer to write the data.
     void writeUint16At(uint16_t data, size_t pos) {
-        if (pos + sizeof(data) > size_) {
+        if (pos + sizeof(data) > buffer_.size()) {
             isc_throw(InvalidBufferPosition, "write at invalid position");
         }
 
@@ -586,11 +559,10 @@ public:
     ///
     /// \param data The 32-bit integer to be written into the buffer.
     void writeUint32(uint32_t data) {
-        ensureAllocated(size_ + sizeof(data));
-        buffer_[size_ ++] = static_cast<uint8_t>((data & 0xff000000) >> 24);
-        buffer_[size_ ++] = static_cast<uint8_t>((data & 0x00ff0000) >> 16);
-        buffer_[size_ ++] = static_cast<uint8_t>((data & 0x0000ff00) >> 8);
-        buffer_[size_ ++] = static_cast<uint8_t>(data & 0x000000ff);
+        buffer_.push_back(static_cast<uint8_t>((data & 0xff000000) >> 24));
+        buffer_.push_back(static_cast<uint8_t>((data & 0x00ff0000) >> 16));
+        buffer_.push_back(static_cast<uint8_t>((data & 0x0000ff00) >> 8));
+        buffer_.push_back(static_cast<uint8_t>(data & 0x000000ff));
     }
 
     /// \brief Write an unsigned 64-bit integer in host byte order
@@ -598,15 +570,14 @@ public:
     ///
     /// \param data The 64-bit integer to be written into the buffer.
     void writeUint64(uint64_t data) {
-        ensureAllocated(size_ + sizeof(data));
-        buffer_[size_ ++] = static_cast<uint8_t>((data & 0xff00000000000000) >> 56);
-        buffer_[size_ ++] = static_cast<uint8_t>((data & 0x00ff000000000000) >> 48);
-        buffer_[size_ ++] = static_cast<uint8_t>((data & 0x0000ff0000000000) >> 40);
-        buffer_[size_ ++] = static_cast<uint8_t>((data & 0x000000ff00000000) >> 32);
-        buffer_[size_ ++] = static_cast<uint8_t>((data & 0x00000000ff000000) >> 24);
-        buffer_[size_ ++] = static_cast<uint8_t>((data & 0x0000000000ff0000) >> 16);
-        buffer_[size_ ++] = static_cast<uint8_t>((data & 0x000000000000ff00) >> 8);
-        buffer_[size_ ++] = static_cast<uint8_t>(data &  0x00000000000000ff);
+        buffer_.push_back(static_cast<uint8_t>((data & 0xff00000000000000) >> 56));
+        buffer_.push_back(static_cast<uint8_t>((data & 0x00ff000000000000) >> 48));
+        buffer_.push_back(static_cast<uint8_t>((data & 0x0000ff0000000000) >> 40));
+        buffer_.push_back(static_cast<uint8_t>((data & 0x000000ff00000000) >> 32));
+        buffer_.push_back(static_cast<uint8_t>((data & 0x00000000ff000000) >> 24));
+        buffer_.push_back(static_cast<uint8_t>((data & 0x0000000000ff0000) >> 16));
+        buffer_.push_back(static_cast<uint8_t>((data & 0x000000000000ff00) >> 8));
+        buffer_.push_back(static_cast<uint8_t>(data &  0x00000000000000ff));
     }
 
     /// \brief Copy an arbitrary length of data into the buffer.
@@ -620,45 +591,14 @@ public:
             return;
         }
 
-        ensureAllocated(size_ + len);
-        static_cast<void>(std::memmove(buffer_ + size_, data, len));
-        size_ += len;
+        const uint8_t* ptr = static_cast<const uint8_t*>(data);
+        buffer_.insert(buffer_.end(), ptr, ptr + len);
     }
     //@}
 
 private:
     /// The actual data
-    uint8_t* buffer_;
-    /// How many bytes are used
-    size_t size_;
-    /// How many bytes do we have preallocated (eg. the capacity)
-    size_t allocated_;
-
-    /// \brief Ensure buffer is appropriate size
-    ///
-    /// 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
-    void ensureAllocated(size_t needed_size) {
-        if (allocated_ < needed_size) {
-            // Guess some bigger size
-            size_t new_size = (allocated_ == 0) ? 1024 : allocated_;
-            while (new_size < needed_size) {
-                new_size *= 2;
-            }
-            // Allocate bigger space.  Note that buffer_ may be NULL,
-            // in which case realloc acts as malloc.
-            uint8_t* new_buffer_(static_cast<uint8_t*>(realloc(buffer_,
-                new_size)));
-            if (new_buffer_ == NULL) {
-                // If it fails, the original block is left intact by it
-                throw std::bad_alloc();
-            }
-            buffer_ = new_buffer_;
-            allocated_ = new_size;
-        }
-    }
+    std::vector<uint8_t> buffer_;
 };
 
 /// \brief Pointer-like types pointing to \c InputBuffer or \c OutputBuffer
index 88f2b1e36d98592e7eb8c6510651921119ed2ae6..59e2983996d2de18bd1108d2586f1f9add8304a2 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2011-2021 Internet Systems Consortium, Inc. ("ISC")
+// Copyright (C) 2011-2024 Internet Systems Consortium, Inc. ("ISC")
 //
 // This Source Code Form is subject to the terms of the Mozilla Public
 // License, v. 2.0. If a copy of the MPL was not distributed with this
@@ -241,7 +241,7 @@ SocketSessionForwarder::push(int sock, int family, int type, int protocol,
     impl_->buf_.writeUint16At(impl_->buf_.getLength() - sizeof(uint16_t), 0);
 
     const struct iovec iov[2] = {
-        { const_cast<void*>(impl_->buf_.getData()), impl_->buf_.getLength() },
+        { const_cast<void*>(impl_->buf_.getDataAsVP()), impl_->buf_.getLength() },
         { const_cast<void*>(data), data_len }
     };
     const int cc = writev(impl_->fd_, iov, 2);
index 0f4556970119e42ef6c31889029ca99388d596b4..46706b179b758b82ddd6b3340ca06e8cb45d3505 100644 (file)
@@ -125,19 +125,19 @@ TEST_F(BufferTest, outputBufferWrite) {
     obuffer.writeUint8(1);
     expected_size += sizeof(uint8_t);
     EXPECT_EQ(expected_size, obuffer.getLength());
-    cp = static_cast<const uint8_t*>(obuffer.getData());
+    cp = obuffer.getData();
     EXPECT_EQ(1, *cp);
 
     obuffer.writeUint16(data16);
     expected_size += sizeof(data16);
-    cp = static_cast<const uint8_t*>(obuffer.getData());
+    cp = obuffer.getData();
     EXPECT_EQ(expected_size, obuffer.getLength());
     EXPECT_EQ(2, *(cp + 1));
     EXPECT_EQ(3, *(cp + 2));
 
     obuffer.writeUint32(data32);
     expected_size += sizeof(data32);
-    cp = static_cast<const uint8_t*>(obuffer.getData());
+    cp = obuffer.getData();
     EXPECT_EQ(expected_size, obuffer.getLength());
     EXPECT_EQ(4, *(cp + 3));
     EXPECT_EQ(5, *(cp + 4));
@@ -147,31 +147,31 @@ TEST_F(BufferTest, outputBufferWrite) {
     obuffer.writeData(testdata, sizeof(testdata));
     expected_size += sizeof(testdata);
     EXPECT_EQ(expected_size, obuffer.getLength());
-    cp = static_cast<const uint8_t*>(obuffer.getData());
+    cp = obuffer.getData();
     EXPECT_EQ(0, memcmp(cp + 7, testdata, sizeof(testdata)));
 }
 
-TEST_F(BufferTest, outputBufferWriteat) {
+TEST_F(BufferTest, outputBufferWriteAt) {
     obuffer.writeUint32(data32);
     expected_size += sizeof(data32);
 
     // overwrite 2nd byte
     obuffer.writeUint8At(4, 1);
     EXPECT_EQ(expected_size, obuffer.getLength()); // length shouldn't change
-    const uint8_t* cp = static_cast<const uint8_t*>(obuffer.getData());
+    const uint8_t* cp = obuffer.getData();
     EXPECT_EQ(4, *(cp + 1));
 
     // overwrite 2nd and 3rd bytes
     obuffer.writeUint16At(data16, 1);
     EXPECT_EQ(expected_size, obuffer.getLength()); // length shouldn't change
-    cp = static_cast<const uint8_t*>(obuffer.getData());
+    cp = obuffer.getData();
     EXPECT_EQ(2, *(cp + 1));
     EXPECT_EQ(3, *(cp + 2));
 
     // overwrite 3rd and 4th bytes
     obuffer.writeUint16At(data16, 2);
     EXPECT_EQ(expected_size, obuffer.getLength());
-    cp = static_cast<const uint8_t*>(obuffer.getData());
+    cp = obuffer.getData();
     EXPECT_EQ(2, *(cp + 2));
     EXPECT_EQ(3, *(cp + 3));
 
@@ -210,35 +210,18 @@ TEST_F(BufferTest, outputBufferTrim) {
 
 TEST_F(BufferTest, outputBufferReadAt) {
     obuffer.writeData(testdata, sizeof(testdata));
-    for (int i = 0; i < sizeof(testdata); i ++) {
+    for (size_t i = 0; i < sizeof(testdata); ++i) {
         EXPECT_EQ(testdata[i], obuffer[i]);
     }
     EXPECT_THROW(obuffer[sizeof(testdata)], isc::util::InvalidBufferPosition);
 }
 
 TEST_F(BufferTest, outputBufferClear) {
-    const uint8_t* cp;
-
     obuffer.writeData(testdata, sizeof(testdata));
-    cp = static_cast<const uint8_t*>(obuffer.getData());
+    const uint8_t* cp = obuffer.getData();
     obuffer.clear();
     EXPECT_EQ(0, obuffer.getLength());
-    EXPECT_EQ(*cp, 1);
-}
-
-TEST_F(BufferTest, outputBufferWipe) {
-    const uint8_t* cp;
-
-    obuffer.writeData(testdata, sizeof(testdata));
-    cp = static_cast<const uint8_t*>(obuffer.getData());
-    obuffer.wipe();
-    EXPECT_EQ(0, obuffer.getLength());
-    EXPECT_EQ(*cp, 0);
-}
-
-TEST_F(BufferTest, emptyOutputBufferWipe) {
-    ASSERT_NO_THROW(obuffer.wipe());
-    EXPECT_EQ(0, obuffer.getLength());
+    EXPECT_FALSE(obuffer.getData());
 }
 
 TEST_F(BufferTest, outputBufferCopy) {
@@ -264,6 +247,7 @@ TEST_F(BufferTest, outputEmptyBufferCopy) {
     EXPECT_NO_THROW({
         OutputBuffer copy(obuffer);
         ASSERT_EQ(0, copy.getLength());
+        EXPECT_FALSE(copy.getData());
     });
 }
 
@@ -294,7 +278,7 @@ TEST_F(BufferTest, outputEmptyBufferAssign) {
         copy = obuffer;
     });
     ASSERT_EQ(0, copy.getLength());
-    EXPECT_EQ(NULL, copy.getData());
+    EXPECT_EQ(0, copy.getData());
 }
 
 // Check assign to self doesn't break stuff
@@ -312,22 +296,6 @@ TEST_F(BufferTest, outputBufferZeroSize) {
     });
 }
 
-TEST_F(BufferTest, inputBufferReadVectorAll) {
-    std::vector<uint8_t> vec;
-
-    // check that vector can read the whole buffer
-    ibuffer.readVector(vec, 5);
-
-    ASSERT_EQ(5, vec.size());
-    EXPECT_EQ(0, memcmp(&vec[0], testdata, 5));
-
-    // ibuffer is 5 bytes long. Can't read past it.
-    EXPECT_THROW(
-        ibuffer.readVector(vec, 1),
-        isc::util::InvalidBufferPosition
-    );
-}
-
 TEST_F(BufferTest, inputBufferReadVectorChunks) {
     std::vector<uint8_t> vec;
 
@@ -341,7 +309,8 @@ TEST_F(BufferTest, inputBufferReadVectorChunks) {
         ibuffer.readVector(vec, 2)
     );
 
-    EXPECT_EQ(0, memcmp(&vec[0], testdata+3, 2));
+    ASSERT_EQ(2, vec.size());
+    EXPECT_EQ(0, memcmp(&vec[0], &testdata[3], 2));
 }
 
 // Tests whether uint64 can be written properly.
@@ -357,7 +326,7 @@ TEST_F(BufferTest, writeUint64) {
 
     obuffer.writeUint64(val1);
     ASSERT_EQ(sizeof(uint64_t), obuffer.getLength());
-    cp = static_cast<const uint8_t*>(obuffer.getData());
+    cp = obuffer.getData();
     EXPECT_TRUE(cp);
     EXPECT_FALSE(memcmp(exp_val1, obuffer.getData(), sizeof(uint64_t)));
 
@@ -365,7 +334,7 @@ TEST_F(BufferTest, writeUint64) {
 
     obuffer.writeUint64(val2);
     ASSERT_EQ(sizeof(uint64_t), obuffer.getLength());
-    cp = static_cast<const uint8_t*>(obuffer.getData());
+    cp = obuffer.getData();
     EXPECT_TRUE(cp);
     EXPECT_FALSE(memcmp(exp_val2, obuffer.getData(), sizeof(uint64_t)));
 }
index acaaf13f02c42615a7765eeb797315ee0f77eb4d..003f14fd9fdad9ba2bf573df903c56f3c28b33cf 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2011-2022 Internet Systems Consortium, Inc. ("ISC")
+// Copyright (C) 2011-2024 Internet Systems Consortium, Inc. ("ISC")
 //
 // This Source Code Form is subject to the terms of the Mozilla Public
 // License, v. 2.0. If a copy of the MPL was not distributed with this
@@ -65,7 +65,7 @@ TEST(asioutil, writeUint16) {
         writeUint16(i16, test, sizeof(test));
 
         // ... and compare
-        const uint8_t* ref = static_cast<const uint8_t*>(buffer.getData());
+        const uint8_t* ref = buffer.getData();
         EXPECT_EQ(ref[0], test[0]);
         EXPECT_EQ(ref[1], test[1]);
     }