From 78fb845f63dd9c7d6e1c40ecb3298fcbb0824b75 Mon Sep 17 00:00:00 2001 From: Tim Wojtulewicz Date: Mon, 24 Oct 2022 17:01:45 -0700 Subject: [PATCH] Rework change to util::vfmt to fix strings getting truncated --- src/util.cc | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/util.cc b/src/util.cc index 5929c59f28..41b6410d23 100644 --- a/src/util.cc +++ b/src/util.cc @@ -1620,11 +1620,11 @@ const char* vfmt(const char* format, va_list al) va_copy(alc, al); int n = vsnprintf(buf, buf_len, format, al); - if ( n < 0 && buf_len < 1024 * 1024 ) + if ( n > 0 && buf_len < n ) { // Not enough room, grow the buffer. - buf_len += 32; + buf_len = n + 32; buf = (char*)safe_realloc(buf, buf_len); - n = vsnprintf(buf, buf_len, format, al); + n = vsnprintf(buf, buf_len, format, alc); } if ( n < 0 )