Skip to content

Commit

Permalink
Merge pull request #6396 from Habbie/stoul-data
Browse files Browse the repository at this point in the history
report unparseable data in stoul invalid_argument exception
  • Loading branch information
pieterlexis committed Mar 27, 2018
2 parents fa4a352 + cccfa59 commit 0df9d29
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions pdns/misc.cc
Expand Up @@ -1360,9 +1360,18 @@ 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()) + "; (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+"\"");
}
if (result > std::numeric_limits<unsigned int>::max()) {
throw std::out_of_range("stou");
throw std::out_of_range("stoul returned result out of unsigned int range; data was \""+str+"\"");
}
return static_cast<unsigned int>(result);
}
Expand Down

0 comments on commit 0df9d29

Please sign in to comment.