最近频频发生 段错误,gdb最后显示Previous frame inner to this frame (corrupt stack?)的问题.

netxuning 2008-04-15 03:23:54
gdb -c core.xxx文件查看 有如下显示:
#49 0x00000000 in ?? ()
#50 0x00001000 in ?? ()
#51 0x00000000 in ?? ()
#52 0x00001000 in ?? ()
#53 0x00000008 in ?? ()
#54 0x00000000 in ?? ()
#55 0x480381f0 in ?? ()
#56 0x00000000 in ?? ()
#57 0x480381f1 in ?? ()
#58 0x00000000 in ?? ()
#59 0x480381f1 in ?? ()
#60 0x00000000 in ?? ()
#61 0x00083be1 in ?? ()
#62 0x00000000 in ?? ()
#63 0x00737e98 in ?? ()
#64 0xbfffb384 in ?? ()
#65 0x00000001 in ?? ()
#66 0xbfffb258 in ?? ()
#67 0x0804cf21 in file2str (file=0x738780 "\001") at utils.c:129
Previous frame inner to this frame (corrupt stack?)

file2str这个函数用来将文件的内容返回为一个字符串:
char*
file2str(const char* file)
{
int fd;
int fsize; /*file size*/
struct stat sb;
char* str = NULL;

fd = open (file, O_RDONLY);
if(-1 == fd)
{
perror (""); //108行
return NULL;
}
fstat (fd, &sb);
fsize = sb.st_size;
/*获得文件大小*/

str = xnew_array (char, fsize + 1);
/*为str分配空间*/
if (!str)
{
close (fd);
return NULL;
}

if (fsize != read (fd, str, fsize))
{
xfree (str);
close (fd);
return NULL;
}
str[fsize] = '\0'; //129行
close(fd);

return str;
}

除了在129行发生段错误外,有时还会在108行perror出现问题.
...全文
4330 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
hsabrina 2008-05-07
  • 打赏
  • 举报
回复
楼住解决了吗? 我也遇到了,报错之前堆栈的外层也不对了,我调试的时候本来是外层有四层,可是突然剩下两层了,接着就是Previous frame inner to this frame (corrupt stack?)
提示,真的是越界啊?
悠悠长风 2008-04-16
  • 打赏
  • 举报
回复
虽然在这两个地方报错,但是不一定错误就在这两个地方。

有可能在调用这个函数前,就有溢出或越界的情况。

因为perror就把不应该会出错。
netxuning 2008-04-16
  • 打赏
  • 举报
回复
没人遇上过这种情况?
netxuning 2008-04-16
  • 打赏
  • 举报
回复
哦 多谢悠悠长风
出现这种情况 是不是就是溢出或越界而造成栈空间被破坏?

23,110

社区成员

发帖
与我相关
我的任务
社区描述
Linux/Unix社区 应用程序开发区
社区管理员
  • 应用程序开发区社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧