[Issue 16555] New: Stack corruption when calling multi-parameter outer function from nested function
via Digitalmars-d-bugs
digitalmars-d-bugs at puremagic.com
Tue Sep 27 13:56:24 PDT 2016
https://issues.dlang.org/show_bug.cgi?id=16555
Issue ID: 16555
Summary: Stack corruption when calling multi-parameter outer
function from nested function
Product: D
Version: D2
Hardware: x86_64
OS: Linux
Status: NEW
Keywords: wrong-code
Severity: normal
Priority: P1
Component: dmd
Assignee: nobody at puremagic.com
Reporter: bugzilla at kyllingen.net
When a nested function calls an outer function with a large number of
parameters, the first argument becomes corrupted.
Test case:
void outer(
double x,
double a, double b, double c, double d,
double e, double f, double g, double h)
{
import std.stdio;
writefln("x=%s a=%s b=%s c=%s d=%s e=%s f=%s g=%s h=%s",
x, a, b, c, d, e, f, g, h);
}
void main()
{
void inner(double x)
{
outer(x, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0);
}
inner(999.0);
}
Here, the value of x in outer() is garbage. That is, the program SHOULD print:
x=999 a=1 b=2 c=3 d=4 e=5 f=6 g=7 h=8
But instead, it prints something like:
x=6.95253e-310 a=1 b=2 c=3 d=4 e=5 f=6 g=7 h=8
Reducing the number of parameters of outer() makes the problem go away. Also,
interestingly, if the program is compiled with -O or -inline, the correct
behaviour is restored.
--
More information about the Digitalmars-d-bugs
mailing list