Red Hat Bugzilla – Bug 105655
segmentation fault on evaluating expr. --*(ptr--)
Last modified: 2007-04-18 12:57:51 EDT
From Bugzilla Helper:
User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.0.1) Gecko/20020830
Description of problem:
When I compiled following program and executed it gives "segmentation fault" error
char *ptr = "abcdefg";
Version-Release number of selected component (if applicable):
And you expected something else?
See ISO C99, 6.4.5 on string literals:
... "If the program attempts to modify such an array, the behavior is undefined." ...
String literals in gcc are in read-only sections if the target supports it.
You can use -fwritable-strings to make them writable (which also means non-shareable).