summaryrefslogtreecommitdiffstats
path: root/src/bfstd.c
diff options
context:
space:
mode:
authorTavian Barnes <tavianator@tavianator.com>2023-11-23 15:25:34 -0500
committerTavian Barnes <tavianator@tavianator.com>2023-11-23 15:25:34 -0500
commitbaa6fc8cd33da879e5f7ac22557fd2ef3e4d8072 (patch)
tree980f0eeb0663d5960da30f5a53fef971add0240b /src/bfstd.c
parent394cf624ee9ab64090135d99ec4dcec0e0a69882 (diff)
downloadbfs-baa6fc8cd33da879e5f7ac22557fd2ef3e4d8072.tar.xz
bfstd: Work around more instances of llvm/llvm-project#65532
Diffstat (limited to 'src/bfstd.c')
-rw-r--r--src/bfstd.c33
1 files changed, 19 insertions, 14 deletions
diff --git a/src/bfstd.c b/src/bfstd.c
index 16cd82e..b5006d1 100644
--- a/src/bfstd.c
+++ b/src/bfstd.c
@@ -284,8 +284,12 @@ const char *xstrerror(int errnum) {
const char *ret = NULL;
static thread_local char buf[256];
-#if __APPLE__ || __COSMOPOLITAN__
- // No strerror_l() on macOS
+ // - __APPLE__
+ // - __COSMOPOLITAN__
+ // - No strerror_l()
+ // - __FreeBSD__ && SANITIZE_MEMORY
+ // - duplocale() triggers https://github.com/llvm/llvm-project/issues/65532
+#if __APPLE__ || __COSMOPOLITAN__ || (__FreeBSD__ && SANITIZE_MEMORY)
if (strerror_r(errnum, buf, sizeof(buf)) == 0) {
ret = buf;
}
@@ -643,6 +647,16 @@ wint_t xmbrtowc(const char *str, size_t *i, size_t len, mbstate_t *mb) {
}
}
+/**
+ * Work around https://github.com/llvm/llvm-project/issues/65532 by forcing a
+ * function, not a macro, to be called.
+ */
+#if __FreeBSD__ && SANITIZE_MEMORY
+# define BFS_INTERCEPT(fn) (fn)
+#else
+# define BFS_INTERCEPT(fn) fn
+#endif
+
size_t xstrwidth(const char *str) {
size_t len = strlen(str);
size_t ret = 0;
@@ -654,7 +668,7 @@ size_t xstrwidth(const char *str) {
// Assume a single-width '?'
++ret;
} else {
- ret += wcwidth(wc);
+ ret += BFS_INTERCEPT(wcwidth)(wc);
}
}
@@ -674,20 +688,11 @@ static unsigned char ctype_cache[UCHAR_MAX + 1];
/** Initialize the ctype cache. */
static void char_cache_init(void) {
-#if __FreeBSD__ && SANITIZE_MEMORY
-// Work around https://github.com/llvm/llvm-project/issues/65532
-# define bfs_isprint (isprint)
-# define bfs_isspace (isspace)
-#else
-# define bfs_isprint isprint
-# define bfs_isspace isspace
-#endif
-
for (size_t c = 0; c <= UCHAR_MAX; ++c) {
- if (bfs_isprint(c)) {
+ if (BFS_INTERCEPT(isprint)(c)) {
ctype_cache[c] |= IS_PRINT;
}
- if (bfs_isspace(c)) {
+ if (BFS_INTERCEPT(isspace)(c)) {
ctype_cache[c] |= IS_SPACE;
}
}