The result you provided in your question contains the following line:
==5190== Use --track-origins=yes to see where uninitialised values come from
For this message, you should run ./ex4 as follows:
valgrind --track-origins=yes ./ex4
To avoid some problems so that Valgrind cannot find debugging information, you can use static binding:
gcc -static -g -o ex4 ex4.c
Valgrind output will contain messages of type Uninitialised value was created by a stack allocation :
==17673== Memcheck, a memory error detector ==17673== Copyright (C) 2002-2011, and GNU GPL'd, by Julian Seward et al. ==17673== Using Valgrind-3.7.0 and LibVEX; rerun with -h for copyright info ==17673== Command: ./ex4 ... ==17673== Use of uninitialised value of size 4 ==17673== at 0x805CA7B: _itoa_word (in /home/user/ex4) ==17673== by 0x8049D5F: printf (in /home/user/ex4) ==17673== by 0x8048ECD: main (ex4.c:8) ==17673== Uninitialised value was created by a stack allocation ==17673== at 0x8048EFA: bad_function (ex4.c:17) ... ==17673== Use of uninitialised value of size 4 ==17673== at 0x805CA7B: _itoa_word (in /home/user/ex4) ==17673== by 0x8049D5F: printf (in /home/user/ex4) ==17673== by 0x80490BE: (below main) (in /home/user/ex4) ==17673== Uninitialised value was created by a stack allocation ==17673== at 0x8048EBE: main (ex4.c:4) ... I am -1094375076 years old. ... I am -1094369310 inches tall. ... ==17673== ==17673== HEAP SUMMARY: ==17673== in use at exit: 0 bytes in 0 blocks ==17673== total heap usage: 0 allocs, 0 frees, 0 bytes allocated ==17673== ==17673== All heap blocks were freed
ex4.c file:
1 #include <stdio.h> 2 3 int main() 4 { 5 int age = 10; 6 int height; 7 8 bad_function(); 9 10 printf("I am %d years old.\n"); 11 printf("I am %d inches tall.\n", height); 12 13 return 0; 14 } 15 16 int bad_function() 17 { 18 int x; 19 printf("%d\n", x); 20 }
Valgrind's output is not perfect. It identifies the frame (function) of the stack containing the uninitialized variable, but does not print the variable name.
Running Linux under VirtualBox does not affect Valgrind.
user811773 Mar 05 2018-12-12T00: 00Z
source share