[Issue 3797] Implicit conversion between incompatible function pointers
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Mon Oct 18 19:30:20 PDT 2010
http://d.puremagic.com/issues/show_bug.cgi?id=3797
--- Comment #5 from yebblies <yebblies at gmail.com> 2010-10-18 19:29:40 PDT ---
(In reply to comment #4)
> Is this a cross-platform bug?
Yes. The problem is that pointers to functions with different calling
conventions and parameters can be implicitly converted to each other. This can
easily cause stack corruption and/or corrupted parameters. This is not unique
to any platform.
------------------------------
import std.stdio;
import std.typetuple;
extern(D)
{
void d1() { writeln("d1"); }
void d2(int a) { writeln("d2(", a, ")"); }
void d3(int a, int b) { writeln("d3(", a, ", ", b, ")"); }
void d4(long a, long b) { writeln("d4(", a, ", ", b, ")"); }
}
extern(C)
{
void c1() { writeln("c1"); }
void c2(int a) { writeln("c2(", a, ")"); }
void c3(int a, int b) { writeln("c3(", a, ", ", b, ")"); }
void c4(long a, long b) { writeln("c4(", a, ", ", b, ")"); }
}
extern(Windows)
{
void w1() { writeln("w1"); }
void w2(int a) { writeln("w2(", a, ")"); }
void w3(int a, int b) { writeln("w3(", a, ", ", b, ")"); }
void w4(long a, long b) { writeln("w4(", a, ", ", b, ")"); }
}
extern(C++)
{
void cpp1() { writeln("cpp1"); }
void cpp2(int a) { writeln("cpp2(", a, ")"); }
void cpp3(int a, int b) { writeln("cpp3(", a, ", ", b, ")"); }
void cpp4(long a, long b) { writeln("cpp4(", a, ", ", b, ")"); }
}
extern(Pascal)
{
void p1() { writeln("p1"); }
void p2(int a) { writeln("p2(", a, ")"); }
void p3(int a, int b) { writeln("p3(", a, ", ", b, ")"); }
void p4(long a, long b) { writeln("p4(", a, ", ", b, ")"); }
}
void main()
{
size_t stack;
asm { mov stack, ESP; }
writeln(stack);
alias TypeTuple!(d1, d2, d3, d4, c1, c2, c3, c4, w1, w2, w3, w4, cpp1,
cpp2, cpp3, cpp4, p1, p2, p3, p4) functions;
auto fptr = &d3;
foreach(f; functions)
{
fptr = &f;
fptr(1, 2);
}
asm { mov stack, ESP; }
writeln(stack);
}
--
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
More information about the Digitalmars-d-bugs
mailing list