From 4f9f2fd5c170552f2b4e811a4d231f3ca882d0e9 Mon Sep 17 00:00:00 2001 From: Otto Moerbeek Date: Fri, 31 Mar 2023 13:36:04 +0200 Subject: [PATCH] Cleanup rcodes enums: base one is 8 bit unisgned, extended one 16 bit unsigned --- pdns/dns.cc | 8 +++++--- pdns/dns.hh | 6 +++--- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/pdns/dns.cc b/pdns/dns.cc index d9fb5096f8..99bbd72aa6 100644 --- a/pdns/dns.cc +++ b/pdns/dns.cc @@ -71,8 +71,9 @@ static const std::array rcodes_short_s = { }; std::string RCode::to_s(uint8_t rcode) { - if (rcode > 0xF) + if (rcode > 0xF) { return std::string("ErrOutOfRange"); + } return ERCode::to_s(rcode); } @@ -83,9 +84,10 @@ std::string RCode::to_short_s(uint8_t rcode) { return rcodes_short_s.at(rcode); } -std::string ERCode::to_s(uint8_t rcode) { - if (rcode > RCode::rcodes_s.size()-1) +std::string ERCode::to_s(uint16_t rcode) { + if (rcode >= RCode::rcodes_s.size()) { return std::string("Err#")+std::to_string(rcode); + } return RCode::rcodes_s.at(rcode); } diff --git a/pdns/dns.hh b/pdns/dns.hh index ef44cf813d..7ceda1eeec 100644 --- a/pdns/dns.hh +++ b/pdns/dns.hh @@ -32,7 +32,7 @@ struct DNSRecord; class RCode { public: - enum rcodes_ { NoError=0, FormErr=1, ServFail=2, NXDomain=3, NotImp=4, Refused=5, YXDomain=6, YXRRSet=7, NXRRSet=8, NotAuth=9, NotZone=10}; + enum rcodes_ : uint8_t { NoError=0, FormErr=1, ServFail=2, NXDomain=3, NotImp=4, Refused=5, YXDomain=6, YXRRSet=7, NXRRSet=8, NotAuth=9, NotZone=10}; static std::string to_s(uint8_t rcode); static std::string to_short_s(uint8_t rcode); const static std::array rcodes_s; @@ -41,8 +41,8 @@ public: class ERCode { public: - enum rcodes_ { BADVERS=16, BADSIG=16, BADKEY=17, BADTIME=18, BADMODE=19, BADNAME=20, BADALG=21, BADTRUNC=22, BADCOOKIE=23 }; - static std::string to_s(uint8_t rcode); + enum rcodes_ : uint16_t { BADVERS=16, BADSIG=16, BADKEY=17, BADTIME=18, BADMODE=19, BADNAME=20, BADALG=21, BADTRUNC=22, BADCOOKIE=23 }; + static std::string to_s(uint16_t rcode); }; class Opcode -- 2.47.2