From 0a0ca17c3d6a77fc36f96189ccff9be12af66e63 Mon Sep 17 00:00:00 2001 From: Jakob Kaivo Date: Tue, 4 Jun 2024 13:41:06 -0400 Subject: track LC_CTYPE epoch in character conversion functions to detect a change --- src/stdlib/_stdlib.h | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'src/stdlib/_stdlib.h') diff --git a/src/stdlib/_stdlib.h b/src/stdlib/_stdlib.h index 7edb9d98..d5f89b09 100644 --- a/src/stdlib/_stdlib.h +++ b/src/stdlib/_stdlib.h @@ -3,8 +3,22 @@ #include #include +#include "locale/_locale.h" #include "_safety.h" +#ifndef NDEBUG +#define ASSERT_CTYPE(__s_ptr) do { \ + static unsigned int __ctype_epoch = 0; \ + if ((__s_ptr) == 0) { \ + __ctype_epoch = __get_ctype_epoch(); \ + } else if (__ctype_epoch != __get_ctype_epoch()) { \ + UNDEFINED("LC_CTYPE has changed since previous call which did not reset internal state"); \ + } \ +} while (0) +#else +#define ASSERT_CTYPE(__s_ptr) (void)(__s_ptr) +#endif + #ifdef NEED_COMPAR #ifdef NDEBUG #define SAFE_COMPAR(__comp, __p1, __p2, __sz, __fn) __comp(__p1, __p2) -- cgit v1.2.1