The setlocale(3) function reloads the ctype(3) arrays from
external files. This happens behind the scenes in the internals
of libc (citrus library, runes functions etc).
ctype(3) functions like isspace(3) can be provided with two
variations on NetBSD: inlined or via a global symbol in libc:
#if defined(_NETBSD_SOURCE) && !defined(_CTYPE_NOINLINE) && \ !defined(__cplusplus) #include <sys/ctype_inline.h> #else #include <sys/ctype_bits.h> #endif
The in-lined versions are de-facto array lookup operations.
#define isspace(c) ((int)((_ctype_tab_ + 1)[(c)] & _CTYPE_S))
After setting setlocale(3) the ctype(3) arrays (_ctype_tab_,
_toupper_tab_, _tolower_tab_) are reload behind the scenes
and they are required to be marked as initialized.
Set them initialized inside the common setlocale(3) interceptor.
The arrays are of size of 257 elements: 0..255 + 1 (EOF).
This corrects errors on NetBSD/amd64 in applications
prebuilt with MSan.
Sponsored by <The NetBSD Foundation>
How about new file:
compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors_netbsd.inc
and moving all netbsd pieces there?
It's OK to do as a followup patch.