[Issue 12980] New: Undefined behavior: Assignment of static string to dynamic string
via Digitalmars-d-bugs
digitalmars-d-bugs at puremagic.com
Tue Jun 24 04:02:27 PDT 2014
https://issues.dlang.org/show_bug.cgi?id=12980
Issue ID: 12980
Summary: Undefined behavior: Assignment of static string to
dynamic string
Product: D
Version: D2
Hardware: x86_64
OS: Mac OS X
Status: NEW
Severity: major
Priority: P1
Component: DMD
Assignee: nobody at puremagic.com
Reporter: yuriy.glukhov at gmail.com
import std.stdio;
char[10] getSomeString()
{
char[10] result;
int i = 0;
for (char a = '0'; a <= '9'; ++a)
{
result[i++] = a;
}
return result;
}
class A
{
this()
{
m = getSomeString();
}
string m;
}
void main()
{
A a = new A();
writeln("STRING: ", a.m); // At this point a.m points to somewhere in stack
and thus contains invalid value.
}
--
More information about the Digitalmars-d-bugs
mailing list