From 79551f5c04d20990e64b26bf577f70eeaeb38652 Mon Sep 17 00:00:00 2001 From: Jakob Kaivo Date: Tue, 14 Nov 2023 12:56:01 -0500 Subject: enable UB-testing for isupper() --- src/stdlib/__constraint_info.h | 3 +++ src/stdlib/__stdlib.c | 9 +++------ src/stdlib/_stdlib.h | 6 ++++++ src/stdlib/abort_handler_s.c | 17 +++++++++++------ 4 files changed, 23 insertions(+), 12 deletions(-) create mode 100644 src/stdlib/__constraint_info.h (limited to 'src/stdlib') 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 +#include +#include +//#include +#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 -- cgit v1.2.1