双链表实现中的"Conditional jump or move depends on uninitialised value"
"Conditional jump or move depends on uninitialised value" in double linked list implementation
Valgrind告诉我两个我无法解决的错误。我得到一个"有条件的跳转或移动取决于未初始化的值"错误信息在以下函数unplug_set
。是因为NULL
支票的原因吗?该函数应该从双链表中拔出一个元素。
void unplug_set(set * set_to_unplug){
set * last_set = set_to_unplug->last;
set * next_set = set_to_unplug->next;
set_to_unplug->next = NULL;
set_to_unplug->last = NULL;
148 if(last_set == NULL && next_set == NULL){ // only one element left
ordered_by_score_set[set_to_unplug->weight] = NULL;
150 }else if(last_set == NULL){ // first set
next_set->last = NULL;
ordered_by_score_set[set_to_unplug->weight] = next_set;
} else if (next_set == NULL) { // last set
last_set->next = NULL;
} else { // set in the middle
last_set->next = next_set;
next_set->last = last_set;
}
}
Valgrind命令:
valgrind --dsymutil=yes --track-origins=yes ./set_program
输出:==45085== Conditional jump or move depends on uninitialised value(s)
==45085== at 0x100001A2C: unplug_set(set*) (:148)
...
==45085== by 0x100001294: main (Main.cpp:81)
==45085== Uninitialised value was created by a heap allocation
==45085== at 0xC713: malloc (vg_replace_malloc.c:274)
==45085== by 0x63346: operator new(unsigned long) (in /usr/lib/libstdc++.6.0.9.dylib)
==45085== by 0x100001E0C: add_set(int, int, unsigned int const*, unsigned short const*, int, unsigned int const*) (:57)
==45085== by 0x10000127E: main (Main.cpp:39)
==45085==
==45085== Conditional jump or move depends on uninitialised value(s)
==45085== at 0x100001A60: unplug_set(set*) (:150)
...
==45085== by 0x100001294: main (Main.cpp:81)
==45085== Uninitialised value was created by a heap allocation
==45085== at 0xC713: malloc (vg_replace_malloc.c:274)
==45085== by 0x63346: operator new(unsigned long) (in /usr/lib/libstdc++.6.0.9.dylib)
==45085== by 0x100001E0C: add_set(int, int, unsigned int const*, unsigned short const*, int, unsigned int const*) (:57)
==45085== by 0x10000127E: main (Main.cpp:39)
set_to_unplug参数值由其构造函数使用new操作符初始化。如果构造函数中没有初始化,那么你就有了valgrind报错的原因。
我们没有足够的资料来回答你的问题。张贴如何使用此功能。以及如何初始化参数值相关文章:
- 瓦尔格林德:数学函数"Conditional jump or move depends on uninitialised value(s)"
- Usages of std::move
- 在C++中对T*类型执行std::move的意外行为
- 关于std::move的使用,是否有编译警告
- 我应该实现右值推送功能吗?我应该使用std::move吗
- 通过实例理解std::move及其目的
- 使用仅使用一次的变量调用的复制构造函数.这可能是通过调用move构造函数进行编译器优化的情况吗
- 是否可以在 C++03 中定义'move-and-swap idiom'等效项
- 返回一个带有 std::move 的对象并链接函数
- '[](std::list& list)<int>{return std::move(list)}(list)' 是否保证将 'list' 留空?
- 为什么字符串的 move() 会改变内存中底层数据的位置?
- 当 std::move 与 C 样式数组或不移动对象时会发生什么
- 为什么当我为 for(auto& it : myUnorderedMap) {... = std::move(it.second)} 时,我会得到一个 const 引用?
- 添加自定义析构函数时,Move 构造函数在派生类中消失
- 将向量从 N1 缩小到 N2 项,而不触发默认构造函数并仅使用 move 语义
- CPP 中的瓦尔格林德和记忆泄漏:"Conditional jump or move depends on uninitialised values"
- std::move a const std::vector in a lambda capture
- "std::forward"和"std::move"真的不生成代码吗?
- std::vector move 而不是交换到空 vector 并释放存储
- 双链表实现中的"Conditional jump or move depends on uninitialised value"