I'm porting some C code from SCO over to SuSE Linux. GCC is throwing me a segmentation fault when I run the code..
(Calling function)
myfunc("\n");
.
.
int myfunc(st)
char *st;
{
int org_len;
org_len = strlen(st);
if( st[org_len-1] == '\n' )
{
/* note: org_len is 1 */
st[org_len - 1] = '\0'; /* segmentation fault */
}
.
.
}
Apparently gcc is more picky than the old SCO compiler. Is it that I'm passing in a string to myfunc instead of a variable that has allocated memory?
Thanks,
Bob
(Calling function)
myfunc("\n");
.
.
int myfunc(st)
char *st;
{
int org_len;
org_len = strlen(st);
if( st[org_len-1] == '\n' )
{
/* note: org_len is 1 */
st[org_len - 1] = '\0'; /* segmentation fault */
}
.
.
}
Apparently gcc is more picky than the old SCO compiler. Is it that I'm passing in a string to myfunc instead of a variable that has allocated memory?
Thanks,
Bob