Skip to content
Permalink
Browse files
Deal with quirks of MSVC's vsnprintf() implementation.
  • Loading branch information
Baldur Karlsson committed Apr 18, 2016
1 parent 303b5b1 commit e2940f39b23f364a45832c94c94430fdf8a2c184
Showing with 16 additions and 1 deletion.
  1. +16 −1 mojoshader_common.c
@@ -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)
{

0 comments on commit e2940f3

Please sign in to comment.