summaryrefslogtreecommitdiff
path: root/src/ctype
diff options
context:
space:
mode:
authorJakob Kaivo <jkk@ung.org>2024-01-31 15:54:38 -0500
committerJakob Kaivo <jkk@ung.org>2024-01-31 15:54:38 -0500
commit57fd57ab4005e37bfab4bf7c637eecc1eb5445b5 (patch)
treea5cc5b9ad040955a0a7247091cbc542f297229bb /src/ctype
parent1dcdfdc0141e94b57b80526ca917b1228fe53f53 (diff)
clean up UB detection
Diffstat (limited to 'src/ctype')
-rw-r--r--src/ctype/_ctype.h10
-rw-r--r--src/ctype/isalnum.c2
-rw-r--r--src/ctype/isalpha.c2
-rw-r--r--src/ctype/isascii.c1
-rw-r--r--src/ctype/isdigit.c2
-rw-r--r--src/ctype/toascii.c1
6 files changed, 15 insertions, 3 deletions
diff --git a/src/ctype/_ctype.h b/src/ctype/_ctype.h
index 2b5fd907..d0771acc 100644
--- a/src/ctype/_ctype.h
+++ b/src/ctype/_ctype.h
@@ -4,6 +4,16 @@
#include "locale/_locale.h"
#include "_safety.h"
+#ifdef NDEBUG
+#define ASSERT_REPRESENTABLE(_n, _min, _max, _type, _sentinel) (void)
+#else
+#define ASSERT_REPRESENTABLE(_n, _min, _max, _type, _sentinel) do { \
+ if (!(((_n) == (_sentinel)) || (((_min) <= (_n)) && ((_n) <= (_max))))) { \
+ __undefined("In call to %s(), parameter %s (value 0x%ju) is not representable as a %s (range [%s, %s]) or exactly %s", __func__, #_n, (uintmax_t)(_n), #_type, #_min, #_max, #_sentinel); \
+ } \
+} while (0)
+#endif
+
typedef enum {
CT_ALPHA = (1 << 0),
CT_CNTRL = (1 << 1),
diff --git a/src/ctype/isalnum.c b/src/ctype/isalnum.c
index b8ffc414..81a1a0fa 100644
--- a/src/ctype/isalnum.c
+++ b/src/ctype/isalnum.c
@@ -1,7 +1,7 @@
#include <ctype.h>
#include <limits.h>
#include <stdio.h>
-#include "_safety.h"
+#include "_ctype.h"
/** test whether a character is alphanumeric **/
diff --git a/src/ctype/isalpha.c b/src/ctype/isalpha.c
index 98fa0853..658e5af9 100644
--- a/src/ctype/isalpha.c
+++ b/src/ctype/isalpha.c
@@ -1,7 +1,7 @@
#include <ctype.h>
#include <limits.h>
#include <stdio.h>
-#include "_safety.h"
+#include "_ctype.h"
/** test whether a character is alphabetic **/
diff --git a/src/ctype/isascii.c b/src/ctype/isascii.c
index 8807bea2..cf7bba28 100644
--- a/src/ctype/isascii.c
+++ b/src/ctype/isascii.c
@@ -1,4 +1,5 @@
#include <ctype.h>
+#include "_ctype.h"
/** test whether a character is in the ASCII range **/
diff --git a/src/ctype/isdigit.c b/src/ctype/isdigit.c
index bf13158b..b1e7871f 100644
--- a/src/ctype/isdigit.c
+++ b/src/ctype/isdigit.c
@@ -1,7 +1,7 @@
#include <ctype.h>
#include <limits.h>
#include <stdio.h>
-#include "_safety.h"
+#include "_ctype.h"
/** test whether a character is a digit **/
diff --git a/src/ctype/toascii.c b/src/ctype/toascii.c
index c3728ae1..c352a121 100644
--- a/src/ctype/toascii.c
+++ b/src/ctype/toascii.c
@@ -1,4 +1,5 @@
#include <ctype.h>
+#include "_ctype.h"
/** convert a character to 7-bit ASCII **/