Fix _mxml_vsnprintf on Windows (Issue #245)

This commit is contained in:
Michael R Sweet 2019-02-10 10:40:53 -05:00
parent 1b8f4a2091
commit a69fcbcaaa
No known key found for this signature in database
GPG Key ID: 999559A027815955
5 changed files with 12 additions and 14 deletions

View File

@ -12,6 +12,7 @@
`mxmlSetText`, and `mxmlSetTextf` functions caused a use-after-free bug if
the value came from the same node (Issue #241)
- The `mxmlSetOpaquef` and `mxmlSetTextf` functions did not work (Issue #244)
- The `_mxml_strdupf` function did not work on Windows (Issue #245)
# Changes in Mini-XML 2.12

View File

@ -13,9 +13,9 @@
* Include necessary headers...
*/
#ifndef WIN32
#ifndef _WIN32
# include <unistd.h>
#endif /* !WIN32 */
#endif /* !_WIN32 */
#include "mxml-private.h"

View File

@ -216,7 +216,7 @@ _mxml_init(void)
}
#elif defined(WIN32) && defined(MXML1_EXPORTS) /**** WIN32 threading ****/
#elif defined(_WIN32) && defined(MXML1_EXPORTS) /**** WIN32 threading ****/
# include <windows.h>
static DWORD _mxml_tls_index; /* Index for global storage */

View File

@ -526,17 +526,14 @@ _mxml_vstrdupf(const char *format, /* I - Printf-style format string */
* needed...
*/
# ifdef WIN32
# ifdef _WIN32
bytes = _vscprintf(format, ap);
# else
va_list apcopy; /* Copy of argument list */
va_copy(apcopy, ap);
bytes = vsnprintf(temp, sizeof(temp), format, apcopy);
# endif /* WIN32 */
if (bytes < sizeof(temp))
if ((bytes = vsnprintf(temp, sizeof(temp), format, apcopy)) < sizeof(temp))
{
/*
* Hey, the formatted string fits in the tiny buffer, so just dup that...
@ -544,10 +541,10 @@ _mxml_vstrdupf(const char *format, /* I - Printf-style format string */
return (strdup(temp));
}
# endif /* _WIN32 */
/*
* Allocate memory for the whole thing and reformat to the new, larger
* buffer...
* Allocate memory for the whole thing and reformat to the new buffer...
*/
if ((buffer = calloc(1, bytes + 1)) != NULL)

View File

@ -20,9 +20,9 @@
#include "config.h"
#include "mxml-private.h"
#ifndef WIN32
#ifndef _WIN32
# include <unistd.h>
#endif /* !WIN32 */
#endif /* !_WIN32 */
#include <fcntl.h>
#ifndef O_BINARY
# define O_BINARY 0
@ -721,7 +721,7 @@ main(int argc, /* I - Number of command-line args */
}
}
#ifndef WIN32
#ifndef _WIN32
/*
* Debug hooks...
*/
@ -738,7 +738,7 @@ main(int argc, /* I - Number of command-line args */
puts("Unable to check for leaks.");
}
# endif /* __APPLE__ */
#endif /* !WIN32 */
#endif /* !_WIN32 */
/*
* Return...