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






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





Writing to string literals causes undefined behavior.


-- 
Apr 25 2007