Thread overview | |||||||
---|---|---|---|---|---|---|---|
|
January 02, 2008 [Issue 1766] New: segfault writing to a string variable... | ||||
---|---|---|---|---|
| ||||
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' } -- |
January 03, 2008 [Issue 1766] segfault writing to a string variable... | ||||
---|---|---|---|---|
| ||||
Posted in reply to d-bugmail | 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'; } -- |
January 03, 2008 [Issue 1766] segfault writing to a string variable... | ||||
---|---|---|---|---|
| ||||
Posted in reply to d-bugmail | 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. -- |
January 03, 2008 Re: [Issue 1766] segfault writing to a string variable... | ||||
---|---|---|---|---|
| ||||
Posted in reply to d-bugmail | 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?
|
January 04, 2008 Re: [Issue 1766] segfault writing to a string variable... | ||||
---|---|---|---|---|
| ||||
Posted in reply to Kenny B | 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 |
Copyright © 1999-2021 by the D Language Foundation