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