X-Git-Url: http://erislabs.net/gitweb/?a=blobdiff_plain;ds=inline;f=lib%2Fgetstr.c;h=6e748a48a206437758db1743cd0a584b6315301f;hb=579b8ed5d608f9746b42e48bfc954823d27af8f6;hp=98c4ac86556d6448c727d942dac6b3a864ced3f0;hpb=92f1833affa37844e22d2ebe4ca4c6ba924377f4;p=gnulib.git diff --git a/lib/getstr.c b/lib/getstr.c index 98c4ac865..6e748a48a 100644 --- a/lib/getstr.c +++ b/lib/getstr.c @@ -25,8 +25,6 @@ #include #include -#include - #if STDC_HEADERS # include #else @@ -49,7 +47,7 @@ int getstr (char **lineptr, size_t *n, FILE *stream, int delim1, int delim2, size_t offset) { - int nchars_avail; /* Allocated but unused chars in *LINEPTR. */ + size_t nchars_avail; /* Allocated but unused chars in *LINEPTR. */ char *read_pos; /* Where we're reading into *LINEPTR. */ int ret; @@ -64,6 +62,9 @@ getstr (char **lineptr, size_t *n, FILE *stream, int delim1, int delim2, return -1; } + if (*n < offset) + return -1; + nchars_avail = *n - offset; read_pos = *lineptr + offset; @@ -75,7 +76,6 @@ getstr (char **lineptr, size_t *n, FILE *stream, int delim1, int delim2, always (unless we get an error while reading the first char) NUL-terminate the line buffer. */ - assert(*n - nchars_avail == read_pos - *lineptr); if (nchars_avail < 2) { if (*n > MIN_CHUNK) @@ -88,7 +88,6 @@ getstr (char **lineptr, size_t *n, FILE *stream, int delim1, int delim2, if (!*lineptr) return -1; read_pos = *n - nchars_avail + *lineptr; - assert(*n - nchars_avail == read_pos - *lineptr); } if (c == EOF || ferror (stream))