/src/botan/src/lib/utils/assert.cpp
Line | Count | Source (jump to first uncovered line) |
1 | | /* |
2 | | * Runtime assertion checking |
3 | | * (C) 2010,2012,2018 Jack Lloyd |
4 | | * |
5 | | * Botan is released under the Simplified BSD License (see license.txt) |
6 | | */ |
7 | | |
8 | | #include <botan/exceptn.h> |
9 | | #include <botan/build.h> |
10 | | #include <sstream> |
11 | | |
12 | | #if defined(BOTAN_TERMINATE_ON_ASSERTS) |
13 | | #include <cstdlib> |
14 | | #include <iostream> |
15 | | #endif |
16 | | |
17 | | namespace Botan { |
18 | | |
19 | | void throw_invalid_argument(const char* message, |
20 | | const char* func, |
21 | | const char* file) |
22 | 2.61k | { |
23 | 2.61k | std::ostringstream format; |
24 | 2.61k | format << message << " in " << func << ":" << file; |
25 | 2.61k | throw Invalid_Argument(format.str()); |
26 | 2.61k | } |
27 | | |
28 | | void throw_invalid_state(const char* expr, |
29 | | const char* func, |
30 | | const char* file) |
31 | 17 | { |
32 | 17 | std::ostringstream format; |
33 | 17 | format << "Invalid state: " << expr << " was false in " << func << ":" << file; |
34 | 17 | throw Invalid_State(format.str()); |
35 | 17 | } |
36 | | |
37 | | void assertion_failure(const char* expr_str, |
38 | | const char* assertion_made, |
39 | | const char* func, |
40 | | const char* file, |
41 | | int line) |
42 | 54 | { |
43 | 54 | std::ostringstream format; |
44 | | |
45 | 54 | format << "False assertion "; |
46 | | |
47 | 54 | if(assertion_made && assertion_made[0] != 0) |
48 | 54 | format << "'" << assertion_made << "' (expression " << expr_str << ") "; |
49 | 0 | else |
50 | 0 | format << expr_str << " "; |
51 | | |
52 | 54 | if(func) |
53 | 54 | format << "in " << func << " "; |
54 | | |
55 | 54 | format << "@" << file << ":" << line; |
56 | | |
57 | | #if defined(BOTAN_TERMINATE_ON_ASSERTS) |
58 | | std::cerr << format.str() << '\n'; |
59 | | std::abort(); |
60 | | #else |
61 | 54 | throw Internal_Error(format.str()); |
62 | 54 | #endif |
63 | 54 | } |
64 | | |
65 | | } |