]> sjero.net Git - wget/commitdiff
[svn] Don't abort in read_whole_lines when a line begins with \0.
authorhniksic <devnull@localhost>
Wed, 5 Dec 2001 23:58:12 +0000 (15:58 -0800)
committerhniksic <devnull@localhost>
Wed, 5 Dec 2001 23:58:12 +0000 (15:58 -0800)
Published in <sxsu1v5nrtg.fsf@florida.arsdigita.de>.

src/ChangeLog
src/utils.c

index 7bd7a4f56783cf18ac3a4dfa43ed84204309f5dd..9620ba74fc79a270a87a6a2e9d4b6f17ea541ee4 100644 (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
index 3c13e67f5a03bf2c63da7deb7dc2b27b8327837a..0130bc2d21df9311e9c32c3c7042cc527c98d736 100644 (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.  */