This is the mail archive of the libc-alpha@sourceware.org mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

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


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(-)

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;
-- 
2.1.3


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]