OSDN Git Service

Prevent runaway asserts, which can happen if there's a problem with
authorManuel Novoa III <mjn3@codepoet.org>
Sat, 17 Jan 2004 14:39:40 +0000 (14:39 -0000)
committerManuel Novoa III <mjn3@codepoet.org>
Sat, 17 Jan 2004 14:39:40 +0000 (14:39 -0000)
stdio or locales.

libc/misc/assert/__assert.c

index 26bcc65..74b5ee8 100644 (file)
@@ -46,21 +46,27 @@ extern const char *__progname;
 
 #if 1
 
+static int in_assert;                  /* bss inits to 0. */
+
 void __assert(const char *assertion, const char * filename,
                          int linenumber, register const char * function)
 {
-       fprintf(stderr,
+       if (!in_assert) {
+               in_assert = 1;
+
+               fprintf(stderr,
 #ifdef ASSERT_SHOW_PROGNAME
-                       "%s: %s: %d: %s: Assertion `%s' failed.\n", __progname,
+                               "%s: %s: %d: %s: Assertion `%s' failed.\n", __progname,
 #else
-                       "%s: %d: %s: Assertion `%s' failed.\n",
+                               "%s: %d: %s: Assertion `%s' failed.\n",
 #endif
-                       filename,
-                       linenumber,
-                       /* Function name isn't available with some compilers. */
-                       ((function == NULL) ? "?function?" : function),
-                       assertion
-                       );
+                               filename,
+                               linenumber,
+                               /* Function name isn't available with some compilers. */
+                               ((function == NULL) ? "?function?" : function),
+                               assertion
+                               );
+       }
        abort();
 }