Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Deal with quirks of MSVC's vsnprintf() implementation.
  • Loading branch information
Baldur Karlsson committed Apr 18, 2016
1 parent 303b5b1 commit e2940f3
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion mojoshader_common.c
Expand Up @@ -557,9 +557,24 @@ int errorlist_add_va(ErrorList *list, const char *_fname,
char scratch[128];
va_list ap;
va_copy(ap, va);
const int len = vsnprintf(scratch, sizeof (scratch), fmt, ap);
int len = vsnprintf(scratch, sizeof (scratch), fmt, ap);
va_end(ap);

// on some versions of the windows C runtime, vsnprintf() returns -1
// if the buffer overflows instead of the length the string would have
// been as expected.
// In this case we make another copy of va and fetch the length only
// with another call to _vscprintf

#ifdef _MSC_VER
if (len == -1)
{
va_copy(ap, va);
len = _vscprintf(fmt, ap);
va_end(ap);
}
#endif

char *failstr = (char *) list->m(len + 1, list->d);
if (failstr == NULL)
{
Expand Down

0 comments on commit e2940f3

Please sign in to comment.