Fix std.outbuffer.[v]printf() for Visual Studio 2015+

MS conforms to the standard beginning with VS 2015, i.e., if the buffer is too small,
vsnprintf() returns the number of required characters (excl. terminating null). VS 2013
and earlier always returned -1 in that case.
So just use the generic (previous POSIX) version, it's compatible with older VS anyway.

Already unittested in line 380 ("hello world 6" vs. "hello world 62665").
This commit is contained in:
kinke 2017-02-07 23:30:23 +01:00 committed by GitHub
parent 04e09c3ffa
commit 961445a303

View file

@ -255,22 +255,6 @@ class OutBuffer
auto p = buffer.ptr;
auto psize = buffer.length;
for (;;)
{
version(Windows)
{
va_list args2;
va_copy(args2, args);
count = vsnprintf(p,psize,f,args2);
va_end(args2);
if (count != -1)
break;
if (psize > psize.max / 2) assert(0); // overflow check
psize *= 2;
p = cast(char *) alloca(psize); // buffer too small, try again with larger size
}
else version(Posix)
{
va_list args2;
va_copy(args2, args);
@ -291,11 +275,6 @@ class OutBuffer
p = cast(char *) alloca(psize); // buffer too small, try again with larger size
}
else
{
static assert(0);
}
}
write(cast(ubyte[]) p[0 .. count]);
}