From 7a4ea3e7f5eb21a688d5e729ce42f5c76d03e22a Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Tue, 8 Dec 2015 15:21:24 +0530 Subject: [PATCH] Use vsnprintf on unix with a NULL buffer to get required size This conforms to POSIX.1-2001 --- src/calibre/utils/podofo/output.cpp | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-) diff --git a/src/calibre/utils/podofo/output.cpp b/src/calibre/utils/podofo/output.cpp index 4d9a775eb2..3617d63bee 100644 --- a/src/calibre/utils/podofo/output.cpp +++ b/src/calibre/utils/podofo/output.cpp @@ -52,16 +52,7 @@ class OutputDevice : public PdfOutputDevice { #ifdef _MSC_VER return _vscprintf(pszFormat, args); #else - char *buf; - 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; - } + return vsnprintf(NULL, 0, pszFormat, args); #endif }