Merge r14125 from the BUF_REMOVAL branch to trunk.
This change eliminates the fixed size buffer in VG_(assert_fail).


git-svn-id: svn://svn.valgrind.org/valgrind/trunk@14588 a5019735-40e9-0310-863c-91ae7b9d1cf9
diff --git a/coregrind/m_libcassert.c b/coregrind/m_libcassert.c
index d48751f..f982ff9 100644
--- a/coregrind/m_libcassert.c
+++ b/coregrind/m_libcassert.c
@@ -410,8 +410,7 @@
 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 @@
       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 @@
       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);
 }