Valgrind为什么说条件跳转或移动取决于静态数组的未初始化值?

问题描述

我不明白为什么这个简单的程序可以正常工作,但是当我用Valgrind检查它时,给了我太多错误。

#include<stdio.h>

int main()
{
    char input[10]  = {'a','b','c','d','e','f','g','\0'};
    while (fgets(input,9,stdin))
    {
        printf("\nComplete line: %s\n",input);
    }
    return 0;
}

这是我从valgrind得到的

14 times this one (with different addresses)
==2079== Conditional jump or move depends on uninitialised value(s)
==2079==    at 0x425DF0: malloc_hook_ini (in /home/utente/Desktop/program)
==2079==    by 0x48204A: _dl_get_origin (in /home/utente/Desktop/program)
==2079==    by 0x455844: _dl_non_dynamic_init (in /home/utente/Desktop/program)
==2079==    by 0x457485: __libc_init_first (in /home/utente/Desktop/program)
==2079==    by 0x402538: (below main) (in /home/utente/Desktop/program)

==2079== Conditional jump or move depends on uninitialised value(s)
==2079==    at 0x410428: __cxa_atexit (in /home/utente/Desktop/program)
==2079==    by 0x402549: (below main) (in /home/utente/Desktop/program)

**This should be useful**
==2079== Conditional jump or move depends on uninitialised value(s)
==2079==    at 0x4185C8: fgets (in /home/utente/Desktop/program)
==2079==    by 0x401D95: main (program.c:6)

==2079== Conditional jump or move depends on uninitialised value(s)
==2079==    at 0x4263BD: malloc (in /home/utente/Desktop/program)
==2079==    by 0x4738F3: _IO_file_doallocate (in /home/utente/Desktop/program)
==2079==    by 0x41ECBF: _IO_doallocbuf (in /home/utente/Desktop/program)
==2079==    by 0x41B5AB: _IO_file_underflow (in /home/utente/Desktop/program)
==2079==    by 0x41ED75: _IO_default_uflow (in /home/utente/Desktop/program)
==2079==    by 0x4189FB: _IO_getline_info (in /home/utente/Desktop/program)
==2079==    by 0x418609: fgets (in /home/utente/Desktop/program)
==2079==    by 0x401D95: main (api.c:6)
and many others similar to the latter

我使用程序

我正在使用Kubuntu并进行编译:

gcc -DEVAL -std=gnu11 -g -static -o program program.c

不幸的是,由于学校项目,我不能使用其他编译选项

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

依赖报错 idea导入项目后依赖报错,解决方案:https://blog....
错误1:代码生成器依赖和mybatis依赖冲突 启动项目时报错如下...
错误1:gradle项目控制台输出为乱码 # 解决方案:https://bl...
错误还原:在查询的过程中,传入的workType为0时,该条件不起...
报错如下,gcc版本太低 ^ server.c:5346:31: 错误:‘struct...