www.digitalmars.com Home | Search | C & C++ | D | DMDScript | News Groups | index | prev | next
Archives

D Programming
D
D.gnu
digitalmars.D
digitalmars.D.bugs
digitalmars.D.dtl
digitalmars.D.ide
digitalmars.D.dwt
digitalmars.D.announce
digitalmars.D.learn
digitalmars.D.debugger

C/C++ Programming
c++
c++.announce
c++.atl
c++.beta
c++.chat
c++.command-line
c++.dos
c++.dos.16-bits
c++.dos.32-bits
c++.idde
c++.mfc
c++.rtl
c++.stl
c++.stl.hp
c++.stl.port
c++.stl.sgi
c++.stlsoft
c++.windows
c++.windows.16-bits
c++.windows.32-bits
c++.wxwindows

digitalmars.empire
digitalmars.DMDScript
electronics




D.gnu - [Issue 1766] New: segfault writing to a string variable...

↑ ↓ ← d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=1766

           Summary: segfault writing to a string variable...
           Product: DGCC aka GDC
           Version: 0.24
          Platform: PC
        OS/Version: Linux
            Status: NEW
          Severity: normal
          Priority: P2
         Component: glue layer
        AssignedTo: dvdfrdmn users.sf.net
        ReportedBy: funisher gmail.com


gentoo gdc 0.24, x86_64, no cflags

here is a simple test case:

void main() {
        string lala = "     ";
        lala[0] = '1';
}

however, reading is fine...

void main() {
        string lala;
        lala = "-----";
        printf("%c %d", lala[0], lala.length); // prints '- 5'
}


-- 
Jan 02 2008
→ d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=1766





------- Comment #1 from ddparnell 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';
}


-- 
Jan 02 2008
d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=1766


bugzilla digitalmars.com changed:

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




------- Comment #2 from bugzilla digitalmars.com  2008-01-02 20:57 -------
This is not a bug, string literals are read-only.


-- 
Jan 02 2008
↑ ↓ Kenny B <funisher gmail.com> writes:
d-bugmail puremagic.com wrote:
 http://d.puremagic.com/issues/show_bug.cgi?id=1766
 
 
 bugzilla digitalmars.com changed:
 
            What    |Removed                     |Added
 ----------------------------------------------------------------------------
              Status|NEW                         |RESOLVED
          Resolution|                            |INVALID
 
 
 
 
 ------- Comment #2 from bugzilla digitalmars.com  2008-01-02 20:57 -------
 This is not a bug, string literals are read-only.
 
 

Ok, I understand it's not a bug and it makes perfect sense, but why did the same exact code work as I originally expected with dmd-2.003? shouldn't that also be read-only? Is it a bug that dmd works?
Jan 03 2008
↑ ↓ → Derek Parnell <derek nomail.afraid.org> writes:
On Fri, 04 Jan 2008 00:03:13 +0100, Kenny B wrote:

 d-bugmail puremagic.com wrote:
 http://d.puremagic.com/issues/show_bug.cgi?id=1766
 
 bugzilla digitalmars.com changed:
 
            What    |Removed                     |Added
 ----------------------------------------------------------------------------
              Status|NEW                         |RESOLVED
          Resolution|                            |INVALID
 
 ------- Comment #2 from bugzilla digitalmars.com  2008-01-02 20:57 -------
 This is not a bug, string literals are read-only.
 

Ok, I understand it's not a bug and it makes perfect sense, but why did the same exact code work as I originally expected with dmd-2.003? shouldn't that also be read-only? Is it a bug that dmd works?

Yes. The Linux compiler places literals in read-only memory but the Windows one doesn't. This is sort of fixed in D v2. -- Derek (skype: derek.j.parnell) Melbourne, Australia 4/01/2008 2:25:46 PM
Jan 03 2008