【发布时间】:2022-01-05 08:38:25
【问题描述】:
我写的
while (ptr->next != NULL) {
//code here
ptr = ptr->next;
}
并且 AddressSanitizer 正在引发堆缓冲区溢出错误。
我加了
if (ptr->next != NULL) {
while (ptr->next != NULL) {
//code here
ptr = ptr->next;
}
}
希望它可能会避免读取未分配的地址,但现在 AddressSanitizer 正在使用 SEGV 终止我的程序。我不太确定如何解决这个问题,因为我是 C 编程新手,任何见解都会非常有帮助。谢谢!
【问题讨论】:
-
添加足够的代码让我们重新创建堆缓冲区溢出。
-
你检查过ptr是否不为空吗?
标签: c gcc data-structures linked-list computer-science