views:

56

answers:

2

Hi,

My C application has the following two lines:

char buf[1024];
sprintf(buf, "%s/game/rabbit/habit/cmd/talkPipe", getenv("APPLICATION_PATH"));

The application sporadically crashes with SIGSEGV in the following manner:

strlen(ff2ba231, 0, ffbfe1d0, 10, 7fff24d7, 0)+0x50
sprintf(ffbfe2a4, ff2ba231, 0, 74656400, 12, ff362ef2)+0x24
RabbitTalk(ffbfea80, ffbfee50, 1, d, ffbfea12, 0)+0x21c
...

Can anyone pass a hint on where/what might be the problem?

Thanx a lot,

+2  A: 

Maybe because getenv returns NULL ?

Even if it's not the problem at hand you should check for NULL : most old style C functions don't.

siukurnin
you are correct... thank you both for the tip :))
roger
A: 

getenv() would return NULL if the environment variable not exist (not exported), this cause the SIGSEGV

J-16 SDiZ
you are correct... thank you both for the tip :))
roger