gcc runtime error in version 2.8.1 and 2.9.5
llewelly@dbritsch.dsl.xmission.com
llewelly@dbritsch.dsl.xmission.com
Thu May 11 11:57:00 GMT 2000
This is a bug in your code, not a bug in gcc.
On Thu, 11 May 2000, Tom Warsinske wrote:
> Greetings,
>
> The following test code produces a Segmentation Fault when compiled with
> gcc 2.8.1 on Solaris 2.5.1 and with gcc 2.9.5 on Solaris 2.7. The
> program executes correctly when compiled with Sun's cc: WorkShop
> Compilers 4.2 30 Oct 1996 C 4.2 on Solaris 2.5.1. Here is the test
> program --
> ++++++++++++++++++++++++
> #include <stdio.h>
> #include <strings.h>
>
> char *rtrim(char *, char );
>
> int main() {
> char *lname = "MOUSExxxx";
String literals are of type char const*const, meaning one is not allowed
to change the characters in the string.
> char *fname = "MICKEY ";
>
> lname = rtrim(lname,'x');
> printf("%s \n",lname);
> }
> char *rtrim(char *str1, char c) {
> char *s;
>
> printf("%s \n",str1);
> s = index(str1, c);
> printf("%s \n",s);
> *s = '\0'; <= causes segmentation fault
Modifying a string literal is undefined.
> return(str1);
> }
>
If you really need to do this, look up the switch -fwritable-strings at
http://gcc.gnu.org/onlinedocs/gcc_2.html#SEC6 .
Thank you for your bug report.
[snip]
More information about the Gcc-bugs
mailing list