readline bug
Matt Kraai <[email protected]>
| Newsgroups | gmane.mail.ifile.general |
|---|---|
| Message-ID | <20020829164951.GD3088@catalonia> |
Howdy,
util.c:readline does not work correctly if the string it is
passed is not NUL-terminated and fgets encounters an error or an
EOF before reading any characters. The appended patch fixes
this problem.
Matt
--- ifile-1.0.8/util.c 2002-08-29 05:36:36.000000000 -0700
+++ ifile/util.c 2002-08-29 09:43:03.000000000 -0700
@@ -169,10 +169,14 @@
{
long int last;
- fgets(string, max_len, stream);
- last = strlen(string)-1;
- if (string[last] == '\n')
- string[last] = '\0';
+ if (fgets(string, max_len, stream) != NULL)
+ {
+ last = strlen(string)-1;
+ if (string[last] == '\n')
+ string[last] = '\0';
+ }
+ else
+ string[0] = '\0';
return string;
}