c - 为什么来自 "Learn C the hard way"的示例在 valgrind 中显示错误?

标签 c valgrind

我正在尝试学习 C 并正在阅读有关 valgrind 的信息。我有一个简单的 C 程序,如下所示,当我运行 valgrind 时它会提示

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

错误从何而来?

最佳答案

对于一些库函数的实现来说,为了最有效,绕过 valgrind 将检查的一些规则是很常见的。

注意错误在__vfprintf (in/usr/lib/system/libsystem_c.dylib)

这并不总是一个问题。如果没有副作用(即使库也可能有错误)我会忽略它。

Valgrind 经常抑制无害的库警告;升级可能包括这个。

关于c - 为什么来自 "Learn C the hard way"的示例在 valgrind 中显示错误?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31190484/

相关文章:

c - C , DOS 中的串行编程

c - 如何解决 "invalid write size of n bytes"和 "Address ___ is n bytes after a block of size n alloc' d”?

c++ - 使用 MPI 进行 Valgrind+gdb 调试,库中出现错误?

c - 具有相同名称和类型的两个变量,在两个不同的 .c 文件中,使用 gcc 编译

c - strstr 带有常规 char 数组,而不是字符串

c - C 套接字服务器中的accept() 速度慢

ubuntu - 使用 libssh 时的内存泄漏

valgrind - valgrind中可能丢失的含义是什么

linux/proc/<pid>/exe & valgrind

c - ANSI-C pow 函数和类型转换