@@ -43,7 +43,7 @@ _IO_getdelim (lineptr, n, delimiter, fp)
int delimiter;
_IO_FILE *fp;
{
- _IO_ssize_t result;
+ _IO_ssize_t result = 0;
_IO_ssize_t cur_len = 0;
_IO_ssize_t len;
@@ -89,7 +89,8 @@ _IO_getdelim (lineptr, n, delimiter, fp)
t = (char *) memchr ((void *) fp->_IO_read_ptr, delimiter, len);
if (t != NULL)
len = (t - fp->_IO_read_ptr) + 1;
- if (__glibc_unlikely (len >= SSIZE_MAX - cur_len))
+ if (__glibc_unlikely (len >= SSIZE_MAX - cur_len) ||
+ __glibc_unlikely (len >= SSIZE_MAX - result))
{
__set_errno (EOVERFLOW);
result = -1;
@@ -115,12 +116,12 @@ _IO_getdelim (lineptr, n, delimiter, fp)
memcpy (*lineptr + cur_len, (void *) fp->_IO_read_ptr, len);
fp->_IO_read_ptr += len;
cur_len += len;
+ result += len;
if (t != NULL || __underflow (fp) == EOF)
break;
len = fp->_IO_read_end - fp->_IO_read_ptr;
}
(*lineptr)[cur_len] = '\0';
- result = cur_len;
unlock_return:
_IO_release_lock (fp);
In preparation for introducing getdelim_append (which will essentially change cur_len from a local variable to an input/output parameter), compute result separately from cur_len. Signed-off-by: Rasmus Villemoes <rv@rasmusvillemoes.dk> --- libio/iogetdelim.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)