From: Fred Morcos Date: Fri, 4 Mar 2022 11:18:43 +0000 (+0100) Subject: Formatting X-Git-Tag: rec-4.7.0-beta1~56^2~4 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=95b87a03545e00ff18e7a0426e810c477935f6f3;p=thirdparty%2Fpdns.git Formatting --- diff --git a/pdns/dnsparser.hh b/pdns/dnsparser.hh index 12ec50622a..b8b612dc62 100644 --- a/pdns/dnsparser.hh +++ b/pdns/dnsparser.hh @@ -257,10 +257,11 @@ public: n2typemap_t::const_iterator iter = getN2Typemap().find(toUpper(name)); if(iter != getN2Typemap().end()) return iter->second.second; - - if (isUnknownType(name)) - return (uint16_t) pdns_stou(name.substr(4)); - + + if (isUnknownType(name)) { + return (uint16_t)pdns_stou(name.substr(4)); + } + throw runtime_error("Unknown DNS type '"+name+"'"); } diff --git a/pdns/misc.cc b/pdns/misc.cc index 9b0e397a99..bb62fb40df 100644 --- a/pdns/misc.cc +++ b/pdns/misc.cc @@ -281,26 +281,30 @@ bool stripDomainSuffix(string *qname, const string &domain) return true; } -static void parseService4(const string &descr, ServiceTuple &st) +static void parseService4(const string& descr, ServiceTuple& st) { - vectorparts; - stringtok(parts,descr,":"); - if(parts.empty()) - throw PDNSException("Unable to parse '"+descr+"' as a service"); - st.host=parts[0]; - if(parts.size()>1) - st.port=pdns_stou(parts[1]); + vector parts; + stringtok(parts, descr, ":"); + if (parts.empty()) { + throw PDNSException("Unable to parse '" + descr + "' as a service"); + } + st.host = parts[0]; + if (parts.size() > 1) { + st.port = pdns_stou(parts[1]); + } } -static void parseService6(const string &descr, ServiceTuple &st) +static void parseService6(const string& descr, ServiceTuple& st) { - string::size_type pos=descr.find(']'); - if(pos == string::npos) - throw PDNSException("Unable to parse '"+descr+"' as an IPv6 service"); + string::size_type pos = descr.find(']'); + if (pos == string::npos) { + throw PDNSException("Unable to parse '" + descr + "' as an IPv6 service"); + } - st.host=descr.substr(1, pos-1); - if(pos + 2 < descr.length()) - st.port=pdns_stou(descr.substr(pos+2)); + st.host = descr.substr(1, pos - 1); + if (pos + 2 < descr.length()) { + st.port = pdns_stou(descr.substr(pos + 2)); + } } void parseService(const string &descr, ServiceTuple &st) @@ -1509,21 +1513,24 @@ gid_t strToGID(const string &str) return result; } -unsigned int pdns_stou(const std::string& str, size_t * idx, int base) +unsigned int pdns_stou(const std::string& str, size_t* idx, int base) { - if (str.empty()) return 0; // compatibility + if (str.empty()) { + return 0; // compatibility + } + unsigned long result; try { result = std::stoul(str, idx, base); } - catch(std::invalid_argument& e) { - throw std::invalid_argument(string(e.what()) + "; (invalid argument during std::stoul); data was \""+str+"\""); + catch (std::invalid_argument& e) { + throw std::invalid_argument(string(e.what()) + "; (invalid argument during std::stoul); data was \"" + str + "\""); } - catch(std::out_of_range& e) { - throw std::out_of_range(string(e.what()) + "; (out of range during std::stoul); data was \""+str+"\""); + catch (std::out_of_range& e) { + throw std::out_of_range(string(e.what()) + "; (out of range during std::stoul); data was \"" + str + "\""); } if (result > std::numeric_limits::max()) { - throw std::out_of_range("stoul returned result out of unsigned int range; data was \""+str+"\""); + throw std::out_of_range("stoul returned result out of unsigned int range; data was \"" + str + "\""); } return static_cast(result); } diff --git a/pdns/misc.hh b/pdns/misc.hh index 6d43465748..595f119b43 100644 --- a/pdns/misc.hh +++ b/pdns/misc.hh @@ -617,7 +617,7 @@ double DiffTime(const struct timeval& first, const struct timeval& second); uid_t strToUID(const string &str); gid_t strToGID(const string &str); -unsigned int pdns_stou(const std::string& str, size_t * idx = 0, int base = 10); +unsigned int pdns_stou(const std::string& str, size_t* idx = 0, int base = 10); bool isSettingThreadCPUAffinitySupported(); int mapThreadToCPUList(pthread_t tid, const std::set& cpus);