]> git.ipfire.org Git - thirdparty/valgrind.git/commitdiff
Merge r14125 from the BUF_REMOVAL branch to trunk.
authorFlorian Krohm <florian@eich-krohm.de>
Sun, 28 Sep 2014 21:35:07 +0000 (21:35 +0000)
committerFlorian Krohm <florian@eich-krohm.de>
Sun, 28 Sep 2014 21:35:07 +0000 (21:35 +0000)
This change eliminates the fixed size buffer in VG_(assert_fail).

git-svn-id: svn://svn.valgrind.org/valgrind/trunk@14588

coregrind/m_libcassert.c

index d48751f2840c7925b2420c84de36231f51eda024..f982ff96aa9a98fb3f2780aa6e650cbee528f42b 100644 (file)
@@ -410,8 +410,7 @@ static void report_and_quit ( const HChar* report,
 void VG_(assert_fail) ( Bool isCore, const HChar* expr, const HChar* file, 
                         Int line, const HChar* fn, const HChar* format, ... )
 {
-   va_list vargs;
-   HChar buf[512];
+   va_list vargs, vargs_copy;
    const HChar* component;
    const HChar* bugs_to;
    UInt written;
@@ -421,15 +420,6 @@ void VG_(assert_fail) ( Bool isCore, const HChar* expr, const HChar* file,
       VG_(exit)(2);
    entered = True;
 
-   va_start(vargs, format);
-   written = VG_(vsnprintf) ( buf, sizeof(buf), format, vargs );
-   va_end(vargs);
-
-   if (written >= sizeof(buf)) {
-      VG_(printf)("\nvalgrind: %s: buf is too small, sizeof(buf) = %u, "
-                  "written = %d\n", __func__, (unsigned)sizeof(buf), written);
-   }
-
    if (isCore) {
       component = "valgrind";
       bugs_to   = VG_BUGS_TO;
@@ -449,8 +439,19 @@ void VG_(assert_fail) ( Bool isCore, const HChar* expr, const HChar* file,
       VG_(printf)("\n%s: %s:%d (%s): Assertion '%s' failed.\n",
                   component, file, line, fn, expr );
    }
-   if (!VG_STREQ(buf, ""))
-      VG_(printf)("%s: %s\n", component, buf );
+
+   /* Check whether anything will be written */
+   HChar buf[5];
+   va_start(vargs, format);
+   va_copy(vargs_copy, vargs);
+   written = VG_(vsnprintf) ( buf, sizeof(buf), format, vargs );
+   va_end(vargs);
+
+   if (written > 0) {
+      VG_(printf)("%s: ", component);
+      VG_(vprintf)(format, vargs_copy);
+      VG_(printf)("\n");
+   }
 
    report_and_quit(bugs_to, NULL);
 }