Brian Wainscott <[EMAIL PROTECTED]> writes:
> #include <stdio.h>
> main()
> {
>    int i,j;
> 
>    for(i=j=0; i< 5; i++) {
>      j=do_sub(j);
>    }
> 
>    printf("Result = %d\n",j);
> }
> int do_sub(int in)
> {
>    int out;
> //int junk=1;    /* No errors */
>    int junk;      /* Errors */
> 
>    out = in+junk;
>    return out;
> }
> 
> has an obvious error ("junk" is not initialized).  When I build this on my 
> OpenSuSE 11.0 x86_64 system with the gcc 4.3.1 compiler, I either get no 
> valgrind errors (if junk=1 is used), or I get this (when junk is not 
> initialized):
> 
> ==22349== Use of uninitialised value of size 8
> ==22349==    at 0x4E6E423: (within /lib64/libc-2.8.so)
> ==22349==    by 0x4E7166F: vfprintf (in /lib64/libc-2.8.so)
> ==22349==    by 0x4E78FE9: printf (in /lib64/libc-2.8.so)
> ==22349==    by 0x40055E: main (in /home/brian/tmp/tst)
> 
> Now, this "error" is in the system libraries, and I don't KNOW that the 
> error report is wrong.  But I don't get ANY errors about the usage of junk, 
> or anything else.

Errors are not reported until they are `visible'.  The
uninitialized-ness of junk propagates to do_sub:out, and then main:j,
but it is only upon the observed access in the printf that the
uninitialized nature of main:j is visible.

See:

   http://www.valgrind.org/docs/manual/mc-manual.html#mc-manual.value

HTH,

-tom

-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
_______________________________________________
Valgrind-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/valgrind-users

Reply via email to