Author: Stan Eisenstat
Subject: Re: [Cs223] Valgrind error in provided code
Date: Friday, 14 Feb 2020, 16:08:30
> Message Posted By: JK
>
> 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)
Thanks for pointing out that the declaration
char *line;
above should have been
char *line = NULL;
I have updated the on-line version of the specification
to reflect this change.
--Stan-
PREV
INDEX
NEXT