From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2178) id 40A0E384D19F; Thu, 21 Jul 2022 14:33:43 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 40A0E384D19F 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] malloc: Simplify implementation of __malloc_assert X-Act-Checkin: glibc X-Git-Author: Florian Weimer X-Git-Refname: refs/heads/master X-Git-Oldrev: 8b84fb862c3c212b294b5f7bf443cb8372dc5376 X-Git-Newrev: ac8047cdf326504f652f7db97ec96c0e0cee052f Message-Id: <20220721143343.40A0E384D19F@sourceware.org> Date: Thu, 21 Jul 2022 14:33:43 +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 14:33:43 -0000 https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=ac8047cdf326504f652f7db97ec96c0e0cee052f commit ac8047cdf326504f652f7db97ec96c0e0cee052f 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 Diff: --- malloc/malloc.c | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/malloc/malloc.c b/malloc/malloc.c index 12908b8f97..bd3c76ed31 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