[Issue 8229] string literals are not zero-terminated during CTFE

d-bugmail at puremagic.com d-bugmail at puremagic.com
Fri Sep 27 15:58:32 PDT 2013


http://d.puremagic.com/issues/show_bug.cgi?id=8229


Martin Nowak <code at dawg.eu> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |code at dawg.eu
           Severity|normal                      |major


--- Comment #4 from Martin Nowak <code at dawg.eu> 2013-09-27 15:58:28 PDT ---
---
string bug(string a)
{
    char[] buf;
    buf.length = a.length;
    buf[0 .. a.length] = a[];
    return cast(string)buf[];
}

static const var = bug("foo");
---

I have a much bigger problem related to this.
String literals resulting from CTFE are missing the terminating zero in the
data segment. Whether or not the bug bites depends on the object layout and the
virtual memory mapping, so this is pretty annoying because it works too often.
The underlying issue is that var is emitted to the object file from
ArrayLiteralExp::toDt which doesn't perform the zero termination.
Not sure if and at which stage this should be converted to a StringLiteralExp.

-- 
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