开发者

C: sprintf leads to SIGSEGV core via an strlen

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,


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.


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜