Skip to content

Commit 486c64c

Browse files
committed
rtld, libthr: Use nonstring attribute to silence compiler warning
With Clang 21 at least, we start to get warnings like: ``` rtld.c:333:58: error: initializer-string for character array is too long, array size is 4 but initializer has size 5 (including the null terminating character); did you mean to use the 'nonstring' attribute? [-Werror,-Wunterminated-string-initialization] 333 | static const char rtld_utrace_sig[RTLD_UTRACE_SIG_SZ] = RTLD_UTRACE_SIG; | ^~~~~~~~~~~~~~~ ./rtld_utrace.h:49:27: note: expanded from macro 'RTLD_UTRACE_SIG' 49 | #define RTLD_UTRACE_SIG "RTLD" | ``` Looking up the `nonstring` attribute [1], it does seem to be the correct thing --- indicating a char array which should not have a null terminator byte --- to use in these two cases. Note: I discovered this when fixing Nixpkgs's FreeBSD cross compilation support. I understand that FreeBSD may not officially support this version of Clang yet, but I am hoping the attribute still works with the version of Clang it does support (even if it not yet needed on that version to fix `-Werror` errors). I am hoping thus that this patch is accessible, as just early readiness for when FreeBSD does upgrade to that version of Clang. [1]: https://clang.llvm.org/docs/AttributeReference.html#nonstring
1 parent b502a45 commit 486c64c

File tree

2 files changed

+2
-2
lines changed

2 files changed

+2
-2
lines changed

lib/libthr/thread/thr_printf.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ _thread_printf(int fd, const char *fmt, ...)
6161
void
6262
_thread_vprintf(int fd, const char *fmt, va_list ap)
6363
{
64-
static const char digits[16] = "0123456789abcdef";
64+
__attribute__((__nonstring__)) static const char digits[16] = "0123456789abcdef";
6565
char buf[20];
6666
char *s;
6767
unsigned long r, u;

libexec/rtld-elf/rtld.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -348,7 +348,7 @@ ld_utrace_log(int event, void *handle, void *mapbase, size_t mapsize,
348348
int refcnt, const char *name)
349349
{
350350
struct utrace_rtld ut;
351-
static const char rtld_utrace_sig[RTLD_UTRACE_SIG_SZ] = RTLD_UTRACE_SIG;
351+
__attribute__((__nonstring__)) static const char rtld_utrace_sig[RTLD_UTRACE_SIG_SZ] = RTLD_UTRACE_SIG;
352352

353353
memset(&ut, 0, sizeof(ut)); /* clear holes */
354354
memcpy(ut.sig, rtld_utrace_sig, sizeof(ut.sig));

0 commit comments

Comments
 (0)