summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJakob Kaivo <jkk@ung.org>2023-11-14 12:56:01 -0500
committerJakob Kaivo <jkk@ung.org>2023-11-14 12:56:01 -0500
commit79551f5c04d20990e64b26bf577f70eeaeb38652 (patch)
treecf9211c4ddf105221ca33a193cbbe3eb6851eea1
parent9e22ec98f4132300301d32f033b2c4d6e4ff5c1d (diff)
enable UB-testing for isupper()
-rw-r--r--src/_assert.h7
-rw-r--r--src/ctype/isupper.c7
-rw-r--r--src/errno/ERANGE.h6
-rw-r--r--src/locale/__get_locale.c5
-rw-r--r--src/locale/__load_locale.c5
-rw-r--r--src/stdlib/__constraint_info.h3
-rw-r--r--src/stdlib/__stdlib.c9
-rw-r--r--src/stdlib/_stdlib.h6
-rw-r--r--src/stdlib/abort_handler_s.c17
9 files changed, 33 insertions, 32 deletions
diff --git a/src/_assert.h b/src/_assert.h
index 0da010ab..4c71f2f6 100644
--- a/src/_assert.h
+++ b/src/_assert.h
@@ -1,9 +1,8 @@
#ifndef ___ASSERT_H__
#define ___ASSERT_H__
-#ifndef NDEBUG
-#define NDEBUG
-#endif
+#include "stdlib/_stdlib.h"
+#include "errno/ERANGE.h"
#ifndef NDEBUG
#define ASSERT_NONNULL(__ptr) do { \
@@ -34,7 +33,7 @@
_ci.func = __func__; \
__stdlib.constraint_handler("Undefined behavior: " \
"Paramater " #_n " must be representable as a " #_type \
- "or be equal to " #_sentinel, &_ci, ERANGE); \
+ " or be equal to " #_sentinel, &_ci, ERANGE); \
} else if (_n < _min || _n > _max) { \
struct __constraint_info _ci = {0}; \
_ci.func = __func__; \
diff --git a/src/ctype/isupper.c b/src/ctype/isupper.c
index a9506910..ccc7ff23 100644
--- a/src/ctype/isupper.c
+++ b/src/ctype/isupper.c
@@ -1,7 +1,5 @@
-#if 0
-
#include <limits.h>
-#include "_assert.h"
+#include <stdio.h>
#include "_ctype.h"
/** test whether a character is an uppercase letter **/
@@ -28,6 +26,3 @@ C_LOCALE(`THIS() is true for the characters CHAR(A), CHAR(B), CHAR(C), CHAR(D),
OTHER_LOCALES(`THIS() is true for a set of characters for which none of FUNCTION(iscntrl), FUNCTION(isdigit), FUNCTION(ispunct), or FUNCTION(isspace) is true')
STDC(1)
*/
-
-
-#endif
diff --git a/src/errno/ERANGE.h b/src/errno/ERANGE.h
index c6fb0bdf..f05d4b12 100644
--- a/src/errno/ERANGE.h
+++ b/src/errno/ERANGE.h
@@ -9,3 +9,9 @@ is used to indicated that the result of an operation is too large or too small.
/*
STDC(1)
*/
+
+
+#ifdef __linux__
+#undef ERANGE
+#define ERANGE 34
+#endif
diff --git a/src/locale/__get_locale.c b/src/locale/__get_locale.c
index 162db164..b795d0f0 100644
--- a/src/locale/__get_locale.c
+++ b/src/locale/__get_locale.c
@@ -1,5 +1,3 @@
-#if 0
-
#include "_locale.h"
/*
@@ -23,6 +21,3 @@ struct __locale_t * __get_locale(void)
}
return &l;
}
-
-
-#endif
diff --git a/src/locale/__load_locale.c b/src/locale/__load_locale.c
index 4b6c8ca4..66177eb6 100644
--- a/src/locale/__load_locale.c
+++ b/src/locale/__load_locale.c
@@ -1,5 +1,3 @@
-#if 0
-
#include <locale.h>
#include <limits.h>
#include <stdio.h>
@@ -233,6 +231,3 @@ char * __load_locale(struct __locale_t *loc, int mask, const char *name)
/*
STDC(0)
*/
-
-
-#endif
diff --git a/src/stdlib/__constraint_info.h b/src/stdlib/__constraint_info.h
new file mode 100644
index 00000000..f8ffb539
--- /dev/null
+++ b/src/stdlib/__constraint_info.h
@@ -0,0 +1,3 @@
+struct __constraint_info {
+ const char *func;
+};
diff --git a/src/stdlib/__stdlib.c b/src/stdlib/__stdlib.c
index aa67fa10..b6423713 100644
--- a/src/stdlib/__stdlib.c
+++ b/src/stdlib/__stdlib.c
@@ -1,12 +1,9 @@
-#if 0
-
#include "_stdlib.h"
-struct __stdlib __stdlib;
+struct __stdlib __stdlib = {
+ .constraint_handler = abort_handler_s,
+};
/*
STDC(0)
*/
-
-
-#endif
diff --git a/src/stdlib/_stdlib.h b/src/stdlib/_stdlib.h
index 929981a6..4d456594 100644
--- a/src/stdlib/_stdlib.h
+++ b/src/stdlib/_stdlib.h
@@ -7,6 +7,11 @@
#define _rand(_n) \
(((_n) = (_n) * 1103515245 + 12345) ? (_n) / UINT_MAX % RAND_MAX : 0)
+#include "errno/errno_t.h"
+#include "constraint_handler_t.h"
+#include "__constraint_info.h"
+void abort_handler_s(const char * restrict msg, void * restrict ptr, errno_t error);
+
struct __stdlib {
struct atexit {
int nfns;
@@ -16,6 +21,7 @@ struct __stdlib {
} atexit;
unsigned int rand;
char **environ;
+ constraint_handler_t constraint_handler;
};
extern struct __stdlib __stdlib;
diff --git a/src/stdlib/abort_handler_s.c b/src/stdlib/abort_handler_s.c
index 31d06568..7639ddfe 100644
--- a/src/stdlib/abort_handler_s.c
+++ b/src/stdlib/abort_handler_s.c
@@ -1,15 +1,20 @@
-#if 0
-
#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+//#include <errno.h>
+#include "errno/errno_t.h"
+#include "_stdlib.h"
void abort_handler_s(const char * restrict msg, void * restrict ptr, errno_t error)
{
- __C_EXT(1, 201112L);
+ struct __constraint_info *ci = ptr;
+
+ puts(msg);
+ printf("In call to %s\n", ci->func);
+ printf("Provided error: %s (%d)\n", strerror(error), error);
+ abort();
}
/*
CEXT1(201112)
*/
-
-
-#endif