// Program to show runtime errors #include #include int main () { int x; int *pInt; printf ("\n\nx = %d\n\n", x); printf ("\n\npInt = %d\n\n", *(pInt + 100000)); return EXIT_SUCCESS; } // -O0 is compile without optimizations which gives better line // number errors by Valgrind gcc -O0 -Wall -g uninit.c // Normal valgrind command valgrind --leak-check=yes ./a.out ... ==3286== 1 errors in context 8 of 8: ==3286== Conditional jump or move depends on uninitialised value(s) ==3286== at 0x4E7BA41: vfprintf (in /lib64/libc-2.19.so) ==3286== by 0x4E85588: printf (in /lib64/libc-2.19.so) ==3286== by 0x400558: main (uninit.c:9) // A little more information valgrind command valgrind --leak-check=yes --track-origins=yes ./a.out ... ==3295== 1 errors in context 8 of 8: ==3295== Conditional jump or move depends on uninitialised value(s) ==3295== at 0x4E7BA41: vfprintf (in /lib64/libc-2.19.so) ==3295== by 0x4E85588: printf (in /lib64/libc-2.19.so) ==3295== by 0x400558: main (uninit.c:9) ==3295== Uninitialised value was created by a stack allocation ==3295== at 0x40053D: main (uninit.c:5) // Runtime error cause by executing ./a.out ryand@linux-sqrp:~/workspace/SVNCS300REPOS/ValgrindHandleLab> ./a.out x = 0 Segmentation fault // Better runtime error detection using GDB ryand@linux-sqrp:~/workspace/SVNCS300REPOS/ValgrindHandleLab> gdb a.out GNU gdb (GDB; openSUSE Leap 42.1) 7.11.1 Copyright (C) 2016 Free Software Foundation, Inc. License GPLv3+: GNU GPL version 3 or later This is free software: you are free to change and redistribute it. There is NO WARRANTY, to the extent permitted by law. Type "show copying" and "show warranty" for details. This GDB was configured as "x86_64-suse-linux". Type "show configuration" for configuration details. For bug reporting instructions, please see: . Find the GDB manual and other documentation resources online at: . For help, type "help". Type "apropos word" to search for commands related to "word"... Reading symbols from a.out...done. (gdb) run Starting program: /home/ryand/workspace/SVNCS300REPOS/ValgrindHandleLab/a.out Missing separate debuginfos, use: zypper install glibc-debuginfo-2.19-22.1.x86_64 x = 0 Program received signal SIGSEGV, Segmentation fault. 0x0000000000400563 in main () at uninit.c:10 10 printf ("\n\npInt = %d\n\n", *(pInt + 100000)); (gdb)