]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
Make conversion to uint16_t explicit, as suggested by Otto 8993/head
authorRemi Gacogne <remi.gacogne@powerdns.com>
Wed, 8 Apr 2020 08:25:10 +0000 (10:25 +0200)
committerRemi Gacogne <remi.gacogne@powerdns.com>
Tue, 1 Sep 2020 08:50:06 +0000 (10:50 +0200)
pdns/ednsoptions.cc
pdns/packetcache.hh

index b10e150aa0c7e313e9f8cb10f80906832ef99e98..ecfba3f867d5485b521c692d936c08f2c50b5786 100644 (file)
@@ -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<const uint8_t*>(data);
 
-  optionCode = (static_cast<unsigned char>(data[pos]) * 256) + static_cast<unsigned char>(data[pos + 1]);
+  optionCode = (static_cast<uint16_t>(p[pos]) * 256) + p[pos + 1];
   pos += EDNS_OPTION_CODE_SIZE;
 
-  optionLen = (static_cast<unsigned char>(data[pos]) * 256) + static_cast<unsigned char>(data[pos + 1]);
+  optionLen = (static_cast<uint16_t>(p[pos]) * 256) + p[pos + 1];
   pos += EDNS_OPTION_LENGTH_SIZE;
 
   return true;
index bbb670df579a120793c1390c705ee7c9ef2fb6b5..a8cf718888eb9953c72cfc41e12d90d995de547c 100644 (file)
@@ -59,7 +59,7 @@ public:
     /* already hashed above */
     pos += 13;
 
-    const uint16_t rdLen = ((static_cast<unsigned char>(packet.at(pos)) * 256) + static_cast<unsigned char>(packet.at(pos + 1)));
+    const uint16_t rdLen = ((static_cast<uint16_t>(packet.at(pos)) * 256) + static_cast<uint16_t>(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<const unsigned char*>(&packet.at(2)), sizeof(dnsheader) - 2, currentHash); // rest of dnsheader, skip id
     pos = sizeof(dnsheader);