1
votes

I am trying to learn C and am reading about valgrind. I have a simple C program, shown below, and when I run valgrind it complains about

Conditional jump or move depends on uninitialised value

by 0x100000F50: main (ex5.c:9)
==4338== Uninitialised value was created by a stack allocation
==4338== at 0x1001F5BF8: __vfprintf (in /usr/lib/system/libsystem_c.dylib)

#include <stdio.h>

/* This is a comment. */
int main(int argc, char *argv[])
{
    int distance = 100;

    // this is also a comment
    printf("You are %d miles away.\n", distance);

    return 0;
}

Where is the error coming from?

3

3 Answers

3
votes

It is common for some implementations of library functions, in order to be most efficient, to skirt some of the rules that valgrind will check.

Notice that the error is in __vfprintf (in /usr/lib/system/libsystem_c.dylib).

This is not always an issue. If there are no side effects (even libraries can have bugs) I would ignore it.

Valgrind often suppresses innocuous library warnings; upgrading might include this one.

2
votes

I don't see any issue in this code. It's fine. Check for the integrity of installed valgrind itself. At times, valgrind may issue warnings (false positives, as we say), from the code in liked libraries, which are not part of your code and mostly out of your control and beyond your concern.

Try checking the code with some other (updated) version of valgrind.

BTW, if you don't plan to use command-line argument, you can reduce main() to

int main(void)
{  ....
0
votes

Your code tested with valgrind 3.10 does not complain about anything. In many cases valgrind upgrade will solve the problem (via package manager or if not available then building yourself should be easy too). I built the code using gcc 4.9.4.