Use vsnprintf on unix with a NULL buffer to get required size

This conforms to POSIX.1-2001
This commit is contained in:
Kovid Goyal 2015-12-08 15:21:24 +05:30
parent 957126c11a
commit 7a4ea3e7f5
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C

View File

@ -52,16 +52,7 @@ class OutputDevice : public PdfOutputDevice {
#ifdef _MSC_VER #ifdef _MSC_VER
return _vscprintf(pszFormat, args); return _vscprintf(pszFormat, args);
#else #else
char *buf; return vsnprintf(NULL, 0, pszFormat, args);
int res, len=1024;
while(true) {
buf = new (std::nothrow) char[len+1];
if (buf == NULL) { PyErr_NoMemory(); throw pyerr(); }
res = vsnprintf(buf, len, pszFormat, args);
delete[] buf;
if (res >= 0) return res + 1;
len *= 2;
}
#endif #endif
} }