Skip to content

Commit 3a00f52

Browse files
author
philippe
committed
Fix vassert_fail producing random output for an empty format
vsnprintf does not do any addition to the buffer for an empty format. So, buf was not null terminated. This e.g. causes an assert_fail to output random characters after the failed expression. Fix by ensuring the buffer of vsnprintf is always null terminated to start with. git-svn-id: svn://svn.valgrind.org/valgrind/trunk@13291 a5019735-40e9-0310-863c-91ae7b9d1cf9
1 parent 3a53220 commit 3a00f52

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

coregrind/m_libcprint.c

+2-1
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,8 @@ UInt VG_(vsnprintf) ( HChar* buf, Int size, const HChar *format, va_list vargs )
232232
b.buf = buf;
233233
b.buf_size = size < 0 ? 0 : size;
234234
b.buf_used = 0;
235-
235+
if (b.buf_size > 0)
236+
b.buf[0] = 0; // ensure to null terminate buf if empty format
236237
(void) VG_(debugLog_vprintf)
237238
( add_to__snprintf_buf, &b, format, vargs );
238239

0 commit comments

Comments
 (0)