From 3e35ea9ebea7a3fb46845372ad59259e5b8b8df0 Mon Sep 17 00:00:00 2001 From: Remi Gacogne Date: Wed, 8 Apr 2020 10:25:10 +0200 Subject: [PATCH] Make conversion to uint16_t explicit, as suggested by Otto --- pdns/ednsoptions.cc | 5 +++-- pdns/packetcache.hh | 4 ++-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/pdns/ednsoptions.cc b/pdns/ednsoptions.cc index b10e150aa0..ecfba3f867 100644 --- a/pdns/ednsoptions.cc +++ b/pdns/ednsoptions.cc @@ -30,11 +30,12 @@ bool getNextEDNSOption(const char* data, size_t dataLen, uint16_t& optionCode, u } size_t pos = 0; + const uint8_t* p = reinterpret_cast(data); - optionCode = (static_cast(data[pos]) * 256) + static_cast(data[pos + 1]); + optionCode = (static_cast(p[pos]) * 256) + p[pos + 1]; pos += EDNS_OPTION_CODE_SIZE; - optionLen = (static_cast(data[pos]) * 256) + static_cast(data[pos + 1]); + optionLen = (static_cast(p[pos]) * 256) + p[pos + 1]; pos += EDNS_OPTION_LENGTH_SIZE; return true; diff --git a/pdns/packetcache.hh b/pdns/packetcache.hh index bbb670df57..a8cf718888 100644 --- a/pdns/packetcache.hh +++ b/pdns/packetcache.hh @@ -59,7 +59,7 @@ public: /* already hashed above */ pos += 13; - const uint16_t rdLen = ((static_cast(packet.at(pos)) * 256) + static_cast(packet.at(pos + 1))); + const uint16_t rdLen = ((static_cast(packet.at(pos)) * 256) + static_cast(packet.at(pos + 1))); /* skip the rd length */ /* already hashed above */ pos += 2; @@ -116,7 +116,7 @@ public: static uint32_t hashHeaderAndQName(const std::string& packet, size_t& pos) { uint32_t currentHash = 0; - size_t packetSize = packet.size(); + const size_t packetSize = packet.size(); assert(packetSize >= sizeof(dnsheader)); currentHash = burtle(reinterpret_cast(&packet.at(2)), sizeof(dnsheader) - 2, currentHash); // rest of dnsheader, skip id pos = sizeof(dnsheader); -- 2.47.2