I cannot understand why this simple program works fine, but when I check it with Valgrind it gives me too many errors.
#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;
}
This is what I get from 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
I give the file using program <input.txt. The file contains rows with max length = 5 and the program properly prints them
I am using Kubuntu and to compile I type:
gcc -DEVAL -std=gnu11 -g -static -o program program.c
Unfortunately I can't use different compiling options because of a school project