Coverage Report

Created: 2022-09-23 06:05

/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
0
   {
32
0
   std::ostringstream format;
33
0
   format << "Invalid state: " << expr << " was false in " << func << ":" << file;
34
0
   throw Invalid_State(format.str());
35
0
   }
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
60
   {
43
60
   std::ostringstream format;
44
45
60
   format << "False assertion ";
46
47
60
   if(assertion_made && assertion_made[0] != 0)
48
60
      format << "'" << assertion_made << "' (expression " << expr_str << ") ";
49
0
   else
50
0
      format << expr_str << " ";
51
52
60
   if(func)
53
60
      format << "in " << func << " ";
54
55
60
   format << "@" << file << ":" << line;
56
57
#if defined(BOTAN_TERMINATE_ON_ASSERTS)
58
   std::cerr << format.str() << '\n';
59
   std::abort();
60
#else
61
60
   throw Internal_Error(format.str());
62
60
#endif
63
60
   }
64
65
}