Skip to content

Commit

Permalink
report unparseable data in stoul invalid_argument exception
Browse files Browse the repository at this point in the history
  • Loading branch information
Habbie committed Mar 26, 2018
1 parent 6883b1d commit 9a0319b
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion pdns/misc.cc
Expand Up @@ -1360,7 +1360,13 @@ gid_t strToGID(const string &str)
unsigned int pdns_stou(const std::string& str, size_t * idx, int base)
{
if (str.empty()) return 0; // compatibility
unsigned long result = std::stoul(str, idx, base);
unsigned long result;
try {
result = std::stoul(str, idx, base);
}
catch(std::invalid_argument& e) {
throw std::invalid_argument(string(e.what()) + "; data was \""+str+"\"");
}
if (result > std::numeric_limits<unsigned int>::max()) {
throw std::out_of_range("stou");
}
Expand Down

0 comments on commit 9a0319b

Please sign in to comment.