asar coverage - build #174


src/asar/
File: src/asar/errors.cpp
Date: 2024-01-28 00:31:05
Lines:
25/28
89.3%
Functions:
6/6
100.0%
Branches:
15/24
62.5%

Line Branch Exec Source
1 #include "asar.h"
2 #include <cassert>
3 #include <cstdarg>
4
5 #include "interface-shared.h"
6
7 template<typename t>
8 2690 void asar_error_template(asar_error_id errid, int whichpass, const char* message)
9 {
10 try
11 {
12
1/2
✓ Branch 0 taken 1345 times.
✗ Branch 1 not taken.
2690 error_interface((int)errid, whichpass, message);
13 t err;
14 2690 throw err;
15 }
16
2/2
✓ Branch 0 taken 622 times.
✓ Branch 1 taken 108 times.
1460 catch (errnull&) {}
17 216 }
18
19 #if !defined(__clang__)
20 void(*shutupgcc1)(asar_error_id, int, const char*) = asar_error_template<errnull>;
21 void(*shutupgcc2)(asar_error_id, int, const char*) = asar_error_template<errblock>;
22 void(*shutupgcc3)(asar_error_id, int, const char*) = asar_error_template<errline>;
23 void(*shutupgcc4)(asar_error_id, int, const char*) = asar_error_template<errfatal>;
24 #endif
25 1345 void asar_throw_error_impl(int whichpass, asar_error_type type, asar_error_id errid, const char* fmt, ...)
26 {
27
2/4
✓ Branch 0 taken 676 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 676 times.
✗ Branch 3 not taken.
676 assert(errid >= 0 && errid < error_id_end);
28
29 char error_buffer[1024];
30 va_list args;
31 1345 va_start(args, fmt);
32
33 #if defined(__clang__)
34 # pragma clang diagnostic push
35 // "format string is not a literal".
36 // The pointer we're passing here should always point to a string literal,
37 // thus, I think, we can safely ignore this here.
38 # pragma clang diagnostic ignored "-Wformat-nonliteral"
39 #endif
40
41 1345 vsnprintf(error_buffer, sizeof(error_buffer), fmt, args);
42
43 #if defined(__clang__)
44 # pragma clang diagnostic pop
45 #endif
46
47 1345 va_end(args);
48
49
4/4
✓ Branch 0 taken 108 times.
✓ Branch 1 taken 1105 times.
✓ Branch 2 taken 108 times.
✓ Branch 3 taken 24 times.
1345 switch (type)
50 {
51 108 case error_type_null:
52
1/2
✓ Branch 0 taken 54 times.
✗ Branch 1 not taken.
108 asar_error_template<errnull>(errid, whichpass, error_buffer);
53 54 break;
54 1105 case error_type_block:
55
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 556 times.
1105 asar_error_template<errblock>(errid, whichpass, error_buffer);
56 break;
57 108 case error_type_line:
58
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 54 times.
108 asar_error_template<errline>(errid, whichpass, error_buffer);
59 break;
60 24 case error_type_fatal:
61 default:
62
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
24 asar_error_template<errfatal>(errid, whichpass, error_buffer);
63 break;
64 }
65 108 }
66
67 954 const char* get_error_name(asar_error_id errid)
68 {
69
2/4
✓ Branch 0 taken 479 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 479 times.
✗ Branch 3 not taken.
479 assert(errid >= 0 && errid < error_id_end);
70
71 479 const asar_error_mapping& error = asar_all_errors[errid];
72
73 954 return error.name;
74 }
75