OS X Yosemite上的Valgrind,出现虚假错误?

Ben*_*ack 3 c macos valgrind

我正在学习C艰难的方式,我正在练习4:介绍Valgrind.我在Mac OS X Yosemite上,在撰写本文时,没有稳定的Valgrind for Yosemite版本.我找到了Yosemite和Valgrind,并使用了最高投票答案的指示brew install --HEAD valgrind.这个安装了Valgrind和我能够跟随Zed的练习.但是,当我"修复"应用程序时,我仍然遇到错误.

为了仔细检查,我回到练习3,这应该没有错误,但我仍然在Valgrind中出错.这是代码,然后是输出:

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;
}
Run Code Online (Sandbox Code Playgroud)

在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)
Run Code Online (Sandbox Code Playgroud)

它说我正在Conditional jump or move depends on uninitialized value(s)ex3.c:8,但height变量在第6行初始化.

我的猜测是这是Valgrind在优胜美地的一个问题而且错误是假的,但我对C很新,虽然我很确定代码是正确的,但我也不知道是否有什么东西我我失踪了.

这是Valgrind或我的代码的问题吗?

Rhy*_*idd 8

这份具体的报告对Valgrind来说是误报.Yosemite上的Valgrind还没有完全覆盖系统库中的所有极端情况以及这些库使用的优化.

这里的提示是函数名称_platform_memchr $ VARIANT $ Haswell,即此错误的存在将取决于您的系统硬件,在这种情况下,您是否拥有基于Intel Haswell的CPU.

如果您可以根据Valgrind的http://valgrind.org/support/bug_reports.html报告此错误,那么可以在下一个稳定的Valgrind版本之前修复它.

完全披露:我是Valgrind开发人员之一,他们提供了补丁以支持OS X 10.10