From: Florian Krohm Date: Sun, 28 Sep 2014 21:35:07 +0000 (+0000) Subject: Merge r14125 from the BUF_REMOVAL branch to trunk. X-Git-Tag: svn/VALGRIND_3_11_0~951 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=e52ad4cb36dda147c8552dac7a29b1c6c0908a21;p=thirdparty%2Fvalgrind.git 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 --- diff --git a/coregrind/m_libcassert.c b/coregrind/m_libcassert.c index d48751f284..f982ff96aa 100644 --- a/coregrind/m_libcassert.c +++ b/coregrind/m_libcassert.c @@ -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); }