mirror of https://github.com/aria2/aria2
Handle the case when MINGW32 vsnprintf returns -1
MINGW32 vsnprintf returns -1 if output is truncated. Increased buffer for vsnprintf in WinConsoleFile and fmt.pull/20/head
parent
96720b297d
commit
73b75186c7
|
@ -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;
|
||||
|
|
14
src/fmt.cc
14
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;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue