diff options
author | Gabe Black <gabeblack@google.com> | 2018-11-16 17:57:41 -0800 |
---|---|---|
committer | Gabe Black <gabeblack@google.com> | 2018-11-19 21:24:14 +0000 |
commit | 9afba24af299493adc86ed471b2464f33a1539e2 (patch) | |
tree | c63b31288e5cdfcf4cce6450db00605d39c36045 /src | |
parent | bd91e3bf1d56d2b9d1a49a7263a5713210ba7c52 (diff) | |
download | gem5-9afba24af299493adc86ed471b2464f33a1539e2.tar.xz |
base: Don't let exceptions leak from the to_number utility function.
This function catches a couple types of exceptions the functions it
calls might throw, but if one that it doesn't catch is thrown, then
it will propogate that exception to its own callers, and not initialize
the value it was asked to convert.
This might be considered desirable behavior since it lets errors
propogate and avoids handling them in code that might not know the
context of when it's called. On the other hand, it upsets g++ since it
thinks that there might be an uninitialized value used elsewhere, even
though that value will only be uninitialized if an exception is
propogating, and the code that would use it is after a point where that
exception would have been caught and execution would have resumed.
To satisfy g++ and to also avoid silently hiding errors, this change
adds a catch all which will panic if an unexpected exception is raised.
Change-Id: Ie94dcef3a50f7902566328a3fa2eac59b3cf9aad
Reviewed-on: https://gem5-review.googlesource.com/c/14399
Reviewed-by: Jason Lowe-Power <jason@lowepower.com>
Maintainer: Jason Lowe-Power <jason@lowepower.com>
Diffstat (limited to 'src')
-rw-r--r-- | src/base/str.hh | 4 |
1 files changed, 4 insertions, 0 deletions
diff --git a/src/base/str.hh b/src/base/str.hh index d73058bc0..52ab977fc 100644 --- a/src/base/str.hh +++ b/src/base/str.hh @@ -39,6 +39,8 @@ #include <string> #include <vector> +#include "base/logging.hh" + inline void eat_lead_white(std::string &s) { @@ -157,6 +159,8 @@ to_number(const std::string &value, T &retval) return false; } catch (const std::invalid_argument&) { return false; + } catch (...) { + panic("Unrecognized exception.\n"); } } |