gpt4 book ai didi

c - Valgrind 告诉我这个简单的 C 程序中有错误并且可能存在内存泄漏

转载 作者:行者123 更新时间:2023-12-02 17:59:03 24 4
gpt4 key购买 nike

挑战是在继续下一课之前清除所有 Valgrind 错误,但我真的不知道这个程序出了什么问题。在继续之前我想知道出了什么问题。谢谢,感谢您的帮助。

#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;
}

这是 valgrind 报告:

==41714== Memcheck, a memory error detector
==41714== Copyright (C) 2002-2013, and GNU GPL'd, by Julian Seward et al.
==41714== Using Valgrind-3.11.0.SVN and LibVEX; rerun with -h for copyright info
==41714== Command: ./ex3
==41714==
==41714== Conditional jump or move depends on uninitialised value(s)
==41714== at 0x1003FBC3F: _platform_memchr$VARIANT$Haswell (in /usr/lib/system/libsystem_platform.dylib)
==41714== by 0x1001EFBB6: __sfvwrite (in /usr/lib/system/libsystem_c.dylib)
==41714== by 0x1001FA005: __vfprintf (in /usr/lib/system/libsystem_c.dylib)
==41714== by 0x10021F9CE: __v2printf (in /usr/lib/system/libsystem_c.dylib)
==41714== by 0x10021FCA0: __xvprintf (in /usr/lib/system/libsystem_c.dylib)
==41714== by 0x1001F5B91: vfprintf_l (in /usr/lib/system/libsystem_c.dylib)
==41714== by 0x1001F39F7: printf (in /usr/lib/system/libsystem_c.dylib)
==41714== by 0x100000F4D: main (ex3.c:8)
==41714==
I am 10 years old.
I am 72 inches tall.
==41714==
==41714== HEAP SUMMARY:
==41714== in use at exit: 38,816 bytes in 426 blocks
==41714== total heap usage: 507 allocs, 81 frees, 44,960 bytes allocated
==41714==
==41714== LEAK SUMMARY:
==41714== definitely lost: 0 bytes in 0 blocks
==41714== indirectly lost: 0 bytes in 0 blocks
==41714== possibly lost: 0 bytes in 0 blocks
==41714== still reachable: 4,096 bytes in 1 blocks
==41714== suppressed: 34,720 bytes in 425 blocks
==41714== Rerun with --leak-check=full to see details of leaked memory
==41714==
==41714== For counts of detected and suppressed errors, rerun with: -v
==41714== Use --track-origins=yes to see where uninitialised values come from
==41714== ERROR SUMMARY: 1 errors from 1 contexts (suppressed: 0 from 0)

最佳答案

很明显没有内存问题。您甚至从来没有 malloc 或 free 任何东西,因此此时所有内存都在您不参与的情况下进行处理。这一定是 Valgrind 的问题。如果您使用 OSX,也许可以尝试在一台装有 Linux 的机器上(如果有的话)。

关于c - Valgrind 告诉我这个简单的 C 程序中有错误并且可能存在内存泄漏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29637295/

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