gpt4 book ai didi

c - Valgrind 无效读取

转载 作者:太空宇宙 更新时间:2023-11-04 00:08:59 25 4
gpt4 key购买 nike

我在 valgrind 中遇到了几个错误,这些错误指的是我的代码的一部分。基本上我有一个充当队列的结构链表。这是我的排队功能:

PcbPtr enqPcb(PcbPtr *headofQ, PcbPtr process){
PcbPtr c = *headofQ;
PcbPtr d = c;
if (!*headofQ) {
*headofQ = process;
return *headofQ;
}
while (c->next) {
c = c->next;
}
c->next = process;
return d;
}

PcbPtr 是指向结构的指针。 Valgrind 在 while 循环中给我各种各样的东西“条件跳跃或移动取决于未初始化的值”等。这有什么明显的错误,或者超出了我所包含的范围吗?谢谢

最佳答案

您可能会考虑初始化 process 所指的next 成员(如果在调用 enqPcb() 之前尚未完成):

PcbPtr enqPcb(PcbPtr *headofQ, PcbPtr process){
PcbPtr c = *headofQ;
PcbPtr d = c;
process->next = NULL;

...

关于c - Valgrind 无效读取,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10929069/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com