Bug 10644 – Win64: wrong code when passing arguments through ...
Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P2
Component
phobos
Product
D
Version
D2
Platform
x86_64
OS
Windows
Creation time
2013-07-15T00:25:00Z
Last change time
2013-07-20T11:42:19Z
Keywords
wrong-code
Assigned to
nobody
Creator
r.sagitario
Comments
Comment #0 by r.sagitario — 2013-07-15T00:25:39Z
An example from the unittest of std.outbuffer:
import std.outbuffer;
void main()
{
OutBuffer buf = new OutBuffer();
buf.printf("%d", 42);
assert(buf.toString() == "42");
}
build and run for win64 throws the assertion.
Checking the implementation of OutBuffer.printf shows that there is no uniform abstraction for passing arguments to printf(string format, ...) anyway, and the Win64 version seems broken.
This also applies to stream.printf.
Comment #1 by bugzilla — 2013-07-19T00:51:07Z
This shrinks down to:
---------------------
import std.c.stdio;
import std.c.stdarg;
void vpr(string format, va_list args)
{
char[128] buffer;
int count;
auto f = format.ptr;
auto p = buffer.ptr;
auto psize = buffer.length;
printf("format = %d, %s\n", cast(int)format.length, f);
count = _vsnprintf(p,psize,f,args);
printf("count = %d, p = %s\n", count, p);
}
void pr(string format, ...)
{
va_list ap;
ap = cast(va_list)&format;
ap += format.sizeof;
vpr(format, ap);
}
void main()
{
pr("%d", 42);
}