Skip to content

Commit

Permalink
(maint) Fix boost::nowide::getenv on OS X
Browse files Browse the repository at this point in the history
Environment tests segfault on OS X due to an uncaught
exception. Return early from get_int if the variable we're trying to
get does not exist.
  • Loading branch information
GabrielNagy committed Aug 23, 2019
1 parent 5f89df6 commit 6fd37f0
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion util/src/environment.cc
Expand Up @@ -8,11 +8,14 @@ namespace leatherman { namespace util {
int environment::get_int(string const& name, int default_value)
{
auto variable = boost::nowide::getenv(name.c_str());
if (!variable) {
return default_value;
}

try {
return stoi(variable);
}
catch (...) {
catch (invalid_argument&) {
return default_value;
}
}
Expand Down

0 comments on commit 6fd37f0

Please sign in to comment.