0

我一直在使用 valgrind 来调试我的程序(程序运行良好,只是在完善它)并且它返回了一个无效指针警告我很难修复,所以我只是想知道是否有人可以指出我正确的方向? 将发布 valgrind 给我的错误以及 valgrind 指向的行(以及它之前的一些行),谢谢!

==9437== Invalid read of size 1
==9437==    at 0x4C25812: __GI_strlen (mc_replace_strmem.c:284)
==9437==    by 0x400F67: main (exec_deathinfo_c.c:95)
==9437==  Address 0x0 is not stack'd, malloc'd or (recently) free'd


char *name;
char *filename;
name = getenv("MCEXEC_PLAYERNAME");
filename = malloc(sizeof "/home/minecraft/freedonia/playerdata/deathlog-.txt" - 1 + strlen(name)  + 1);
4

1 回答 1

4
==9437== Invalid read of size 1
==9437==    at 0x4C25812: __GI_strlen (mc_replace_strmem.c:284)
==9437==    by 0x400F67: main (exec_deathinfo_c.c:95)
Address 0x0 is not stack'd, malloc'd or (recently) free'd

表明

name = getenv("MCEXEC_PLAYERNAME");

返回NULL

于 2012-05-20T02:10:34.160 回答