From: Gabe Black Date: Sat, 17 Nov 2018 01:57:41 +0000 (-0800) Subject: base: Don't let exceptions leak from the to_number utility function. X-Git-Tag: v19.0.0.0~1380 X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=9afba24af299493adc86ed471b2464f33a1539e2;p=gem5.git 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 Maintainer: Jason Lowe-Power --- 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 #include +#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"); } }