From 31326a2cac0cf0cc6134bc3369ba587be9d4b4f2 Mon Sep 17 00:00:00 2001 From: Albert Astals Cid Date: Thu, 29 Sep 2011 12:50:09 +0200 Subject: [PATCH] Apply and update 06-mingw-_synctex_error.diff --- .../patches/06-mingw-_synctex_error.diff | 10 +++++----- .../poppler/synctex/synctex_parser_utils.c | 18 ++++++++++++++++++ 2 files changed, 23 insertions(+), 5 deletions(-) diff --git a/generators/poppler/synctex/patches/06-mingw-_synctex_error.diff b/generators/poppler/synctex/patches/06-mingw-_synctex_error.diff index d92fd0814..5c838d775 100644 --- a/generators/poppler/synctex/patches/06-mingw-_synctex_error.diff +++ b/generators/poppler/synctex/patches/06-mingw-_synctex_error.diff @@ -2,11 +2,11 @@ _vscprintf() is specific for MSVC; thus in _synctex_error(), for any other compiler on Windows, use _vsnprintf() and grow the buffer until necessary. Patch provided by Patrick Spendrin . -Index: synctex/synctex_parser_utils.c -=================================================================== ---- synctex.orig/synctex_parser_utils.c 2010-05-23 19:17:10.000000000 +0200 -+++ synctex/synctex_parser_utils.c 2010-05-23 19:17:33.000000000 +0200 -@@ -89,8 +89,26 @@ +diff --git a/generators/poppler/synctex/synctex_parser_utils.c b/generators/poppler/synctex/synctex_parser_utils.c +index e85ca73..ef1645e 100644 +--- a/generators/poppler/synctex/synctex_parser_utils.c ++++ b/generators/poppler/synctex/synctex_parser_utils.c +@@ -90,8 +90,26 @@ int _synctex_error(const char * reason,...) { char *buff; size_t len; OutputDebugStringA("SyncTeX ERROR: "); diff --git a/generators/poppler/synctex/synctex_parser_utils.c b/generators/poppler/synctex/synctex_parser_utils.c index e85ca7300..ef1645e5e 100644 --- a/generators/poppler/synctex/synctex_parser_utils.c +++ b/generators/poppler/synctex/synctex_parser_utils.c @@ -90,8 +90,26 @@ int _synctex_error(const char * reason,...) { char *buff; size_t len; OutputDebugStringA("SyncTeX ERROR: "); +# ifdef _MSC_VER len = _vscprintf(reason, arg) + 1; buff = (char*)malloc( len * sizeof(char) ); +#else /* MinGW */ + size_t buffersize = 1024; + size_t max_buffersize = 1024 * buffersize; + int result; + buff = (char*)malloc(buffersize * sizeof(char)); + result = _vsnprintf(buff, buffersize - 1, reason, arg); + while(-1 == result && buffersize <= max_buffersize) { + buffersize = buffersize * 2; + buff = (char*)realloc(buff, buffersize * sizeof(char)); + result = _vsnprintf(buff, buffersize - 1, reason, arg); + } + if(-1 == result) { + // could not make the buffer big enough or simply could not write to it + free(buff); + return -1; + } +#endif result = vsprintf(buff, reason, arg) +strlen("SyncTeX ERROR: "); OutputDebugStringA(buff); OutputDebugStringA("\n");