Daniel Stenberg <[EMAIL PROTECTED]> writes:
> On Mon, 24 Sep 2001, Lenny Foner wrote:
>
>> utils.c:906: failed assertion `length > 0'
>
> This is the key issue here.
>
> The "file" read by wget (which happens to be a directory in this
> case) returns a zero length line and the assert() line warns about
> this and then aborts.
[...]
> I would fix that assert() to be a better check (...)
A good suggestion; I've now done that. But instead of returning NULL
like your patch does, my version simply skips such an "invalid" line.
In a later release, I'll rewrite the function to report the length of
the line to the callers that are interested, so it will be usable with
binary data.
2001-12-06 Hrvoje Niksic <[EMAIL PROTECTED]>
* utils.c (read_whole_line): Handle lines beginning with \0.
Index: src/utils.c
===================================================================
RCS file: /pack/anoncvs/wget/src/utils.c,v
retrieving revision 1.33
diff -u -r1.33 utils.c
--- src/utils.c 2001/12/04 23:42:18 1.33
+++ src/utils.c 2001/12/05 23:53:26
@@ -955,14 +955,18 @@
/* 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 @@
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. */