@@ -45,17 +45,20 @@ POSSIBILITY OF SUCH DAMAGE.
45
45
46
46
#ifdef PCRE2_DEBUG
47
47
48
+ #if defined(HAVE_ASSERT_H ) && !defined(NDEBUG )
49
+ #include <assert.h>
50
+ #endif
51
+
48
52
/* PCRE2_ASSERT(x) can be used to inject an assert() for conditions
49
53
that the code below doesn't support. It is a NOP for non debug builds
50
54
but in debug builds will print information about the location of the
51
55
code where it triggered and crash.
52
56
53
- it is meant to work like assert(), and therefore the expressiom used
57
+ It is meant to work like assert(), and therefore the expression used
54
58
should indicate what the expected state is, and shouldn't have any
55
- sideeffects . */
59
+ side-effects . */
56
60
57
61
#if defined(HAVE_ASSERT_H ) && !defined(NDEBUG )
58
- #include <assert.h>
59
62
#define PCRE2_ASSERT (x ) assert(x)
60
63
#else
61
64
#define PCRE2_ASSERT (x ) do \
@@ -73,21 +76,26 @@ shouldn't be reached. In non debug builds is defined as a hint for
73
76
the compiler to eliminate any code after it, so it is useful also for
74
77
performance reasons, but should be used with care because if it is
75
78
ever reached will trigger Undefined Behaviour and if you are lucky a
76
- crash. In debug builds will report the location where it was trigered
79
+ crash. In debug builds it will report the location where it was triggered
77
80
and crash. One important point to consider when using this macro, is
78
81
that it is only implemented for a few compilers, and therefore can't
79
82
be relied on to always be active either, so if it is followed by some
80
- code it is imoprtant to make sure that the whole thing is safe to
83
+ code it is important to make sure that the whole thing is safe to
81
84
use even if the macro is not there (ex: make sure there is a `break`
82
85
after it if used at the end of a `case`) and to test your code also
83
86
with a configuration where the macro will be a NOP. */
84
87
88
+ #if defined(HAVE_ASSERT_H ) && !defined(NDEBUG )
89
+ #define PCRE2_UNREACHABLE () \
90
+ assert(((void)"Execution reached unexpected point", 0))
91
+ #else
85
92
#define PCRE2_UNREACHABLE () do \
86
93
{ \
87
94
fprintf(stderr, "Execution reached unexpected point at " __FILE__ \
88
95
":%d\n", __LINE__); \
89
96
abort(); \
90
97
} while(0)
98
+ #endif
91
99
92
100
/* PCRE2_DEBUG_UNREACHABLE() is a debug only version of the previous
93
101
macro. It is meant to be used in places where the code is handling
0 commit comments