This commit is contained in:
Kovid Goyal 2012-09-02 18:04:56 +05:30
parent f280dd4de7
commit 94b192b134

View File

@ -37,14 +37,16 @@ class OutputDevice : public PdfOutputDevice {
#ifdef _MSC_VER #ifdef _MSC_VER
return _vscprintf(pszFormat, args); return _vscprintf(pszFormat, args);
#else #else
char buf[10]; char *buf;
int res; int res, len=1024;
res = vsnprintf(buf, 1, pszFormat, args); while(true) {
if (res < 0) { buf = new (std::nothrow) char[len];
PyErr_SetString(PyExc_Exception, "Something bad happened while calling vsnprintf to get buffer length"); if (buf == NULL) { PyErr_NoMemory(); throw pyerr(); }
throw pyerr(); res = vsnprintf(buf, len, pszFormat, args);
delete[] buf;
if (res >= 0) return res + 1;
len *= 2;
} }
return static_cast<long>(res+1);
#endif #endif
} }