I'm following along in Learn C The Hard Way and I'm on Exercise 4: Introducing Valgrind. I'm on Mac OS X Yosemite, and as of this writing, there's not a stable build of Valgrind for Yosemite. I found Yosemite and Valgrind and used the directions from the top-voted answer to brew install --HEAD valgrind
. This installed Valgrind and I was able to follow along with Zed's exercise. However, when I "fixed" the app, I was still getting errors.
To double check, I went back to Exercise 3, which shouldn't have errors, but I still got errors in Valgrind. Here's the code and then the output:
ex3.c
#include <stdio.h>
int main()
{
int age = 10;
int height = 72;
printf("I am %d years old.\n", age);
printf("I am %d inches tall.\n", height);
return 0;
}
In iTerm:
ransom:learn-c-the-hard-way ben$ rm -f ex3
ransom:learn-c-the-hard-way ben$ make ex3
cc -Wall -g ex3.c -o ex3
ransom:learn-c-the-hard-way ben$ valgrind ./ex3
==8795== Memcheck, a memory error detector
==8795== Copyright (C) 2002-2013, and GNU GPL'd, by Julian Seward et al.
==8795== Using Valgrind-3.11.0.SVN and LibVEX; rerun with -h for copyright info
==8795== Command: ./ex3
==8795==
==8795== Conditional jump or move depends on uninitialised value(s)
==8795== at 0x1003FBC3F: _platform_memchr$VARIANT$Haswell (in /usr/lib/system/libsystem_platform.dylib)
==8795== by 0x1001EFB96: __sfvwrite (in /usr/lib/system/libsystem_c.dylib)
==8795== by 0x1001F9FE5: __vfprintf (in /usr/lib/system/libsystem_c.dylib)
==8795== by 0x10021F9AE: __v2printf (in /usr/lib/system/libsystem_c.dylib)
==8795== by 0x10021FC80: __xvprintf (in /usr/lib/system/libsystem_c.dylib)
==8795== by 0x1001F5B71: vfprintf_l (in /usr/lib/system/libsystem_c.dylib)
==8795== by 0x1001F39D7: printf (in /usr/lib/system/libsystem_c.dylib)
==8795== by 0x100000F2D: main (ex3.c:8)
==8795==
==8795== Conditional jump or move depends on uninitialised value(s)
==8795== at 0x1003FBC47: _platform_memchr$VARIANT$Haswell (in /usr/lib/system/libsystem_platform.dylib)
==8795== by 0x1001EFB96: __sfvwrite (in /usr/lib/system/libsystem_c.dylib)
==8795== by 0x1001F9FE5: __vfprintf (in /usr/lib/system/libsystem_c.dylib)
==8795== by 0x10021F9AE: __v2printf (in /usr/lib/system/libsystem_c.dylib)
==8795== by 0x10021FC80: __xvprintf (in /usr/lib/system/libsystem_c.dylib)
==8795== by 0x1001F5B71: vfprintf_l (in /usr/lib/system/libsystem_c.dylib)
==8795== by 0x1001F39D7: printf (in /usr/lib/system/libsystem_c.dylib)
==8795== by 0x100000F2D: main (ex3.c:8)
==8795==
I am 10 years old.
I am 72 inches tall.
==8795==
==8795== HEAP SUMMARY:
==8795== in use at exit: 38,888 bytes in 426 blocks
==8795== total heap usage: 506 allocs, 80 frees, 45,016 bytes allocated
==8795==
==8795== LEAK SUMMARY:
==8795== definitely lost: 0 bytes in 0 blocks
==8795== indirectly lost: 0 bytes in 0 blocks
==8795== possibly lost: 0 bytes in 0 blocks
==8795== still reachable: 4,096 bytes in 1 blocks
==8795== suppressed: 34,792 bytes in 425 blocks
==8795== Rerun with --leak-check=full to see details of leaked memory
==8795==
==8795== For counts of detected and suppressed errors, rerun with: -v
==8795== Use --track-origins=yes to see where uninitialised values come from
==8795== ERROR SUMMARY: 4 errors from 2 contexts (suppressed: 0 from 0)
It says I'm getting Conditional jump or move depends on uninitialized value(s)
on ex3.c:8
, but the height
variable is initialized on line 6.
My guess is that this is a problem with Valgrind on Yosemite and the error is bogus, but I'm very new to C and while I'm fairly certain the code is correct, I also don't know if there might be something I'm missing.
Is it a problem with Valgrind or my code?