From 94b192b1340658d92df8e5dcf6a48d9f32f5f96e Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Sun, 2 Sep 2012 18:04:56 +0530 Subject: [PATCH] ... --- src/calibre/utils/podofo/output.cpp | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/src/calibre/utils/podofo/output.cpp b/src/calibre/utils/podofo/output.cpp index b0620f7f82..015949502a 100644 --- a/src/calibre/utils/podofo/output.cpp +++ b/src/calibre/utils/podofo/output.cpp @@ -37,14 +37,16 @@ class OutputDevice : public PdfOutputDevice { #ifdef _MSC_VER return _vscprintf(pszFormat, args); #else - char buf[10]; - int res; - res = vsnprintf(buf, 1, pszFormat, args); - if (res < 0) { - PyErr_SetString(PyExc_Exception, "Something bad happened while calling vsnprintf to get buffer length"); - throw pyerr(); + char *buf; + int res, len=1024; + while(true) { + buf = new (std::nothrow) char[len]; + if (buf == NULL) { PyErr_NoMemory(); throw pyerr(); } + res = vsnprintf(buf, len, pszFormat, args); + delete[] buf; + if (res >= 0) return res + 1; + len *= 2; } - return static_cast(res+1); #endif }