解释 gdb 输出
我的程序中出现段错误,并尝试通过 gdb 检测源。
gdb 的 O/p 如下:
[Switching to Thread 0xb6dffb70 (LWP 6448)]
#0 0x00adc026 in __strlen_sse2_bsf () from /lib/libc.so/6
#1 0x08049e77 in sim_txn (fd=0x804c5c0) at rand_trace0.c:390
在 rand_trace0.c:390
处,我有一行“
system_call_length = strlen("rename(")+strlen(filename1)+strlen(",")+strlen(filename)+strlen(")")+1;
一切似乎都在它之前工作”。 我不知所措。
I get a segfault in my program and was trying to detect the source via gdb.
O/p of the gdb is as follows:
[Switching to Thread 0xb6dffb70 (LWP 6448)]
#0 0x00adc026 in __strlen_sse2_bsf () from /lib/libc.so/6
#1 0x08049e77 in sim_txn (fd=0x804c5c0) at rand_trace0.c:390
and at rand_trace0.c:390
I have the line
system_call_length = strlen("rename(")+strlen(filename1)+strlen(",")+strlen(filename)+strlen(")")+1;
Everything seems to be working before it.
I am at a loss.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
filename1
和filename
都是指向空终止字符串的有效指针吗?出现段错误的最常见原因是指针未正确初始化,或者其中一个字符串不是以 null 结尾(可能是由于缓冲区溢出),从而导致 strlen( ) 尝试读取已分配内存的大小。Are
filename1
andfilename
both valid pointers to null-terminated strings? The most common reason you might get a segfault with that is if your pointer wasn't properly initialized or if one of the strings isn't null-terminated (possibly because of a buffer overflow) and thus is resulting instrlen()
trying to read past the size of the allocated memory.