diff options
author | Jack Lloyd <[email protected]> | 2018-08-17 17:32:42 -0400 |
---|---|---|
committer | Jack Lloyd <[email protected]> | 2018-08-17 17:32:42 -0400 |
commit | a86d2dea373053a045e6dd97a40b92b8607be0de (patch) | |
tree | bee05a572e0d9949b93245a542edb9974579e9e2 /src/lib | |
parent | 18af8859a5c007c6df47181be0fabf2913204979 (diff) |
Add BOTAN_STATE_CHECK macro
Diffstat (limited to 'src/lib')
-rw-r--r-- | src/lib/utils/assert.cpp | 11 | ||||
-rw-r--r-- | src/lib/utils/assert.h | 12 |
2 files changed, 21 insertions, 2 deletions
diff --git a/src/lib/utils/assert.cpp b/src/lib/utils/assert.cpp index cd957e00d..31a35374a 100644 --- a/src/lib/utils/assert.cpp +++ b/src/lib/utils/assert.cpp @@ -15,12 +15,19 @@ void throw_invalid_argument(const char* message, const char* file) { std::ostringstream format; - format << message << " in " << func << ":" << file; - throw Invalid_Argument(format.str()); } +void throw_invalid_state(const char* expr, + const char* func, + const char* file) + { + std::ostringstream format; + format << "Invalid state: " << expr << " was false in " << func << ":" << file; + throw Invalid_State(format.str()); + } + void assertion_failure(const char* expr_str, const char* assertion_made, const char* func, diff --git a/src/lib/utils/assert.h b/src/lib/utils/assert.h index a12872f2b..20e15ac0e 100644 --- a/src/lib/utils/assert.h +++ b/src/lib/utils/assert.h @@ -38,6 +38,18 @@ BOTAN_NORETURN void BOTAN_UNSTABLE_API throw_invalid_argument(const char* messag do { if(!(expr)) Botan::throw_invalid_argument(msg, BOTAN_CURRENT_FUNCTION, __FILE__); } while(0) /** +* Called when an invalid state is encountered +* Throws Invalid_State +*/ +BOTAN_NORETURN void BOTAN_UNSTABLE_API throw_invalid_state(const char* message, + const char* func, + const char* file); + + +#define BOTAN_STATE_CHECK(expr) \ + do { if(!(expr)) Botan::throw_invalid_state(#expr, BOTAN_CURRENT_FUNCTION, __FILE__); } while(0) + +/** * Make an assertion */ #define BOTAN_ASSERT(expr, assertion_made) \ |