Author: JK
Subject: Valgrind error in provided code
Date: Friday, 14 Feb 2020, 14:30:49
The example code for using getline fails to initialize "line". If I run the following code through valgrind: #define _GNU_SOURCE #include <stdio.h> #include <stdlib.h> int main() { size_t n = 0; char *line; while (getline (&line, &n, stdin) != -1) { fputs (line, stdout); free (line); n = 0; line = NULL; } free (line); } then valgrind prints the following message: ==3587233== Conditional jump or move depends on uninitialised value(s) ==3587233== at 0x48F61F1: getdelim (in /usr/lib/libc-2.30.so) ==3587233== by 0x1091D5: main (in /home/jk/temp/algo/hw3/a.out)PREV INDEX NEXT