Skip to content

Commit

Permalink
Fix _mxml_vsnprintf on Windows (Issue #245)
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelrsweet committed Feb 10, 2019
1 parent 1b8f4a2 commit a69fcbc
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 14 deletions.
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions mxml-file.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@
* Include necessary headers...
*/

#ifndef WIN32
#ifndef _WIN32
# include <unistd.h>
#endif /* !WIN32 */
#endif /* !_WIN32 */
#include "mxml-private.h"


Expand Down
2 changes: 1 addition & 1 deletion mxml-private.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down
11 changes: 4 additions & 7 deletions mxml-string.c
Original file line number Diff line number Diff line change
Expand Up @@ -526,28 +526,25 @@ _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...
*/

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)
Expand Down
8 changes: 4 additions & 4 deletions testmxml.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -721,7 +721,7 @@ main(int argc, /* I - Number of command-line args */
}
}

#ifndef WIN32
#ifndef _WIN32
/*
* Debug hooks...
*/
Expand All @@ -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...
Expand Down

0 comments on commit a69fcbc

Please sign in to comment.