From 6f0ea84f17581d13ad668adbc181c37141d389b8 Mon Sep 17 00:00:00 2001 From: Adhemerval Zanella Date: Mon, 30 Dec 2024 16:36:18 -0300 Subject: assert: Remove the use of %n from __assert_fail_base (BZ #32456) The require size for mmap can be inferred from __vasprintf return value. It also fixes tst-assert-2 when building with --enable-fortify, where even if the format is not translated, __readonly_area fails because malloc can not be used. Checked on aarch64-linux-gnu. Reviewed-by: Florian Weimer --- assert/assert.c | 27 ++++++++++----------------- 1 file changed, 10 insertions(+), 17 deletions(-) (limited to 'assert/assert.c') diff --git a/assert/assert.c b/assert/assert.c index 47b06ec7fd..db90b8d7ef 100644 --- a/assert/assert.c +++ b/assert/assert.c @@ -15,24 +15,17 @@ License along with the GNU C Library; if not, see . */ -#include -#include +#include #include #include -#include -#include -#include -#include -#include +#include #include #include -#include +#include extern const char *__progname; -#include -#include #define fflush(s) _IO_fflush (s) /* This function, when passed a string containing an asserted @@ -56,12 +49,12 @@ __assert_fail_base (const char *fmt, const char *assertion, const char *file, FATAL_PREPARE; #endif - int total; - if (__asprintf (&str, fmt, - __progname, __progname[0] ? ": " : "", - file, line, - function ? function : "", function ? ": " : "", - assertion, &total) >= 0) + int total = __asprintf (&str, fmt, + __progname, __progname[0] ? ": " : "", + file, line, + function ? function : "", function ? ": " : "", + assertion); + if (total >= 0) { /* Print the message. */ (void) __fxprintf (NULL, "%s", str); @@ -129,6 +122,6 @@ void __assert_fail (const char *assertion, const char *file, unsigned int line, const char *function) { - __assert_fail_base (_("%s%s%s:%u: %s%sAssertion `%s' failed.\n%n"), + __assert_fail_base (_("%s%s%s:%u: %s%sAssertion `%s' failed.\n"), assertion, file, line, function); } -- cgit v1.2.3