Is there anyway a valgrind message “Conditional jump or move depends on uninitialized value” can be a so called 'false positive'

给你一囗甜甜゛ 提交于 2019-12-05 02:40:38

What valgrind is reporting is that it sees a jump based on a read from a location for which it knows that it was allocated by the program but for which it hasn't seen an initialization. This might happen if the object is initialized by some magic that valgrind doesn't know about. Architectures evolve constantly and maybe you have an instruction or register type that valgrind doesn't know enough about.

Another difficult source of such non-initializations are unions. Two sources:

  • Per default, for these only the first member is initialized and so when another field goes beyond that first member that part might be uninitialized.
  • If the members of the union are struct they may have padding bytes at different places, and so part of a member may be uninitialized if you assigned to a different member.

In some cases it might be legitimate to even read these things (through a unsigned char[] for example) so if you consider such things as a bug (false positive) or not is a matter of perspective.

Absolutely! I once had C code of the form

// compute a and, possibly, b
if (a && b) {
    // do stuff
}

in which b was guaranteed to be initialized if a were true. Thus, there was no way that an uninitialized value of b could cause a problem. However, gcc, when optimizing sufficiently aggressively, decided to check the value of b first. This was acceptable since neither check had any side effects, but it still caused valgrind to complain.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!