gcc solution
Tom Warsinske
twarsins@orchard.wccnet.org
Thu May 11 10:19:00 GMT 2000
Greetings again,
I have just discovered the gcc "-fwritable-strings" compiler switch.ÃÂ
This effectively eliminated the problem which I submitted earlier.ÃÂ
My apologies.
-Tom Warsinske
++++++++++++++++++++++++++++++++++
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";
ÃÂ ÃÂ ÃÂ ÃÂ ÃÂ ÃÂ ÃÂ 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
ÃÂ ÃÂ ÃÂ ÃÂ ÃÂ ÃÂ ÃÂ return(str1);
}
$a.out
MOUSExxxx
xxxx
Segmentation Fault
ÃÂ
Cordially yours,
Tom Warsinske, DBA
Washtenaw Community College
Ann Arbor, MI
(734) 973-3654
ÃÂ
ÃÂ
More information about the Gcc-bugs
mailing list