Bug 11560 – API returning immutable string on stack?
Status
RESOLVED
Resolution
DUPLICATE
Severity
critical
Priority
P2
Component
phobos
Product
D
Version
D2
Platform
All
OS
All
Creation time
2013-11-19T22:37:00Z
Last change time
2013-11-19T23:42:36Z
Assigned to
nobody
Creator
turkeyman
Comments
Comment #0 by turkeyman — 2013-11-19T22:37:12Z
This code:
string hash = std.digest.digest.toHexString(std.digest.sha.sha1Of("text"));
Does it seem reasonable that users should expect that 'hash' is on the stack?
As the program continues, 'hash' starts changing randomly.
hash.idup, it persists as expected.
Comment #1 by yebblies — 2013-11-19T22:59:54Z
A compilable test case that shows the problem would be helpful.
Comment #2 by turkeyman — 2013-11-19T23:30:17Z
(In reply to comment #1)
> A compilable test case that shows the problem would be helpful.
string func()
{
string hash = std.digest.digest.toHexString(std.digest.sha.sha1Of("text"));
return hash;
}
void main()
{
string s = func();
std.stdio.writeln("hello world"); // call a funtion
std.stdio.writeln(s); // s is rubbish
}
Comment #3 by yebblies — 2013-11-19T23:42:36Z
*** This issue has been marked as a duplicate of issue 9279 ***