[Issue 1766] segfault writing to a string variable...

d-bugmail at puremagic.com d-bugmail at puremagic.com
Wed Jan 2 17:25:47 PST 2008


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





------- Comment #1 from ddparnell at bigpond.com  2008-01-02 19:25 -------
I don't think this is a bug. Its working as I would expect it to.

The identifier 'lala' is not a VARIABLE, its a reference to a string literal
and literals are in read-only memory on Linux, thus you can't write to it. The
segfault is the operating system's reaction to the attempt.

Use this instead ...

void main() {
        string lala = "     ".dup; // Take a writable copy of the literal.
        lala[0] = '1';
}


-- 



More information about the D.gnu mailing list