mirror of
https://github.com/dlang/phobos.git
synced 2025-04-28 14:10:30 +03:00
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:
parent
04e09c3ffa
commit
961445a303
1 changed files with 11 additions and 32 deletions
|
@ -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]);
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue