linux - gcc 编译器 NULL 分配不分配 NULL
问题描述
我正在调试别人的库(AGAR),我遇到了这样一种情况,即在紧接着的代码行上,指针被分配了一个 NULL 值,它不是 NULL。
非 NULL 值导致段错误!
我在代码中看不到问题。
int AG_EventLoop(void)
{
AG_EventSource *src = AG_GetEventSource();
AG_EventSink *es;
...
for((es) = ((&src->epilogues)->tqh_first); (es) != NULL; (es) = ((es)->sinks.tqe_next)) {
es->fn(es, &es->fnArgs); // seg fault here should not have entered
}
...
}
在 for 循环中,es 被分配了队列中的第一项:
(es) = ((&src->epilogues)->tqh_first);
调试器显示值:
src->epilogues: 0x1bbd28
tqh_first: 0x0
tqh_last: 0x1bbd28
es: 0xfeeefeeefeeefeee
如果 tqh_first 为 0x0 (NULL),es 的值 0xfeeefeeefeeefeee 来自哪里?
该代码仅在 MINGW64 中失败,并且在 Linux 中按预期工作。
解决方案
推荐阅读
- permissions - Avada Wordpress 主题 - 无法访问品牌设置
- c# - 如何通过创建一个空行来结束一个序列?
- applescript - 使用 AppleScript 将 finder 中的副本替换为脚本
- android - 使用 SpeechRecognizer API 对 editText 的语音输入进行 Espresso 测试
- python - 海王星插入数据很慢
- c# - 使用 getter 类在 C# 中解析嵌套的 JSON [Array]
- java - Java 对象引用数组初始化
- kubernetes - 为角色绑定修补命名空间和更改资源类型
- eclipse - Liferay 为多个 portlet 创建自定义 PanelCategory
- highcharts - Highcharts MapBubble - 是否可以使用数据模块加载数据?