1
0
mirror of https://github.com/moparisthebest/wget synced 2024-07-03 16:38:41 -04:00

[svn] Don't abort in read_whole_lines when a line begins with \0.

Published in <sxsu1v5nrtg.fsf@florida.arsdigita.de>.
This commit is contained in:
hniksic 2001-12-05 15:58:12 -08:00
parent 8a2ab60263
commit b248bfe395
2 changed files with 17 additions and 4 deletions

View File

@ -1,3 +1,7 @@
2001-12-06 Hrvoje Niksic <hniksic@arsdigita.com>
* utils.c (read_whole_line): Handle lines beginning with \0.
2001-12-05 Hrvoje Niksic <hniksic@arsdigita.com>
* recur.c (convert_all_links): Guard against duplicates in

View File

@ -955,13 +955,17 @@ suffix (const char *str)
/* Read a line from FP. The function reallocs the storage as needed
to accomodate for any length of the line. Reallocs are done
storage exponentially, doubling the storage after each overflow to
minimize the number of calls to realloc() and fgets(). The newline
exponentially, doubling the storage after each overflow to minimize
the number of calls to realloc() and fgets(). The newline
character at the end of line is retained.
After end-of-file is encountered without anything being read, NULL
is returned. NULL is also returned on error. To distinguish
between these two cases, use the stdio function ferror(). */
between these two cases, use the stdio function ferror().
A future version of this function will be rewritten to use fread()
instead of fgets(), and to return the length of the line, which
will make the function usable on files with binary content. */
char *
read_whole_line (FILE *fp)
@ -973,9 +977,14 @@ read_whole_line (FILE *fp)
while (fgets (line + length, bufsize - length, fp))
{
length += strlen (line + length);
assert (length > 0);
if (length == 0)
/* Possible for example when reading from a binary file where
a line begins with \0. */
continue;
if (line[length - 1] == '\n')
break;
/* fgets() guarantees to read the whole line, or to use up the
space we've given it. We can double the buffer
unconditionally. */