diff --git a/src/WinConsoleFile.cc b/src/WinConsoleFile.cc index fecd55fd..dc9de9f7 100644 --- a/src/WinConsoleFile.cc +++ b/src/WinConsoleFile.cc @@ -74,12 +74,16 @@ size_t WinConsoleFile::write(const char* str) int WinConsoleFile::printf(const char* format, ...) { - char buf[1024]; + char buf[2048]; va_list ap; va_start(ap, format); int r = vsnprintf(buf, sizeof(buf), format, ap); va_end(ap); - if(r <= 0) { + if(r == -1) { + // MINGW32 vsnprintf returns -1 if output is truncated. + r = strlen(buf); + } else if(r < 0) { + // Reachable? return 0; } DWORD written; diff --git a/src/fmt.cc b/src/fmt.cc index a4e97330..5eb0979b 100644 --- a/src/fmt.cc +++ b/src/fmt.cc @@ -44,10 +44,20 @@ std::string fmt(const char* fmtTemplate, ...) { va_list ap; va_start(ap, fmtTemplate); - char buf[1024]; - if(vsnprintf(buf, sizeof(buf), fmtTemplate, ap) <= 0) { + char buf[2048]; + int rv; + rv = vsnprintf(buf, sizeof(buf), fmtTemplate, ap); +#ifdef __MINGW32__ + // MINGW32 vsnprintf returns -1 if output is truncated. + if(rv < 0 && rv != -1) { + // Reachable? buf[0] = '\0'; } +#else // !__MINGW32__ + if(rv < 0) { + buf[0] = '\0'; + } +#endif // !__MINGW32__ va_end(ap); return buf; }