Valgrind errors in c libraries?

Valgrind shows an uninitialized error value of size 8. And sometimes, below is a conditional jump on an uninitialized error value.

All I do is print a formatted string using the stdC ++ library that comes with gcc and the built-in vsnprintf.

This is inside a method called a format that is part of a custom string class. Now what? everything looks right. The error seems to be inside _itoa.c. But all that I can think of is external, does not use this function, which is not very possible!

==4229== Memcheck, a memory error detector ==4229== Copyright (C) 2002-2009, and GNU GPL'd, by Julian Seward et al. ==4229== Using Valgrind-3.6.0.SVN-Debian and LibVEX; rerun with -h for copyright info ==4229== Command: ./test ==4229== ==4229== Use of uninitialised value of size 8 ==4229== at 0x54A3DF1: _itoa_word (_itoa.c:196) ==4229== by 0x54A5138: vfprintf (vfprintf.c:1613) ==4229== by 0x555C74F: __vsnprintf_chk (vsnprintf_chk.c:65) ==4229== by 0x407E57: myString::format(char const*, ...) (stdio2.h:79) ==4229== by 0x419D14: ID::toString() (id.cpp:151) ==4229== by 0x41D03D: main (test.cpp:126) ==4229== ==4229== Conditional jump or move depends on uninitialised value(s) ==4229== at 0x54A3DF8: _itoa_word (_itoa.c:196) ==4229== by 0x54A5138: vfprintf (vfprintf.c:1613) ==4229== by 0x555C74F: __vsnprintf_chk (vsnprintf_chk.c:65) ==4229== by 0x407E57: myString::format(char const*, ...) (stdio2.h:79) ==4229== by 0x419D14: ID::toString() (uuid.cpp:151) ==4229== by 0x41D03D: main (test.cpp:126) ==4229== ==4229== ==4229== HEAP SUMMARY: ==4229== in use at exit: 0 bytes in 0 blocks ==4229== total heap usage: 6 allocs, 6 frees, 1,340 bytes allocated ==4229== ==4229== All heap blocks were freed -- no leaks are possible ==4229== ==4229== For counts of detected and suppressed errors, rerun with: -v ==4229== Use --track-origins=yes to see where uninitialised values come from ==4229== ERROR SUMMARY: 3 errors from 2 contexts (suppressed: 4 from 4) 
+6
gcc valgrind
source share
2 answers

This is the place in the C library where it actually looks at your number to format it as a string, and indicates that the number you are formatting was obtained from uninitialized storage.

Add the option valgrind --track-origins=yes for more information on the origin of the uninitialized value.

Because it is the usual copy around uninitialized memory, for example. filling in structures, tracking copies of uninitialized values ​​and does not file complaints until the moment when the value is really used in a way that can affect the appearance of your program. This can confuse the definition of the original source of an uninitialized value, as it may have been copied several times before anything was done to it. The option --track-origins=yes monitors additional information to determine the source of the uninitialized value so that it can be displayed when an uninitialized value is used.

+5
source share

If he says that he is in one of the standard libraries, it means that something you are going through is not configured correctly. So, to debug, go to the first line in the hierarchy, which is your code ... like this: ID :: toString () (id.cpp: 151).

Look what is returning there, and you will find your culprit.

+1
source share

All Articles