www.digitalmars.com         C & C++   DMDScript  

D.gnu - [Issue 1185] New: assignment failure

reply d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=1185

           Summary: assignment failure
           Product: DGCC aka GDC
           Version: 0.23
          Platform: Other
        OS/Version: Linux
            Status: NEW
          Severity: critical
          Priority: P2
         Component: glue layer
        AssignedTo: dvdfrdmn users.sf.net
        ReportedBy: sheffmail mail.ru


The following code compiles successfully but when it runs it generates SIGSEGV:

int main(char[][] args)
{
 char[] a = "a";
 a[0] = 'b';
}


-- 
Apr 24 2007
next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=1185





------- Comment #1 from afb algonet.se  2007-04-24 05:32 -------
This is by language design, the code is not using COW.
(should use a a.dup, before trying to assign anything)

See http://www.digitalmars.com/d/dcompiler.html#linux :
Differences from Win32 version
* String literals are read-only. Attempting to write to them will cause a
segment violation.
Same goes for GDC, see the "writable-strings" settings.


-- 
Apr 24 2007
prev sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=1185


bugzilla digitalmars.com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|                            |INVALID




------- Comment #2 from bugzilla digitalmars.com  2007-04-25 03:28 -------
Writing to string literals causes undefined behavior.


-- 
Apr 25 2007