|
From: Nicholas N. <n.n...@gm...> - 2009-03-05 21:38:16
|
On Fri, Mar 6, 2009 at 5:45 AM, Ross Boylan <ro...@bi...> wrote: > When I run a test program with leak-check, the first error is > ==14820== Use of uninitialised value of size 4 > ==14820== at 0x40F6841: (within /usr/lib/libstdc++.so.6.0.10) > > Data_test.cc excerpt > BOOST_CHECK_EQUAL(pdi4->next(), true); > Data::TIObs p4b = pdi4->begin(); > //p4b = 2u; > Data::TIObs p4bt = 0u; > BOOST_CHECK_EQUAL(p4b, p4bt); // line 133 triggering error > > First question: why isn't it telling me where the uninitialised value is? Or is it? Because when this happens the value is in a register. It's hard for Memcheck to know which memory location it came from; indeed, the value may be the result of operations combining multiple originally-in-memory values. > My understanding is that > the first at (0x40F6841) is the instruction location, not the memory being referenced. That's correct. > It may be relevant that I invoked with > valgrind --leak-check=yes --num-callers=20 ./test1 --report_level=detailed /home/ross/peter/R/mspath/src/test/inputs > Does --num-callers disable other information? I couldn't find a switch that would enable reporting of the offending memory location. --num-callers doesn't disable anything. Upgrade to 3.4.1 and use --track-origins=yes if you want more information, as Tom suggested. One thing the message doesn't say which it could is that the likely use of the undefined value is as a pointer in a load or store. (It could also be as the shift amount in a shift operation, or one or two other obscure cases, but they're unlikely.) > Second question: why is the error reported in the equality test, and not at > Data::TIObs p4b = pdi4->begin(); > ? By uncommenting p4b = 2u I was able to suppress the error, which seems to indicate that p4b is the culprit. > Data:TIObs is type size_t. Memcheck doesn't complain about all uses of uninitialised values, only ones that it thinks are dangerous. See the manual for more: http://www.valgrind.org/docs/manual/mc-manual.html#mc-manual.uninitvals And this FAQ as a follow-up: http://www.valgrind.org/docs/manual/faq.html#faq.undeferrors And this blog post if you want a more detailed discussion: http://blog.mozilla.com/nnethercote/2009/02/27/eliminating-undefined-values-with-valgrind-the-easy-way/ And this paper if you really want all the details: http://www.valgrind.org/docs/memcheck2005.pdf Hope this helps. Nick |