[RFC/PoC,4/4] getdelim: Allow a return value of SSIZE_MAX

Message ID 1428928117-8643-5-git-send-email-rv@rasmusvillemoes.dk
State New, archived
Headers

Commit Message

Rasmus Villemoes April 13, 2015, 12:28 p.m. UTC
  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(-)
  

Patch

diff --git a/libio/iogetdelim.c b/libio/iogetdelim.c
index 1d20594..e201b9c 100644
--- a/libio/iogetdelim.c
+++ b/libio/iogetdelim.c
@@ -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;