mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-08 02:34:06 -04:00
Use vsnprintf on unix with a NULL buffer to get required size
This conforms to POSIX.1-2001
This commit is contained in:
parent
957126c11a
commit
7a4ea3e7f5
@ -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
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user