From bcfdc806a5681dc5f8f9e49f689e89c645f0b87d Mon Sep 17 00:00:00 2001 From: Holger Vogt Date: Wed, 4 Mar 2020 22:44:20 +0100 Subject: [PATCH] work around a bug in MINGW Reported in https://github.com/msys2/MINGW-packages/issues/6254 --- src/misc/string.c | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/src/misc/string.c b/src/misc/string.c index 7aaf87c03..2b9cf1c29 100644 --- a/src/misc/string.c +++ b/src/misc/string.c @@ -106,6 +106,23 @@ char *tvprintf(const char *fmt, va_list args) * usage, but both return negative values (possibly -1) on an * encoding error, which would lead to an infinte loop (until * memory was exhausted) with the old behavior */ + +#ifdef __MINGW32__ + /* mingw still shows the 'old behavior' */ + if (nchars == -1) { // compatibility to old implementations + size *= 2; + } + else if (size < nchars + 1) { + size = nchars + 1; + } + else { + break; + } + /* limit memory usage */ + if (size > 100000) { + controlled_exit(-1); + } +#else if (nchars < 0) { controlled_exit(-1); } @@ -118,7 +135,7 @@ char *tvprintf(const char *fmt, va_list args) * that would have been written if the buffer were large enough * excluding the terminiating null. */ size = nchars + 1; /* min required allocation size */ - +#endif /* Allocate a larger buffer */ if (p == buf) { p = TMALLOC(char, size);