返回信息流大家有没有遇到过这样的问题?
这是一条镜像帖。来源:北邮人论坛 / cpp / #92301同步于 2016/6/27
该镜像源已超过 30 天没有更新,可能在源站已被删除。
CPP机器人发帖
linux debug 版没问题 release 版出core
ppzhoujun
2016/6/27镜像同步16 回复
订阅后,新回复会通过你的通知中心匿名送达。
9 条回复
下面的代码release版本core了
int *pos = (int*)realloc(array->pos, (max_row+1)*sizeof(int));
if (pos == NULL) return -1;
for (int i=array->row; i<max_row+1; ++i) {
pos[i] = 0;// core here
}
修改成下面的代码后release版core没了,程序正常。
int *pos = (int*)realloc(array->pos, (max_row+1)*sizeof(int));
if (pos == NULL) return -1;
for (int i=array->row; i<max_row+1; ++i) {
if (pos[i] != 0) pos[i] = 0;
}
暖神知道是什么情况吗?
【 在 nuanyangyang 的大作中提到: 】
: 遇到“未定义行为”了吧。
【 在 ppzhoujun 的大作中提到: 】
: 下面的代码release版本core了
: int *pos = (int*)realloc(array->pos, (max_row+1)*sizeof(int));
: if (pos == NULL) return -1;
: ...................
检查一下i是否会是负的?也就是array->row是否有可能是负的?
并不是, 这代码之前是没问题的,最近其他地方做了些修改之后就影响到这了,但这块没动过,不知道是哪块牵扯到这了,但这也太诡异了。 一定先要对这个新分配内存读一下才能写。。。。
【 在 nuanyangyang 的大作中提到: 】
:
: 检查一下i是否会是负的?也就是array->row是否有可能是负的?
row=0, max_row=6
row=0, max_row=1
row=0, max_row=1
显示 值 是没问题的
【 在 nuanyangyang 的大作中提到: 】
: 另外,你说的core dump,实际上的错误是segmentation fault吗?
嗯, 是segmentation fault 显示在这行 No such file or directory
【 在 ppzhoujun 的大作中提到: 】
: row=0, max_row=6
: row=0, max_row=1
: row=0, max_row=1
: ...................
话说那个no such file or directory是怎么回事?你确定是这一行出错了?
ps
err_msg("%d",i);
pos[i] = 0;
这样 core也没了。。。。。
【 在 nuanyangyang 的大作中提到: 】
: 另外,你说的core dump,实际上的错误是segmentation fault吗?