From Bugzilla Helper: User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.2.1) Gecko/20030225 Description of problem: I've tried it on RH9 and RH7.1, result was the same. I've compiled short program: #include <stdio.h> int main() { int i; char * logname="logfile0.txt"; for (i=0; i<10; i++) { printf("%s\n", logname); printf("%d\n", logname[7]); /* will work fine here */ logname[7]++; /* will fail here */ /* will also fail if I change it to something easier: logname[0]='A'; */ } return 0; } Memory fail error will showup after printing first two lines (printf()). After I change char * logname="literal expression"; to char logname[]="literal expression"; everything is fine. In my opinion, program should work properly in both cases, that would be much safer. Version-Release number of selected component (if applicable): How reproducible: Always Steps to Reproduce: 1. compile example code given above 2. run example code Actual Results: Memory fail error Expected Results: Proper program execution Additional info:
Please read ISO C (e.g. ISO C99 6.4.5 says: "The multibyte character sequence is then used to initialize an array of static storage duration and length just sufficient to contain the sequence." and later on: "If the program attempts to modify such an array, the behavior is undefined." You can use -fwritable-strings to make string literals writable in gcc, but I'd strongly suggest you instead create a char array if you intend to modify it (-fwritable-string will be likely removed in the future). char logname[] = "logfile0.txt";