076f82
commit b2f32e746492615a6eb3e66fac1e766e32e8deb1
076f82
Author: Florian Weimer <fweimer@redhat.com>
076f82
Date:   Thu Jul 21 12:12:08 2022 +0200
076f82
076f82
    malloc: Simplify implementation of __malloc_assert
076f82
    
076f82
    It is prudent not to run too much code after detecting heap
076f82
    corruption, and __fxprintf is really complex.  The line number
076f82
    and file name do not carry much information, so it is not included
076f82
    in the error message.  (__libc_message only supports %s formatting.)
076f82
    The function name and assertion should provide some context.
076f82
    
076f82
    Reviewed-by: Siddhesh Poyarekar <siddhesh@sourceware.org>
076f82
    (cherry picked from commit ac8047cdf326504f652f7db97ec96c0e0cee052f)
076f82
076f82
diff --git a/malloc/malloc.c b/malloc/malloc.c
076f82
index 7882c70f0a0312d1..d31e985ecce968fe 100644
076f82
--- a/malloc/malloc.c
076f82
+++ b/malloc/malloc.c
076f82
@@ -294,19 +294,14 @@
076f82
 # define __assert_fail(assertion, file, line, function)			\
076f82
 	 __malloc_assert(assertion, file, line, function)
076f82
 
076f82
-extern const char *__progname;
076f82
-
076f82
-static void
076f82
+_Noreturn static void
076f82
 __malloc_assert (const char *assertion, const char *file, unsigned int line,
076f82
 		 const char *function)
076f82
 {
076f82
-  (void) __fxprintf (NULL, "%s%s%s:%u: %s%sAssertion `%s' failed.\n",
076f82
-		     __progname, __progname[0] ? ": " : "",
076f82
-		     file, line,
076f82
-		     function ? function : "", function ? ": " : "",
076f82
-		     assertion);
076f82
-  fflush (stderr);
076f82
-  abort ();
076f82
+  __libc_message (do_abort, "\
076f82
+Fatal glibc error: malloc assertion failure in %s: %s\n",
076f82
+		  function, assertion);
076f82
+  __builtin_unreachable ();
076f82
 }
076f82
 #endif
076f82
 #endif