我在执行所有 C 代码后遇到段错误。它生成具有零字节内存泄漏的 rquired 输出。之后,它显示“segmentation fault”。以下是 gdb
输出。
Program received signal SIGSEGV, Segmentation fault.
0x08060f90 in _GLOBAL_OFFSET_TABLE_ ()
(gdb) bt
#0 0x08060f90 in _GLOBAL_OFFSET_TABLE_ ()
#1 0xffbecd18 in ?? ()
#2 0x15048815 in ?? ()
#3 0xcd0fbecd in ?? ()
#4 0x0610ffbe in ?? ()
#5 0xffbecd08 in ?? ()
#6 0xf7f79ff4 in ?? () from /lib/tls/libc.so.6
#7 0x00000000 in ?? ()
(gdb)
编辑
char **Connections,**Doors,**Zones;
char *s1,*s2;
char con[] = "c_";
char zon[] = "z_";
char dor[] = "d_";
for (i=0; i<nc ; i++){
s1 = con;
s2 = string_IntToString(i);
Connections[i]= string_Conc(s1,s2);
string_StringFree(s2);
}
编辑
char* string_Conc(const char* s1, const char* s2)
{
char* dst;
dst = memory_Malloc(strlen(s1) + strlen(s2) + 1);
strcpy(dst, s1);
return strcat(dst,s2);
}
最佳答案
正如评论者所指出的,这听起来像是缓冲区溢出或导致堆损坏、调用堆栈或类似事件的其他事件。
您可以尝试通过 Valgrind 运行您的代码, 它经常可以捕捉到这样的错误。
关于c - 执行全部代码后得到 "segmentation fault",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4780971/