From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2178) id B2582385843D; Thu, 21 Jul 2022 15:05:31 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org B2582385843D Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: Florian Weimer To: glibc-cvs@sourceware.org Subject: [glibc/release/2.35/master] malloc: Simplify implementation of __malloc_assert X-Act-Checkin: glibc X-Git-Author: Florian Weimer X-Git-Refname: refs/heads/release/2.35/master X-Git-Oldrev: dc2d843045678f4adb7803f1ed0dd05147770974 X-Git-Newrev: 0e5b239f45992e4b54c6f946ecb0c410afc8bb08 Message-Id: <20220721150531.B2582385843D@sourceware.org> Date: Thu, 21 Jul 2022 15:05:31 +0000 (GMT) X-BeenThere: glibc-cvs@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Glibc-cvs mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 21 Jul 2022 15:05:31 -0000 https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=0e5b239f45992e4b54c6f946ecb0c410afc8bb08 commit 0e5b239f45992e4b54c6f946ecb0c410afc8bb08 Author: Florian Weimer Date: Thu Jul 21 12:12:08 2022 +0200 malloc: Simplify implementation of __malloc_assert It is prudent not to run too much code after detecting heap corruption, and __fxprintf is really complex. The line number and file name do not carry much information, so it is not included in the error message. (__libc_message only supports %s formatting.) The function name and assertion should provide some context. Reviewed-by: Siddhesh Poyarekar (cherry picked from commit ac8047cdf326504f652f7db97ec96c0e0cee052f) Diff: --- malloc/malloc.c | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/malloc/malloc.c b/malloc/malloc.c index 1a1ac1d8f0..fe9cb9b800 100644 --- a/malloc/malloc.c +++ b/malloc/malloc.c @@ -292,19 +292,14 @@ # define __assert_fail(assertion, file, line, function) \ __malloc_assert(assertion, file, line, function) -extern const char *__progname; - -static void +_Noreturn static void __malloc_assert (const char *assertion, const char *file, unsigned int line, const char *function) { - (void) __fxprintf (NULL, "%s%s%s:%u: %s%sAssertion `%s' failed.\n", - __progname, __progname[0] ? ": " : "", - file, line, - function ? function : "", function ? ": " : "", - assertion); - fflush (stderr); - abort (); + __libc_message (do_abort, "\ +Fatal glibc error: malloc assertion failure in %s: %s\n", + function, assertion); + __builtin_unreachable (); } #endif #endif