You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
35 lines
1.4 KiB
35 lines
1.4 KiB
_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 <ps_ml@gmx.de>. |
|
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: "); |
|
+# 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");
|
|
|