|
From: <Rom...@cr...> - 2013-01-25 14:47:00
|
Hi
I have the following code (compiled with g++ 4.4.3):
3: int main()
4: {
5: char lMsg[256];
6: sprintf(lMsg, "%i%i%i%i", 1, 2, 3, 4);
7: printf("%s", lMsg);
8: return 0;
9: }
memcheck with Valgrind 3.8.1 complains about:
==28037== Conditional jump or move depends on uninitialised value(s)
==28037== at 0x41EB419: ??? (in /lib/tls/i686/cmov/libc-2.11.1.so)
==28037== by 0x41BF2BF: printf (in /lib/tls/i686/cmov/libc-2.11.1.so)
==28037== by 0x80485B6: main (test.cpp:7)
==28037== Uninitialised value was created by a stack allocation
==28037== at 0x804855A: main (test.cpp:4)
I'm fairly new to Valgrind and I can't figure out what's wrong - but it feels like I am missing something obvious :) Any ideas?
Thanks in advance
Roman
|
|
From: John R. <jr...@bi...> - 2013-01-25 15:30:09
|
> 6: sprintf(lMsg, "%i%i%i%i", 1, 2, 3, 4);
> 7: printf("%s", lMsg);
> memcheck with Valgrind 3.8.1 complains about:
>
> ==28037== Conditional jump or move depends on uninitialised value(s)
> ==28037== at 0x41EB419: ??? (in /lib/tls/i686/cmov/libc-2.11.1.so)
> ==28037== by 0x41BF2BF: printf (in /lib/tls/i686/cmov/libc-2.11.1.so)
> ==28037== by 0x80485B6: main (test.cpp:7)
> ==28037== Uninitialised value was created by a stack allocation
> ==28037== at 0x804855A: main (test.cpp:4)
>
> I'm fairly new to Valgrind and I can't figure out what's wrong - but it feels like I am missing something obvious :) Any ideas?
The suspect code is in a subroutine that is called by printf, and is inside libc-2.11.1.so.
It's probably the equivalent of strlen() applied to "1234", and which uses
word-wide operations on the terminating "\0???" where the '?' are uninit bytes.
Therefore this particular complaint is a "false positive" that you should ignore.
libc-2.11 is about three years old; 2.17 is current. The complaint above
does not arise with 2.17. Have you considered upgrading?
--
|
|
From: <Rom...@cr...> - 2013-01-25 17:35:15
|
> > 6: sprintf(lMsg, "%i%i%i%i", 1, 2, 3, 4);
> > 7: printf("%s", lMsg);
> >
> > memcheck with Valgrind 3.8.1 complains about:
> >
> > ==28037== Conditional jump or move depends on uninitialised value(s)
> > ==28037== at 0x41EB419: ??? (in /lib/tls/i686/cmov/libc-2.11.1.so)
> > ==28037== by 0x41BF2BF: printf (in /lib/tls/i686/cmov/libc-2.11.1.so)
> > ==28037== by 0x80485B6: main (test.cpp:7)
> > ==28037== Uninitialised value was created by a stack allocation
> > ==28037== at 0x804855A: main (test.cpp:4)
> The suspect code is in a subroutine that is called by printf, and is inside libc-
> 2.11.1.so.
> It's probably the equivalent of strlen() applied to "1234", and which uses
> word-wide operations on the terminating "\0???" where the '?' are uninit
> bytes.
That sounds reasonable. If the length of the resulting string is a multiple of 4 minus 1, Valgrind doesn't complain.
> libc-2.11 is about three years old; 2.17 is current. The complaint above does
> not arise with 2.17. Have you considered upgrading?
I'll consider upgrading to a newer libc...
Thanks,
Roman
|
|
From: Wiser, T. <TW...@lo...> - 2013-01-25 15:59:30
|
I don't know if it is relative to your situation, but I have seen many of these same errors when I was running memcheck on a statically-linked application. Once I changed to dynamically link all of the errors went away without any code change. > ==28037== Conditional jump or move depends on uninitialised value(s) > ==28037== at 0x41EB419: ??? (in /lib/tls/i686/cmov/libc-2.11.1.so) > ==28037== by 0x41BF2BF: printf (in /lib/tls/i686/cmov/libc-2.11.1.so) > ==28037== by 0x80485B6: main (test.cpp:7) > ==28037== Uninitialised value was created by a stack allocation > ==28037== at 0x804855A: main (test.cpp:4) |