gpt4 book ai didi

c - OS X Yosemite 上的 Valgrind,给出虚假错误?

转载 作者:太空狗 更新时间:2023-10-29 15:50:22 25 4
gpt4 key购买 nike

<分区>

我正在关注 Learn C The Hard Way我在 Exercise 4: Introducing Valgrind .我在 Mac OS X Yosemite 上,在撰写本文时,还没有用于 Yosemite 的稳定版本的 Valgrind。我找到了 Yosemite and Valgrind并使用了 brew install --HEAD valgrind 的最高投票答案中的说明。这安装了 Valgrind,我能够跟随 Zed 的练习。但是,当我“修复”该应用程序时,我仍然遇到错误。

为了仔细检查,我回到了 Exercise 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;
}

在 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)

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

我的猜测是 Yosemite 上的 Valgrind 的问题,错误是伪造的,但我是 C 的新手,虽然我相当确定代码是正确的,但我也不知道我是否遗漏了什么。

是 Valgrind 还是我的代码有问题?

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com