From 048a94c8f606706fbb42882f7b559cd982eb3914 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= Date: Tue, 8 Jul 2025 12:44:06 +0200 Subject: [PATCH] basic/stdio-util: use a fixed message in xsprintf We put the name of the variable in the message, but it is a local variable and the name does not have global meaning. We end up with pointless copies of the error string: $ strings build/libsystemd.so.0.40.0 | grep 'big enough' xsprintf: p[] must be big enough xsprintf: error[] must be big enough xsprintf: prefix[] must be big enough xsprintf: pty[] must be big enough xsprintf: mode[] must be big enough xsprintf: t[] must be big enough xsprintf: s[] must be big enough xsprintf: spid[] must be big enough xsprintf: header_priority[] must be big enough xsprintf: header_pid[] must be big enough xsprintf: path[] must be big enough xsprintf: buf[] must be big enough The error message already shows the file, line, and function name, which is enough to identify the problem: Assertion 'xsprintf: buffer too small' failed at src/test/test-string-util.c:20, function test_xsprintf(). Aborting. --- src/basic/stdio-util.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/basic/stdio-util.h b/src/basic/stdio-util.h index 54640314346..052087ce15d 100644 --- a/src/basic/stdio-util.h +++ b/src/basic/stdio-util.h @@ -19,7 +19,7 @@ static inline char* snprintf_ok(char *buf, size_t len, const char *format, ...) } #define xsprintf(buf, fmt, ...) \ - assert_message_se(snprintf_ok(buf, ELEMENTSOF(buf), fmt, ##__VA_ARGS__), "xsprintf: " #buf "[] must be big enough") + assert_message_se(snprintf_ok(buf, ELEMENTSOF(buf), fmt, ##__VA_ARGS__), "xsprintf: buffer too small") #define VA_FORMAT_ADVANCE(format, ap) \ do { \ -- 2.47.3