[RFC/PoC,4/4] getdelim: Allow a return value of SSIZE_MAX
Commit Message
The current getdelim function fails with EOVERFLOW if the delimiter is
found after exactly SSIZE_MAX characters, but clearly we should
succeed and return SSIZE_MAX in that case.
We keep >= in the len >= SIZE_MAX - *cur_len comparison, since needed
is computed as *cur_len + len + 1.
Note that the POSIX 2008 wording for EOVERFLOW ("More than {SSIZE_MAX}
characters were read without encountering the delimiter character.")
is slightly flawed; it is fixed by
<http://austingroupbugs.net/view.php?id=570>.
Signed-off-by: Rasmus Villemoes <rv@rasmusvillemoes.dk>
---
libio/iogetdelim.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
@@ -90,7 +90,7 @@ _IO_getdelim_append (lineptr, n, delimiter, fp, cur_len)
if (t != NULL)
len = (t - fp->_IO_read_ptr) + 1;
if (__glibc_unlikely (len >= SIZE_MAX - *cur_len) ||
- __glibc_unlikely (len >= SSIZE_MAX - result))
+ __glibc_unlikely (len > SSIZE_MAX - result))
{
__set_errno (EOVERFLOW);
result = -1;