This is the mail archive of the
libc-alpha@sourceware.org
mailing list for the glibc project.
[RFC/PoC 4/4] getdelim: Allow a return value of SSIZE_MAX
- From: Rasmus Villemoes <rv at rasmusvillemoes dot dk>
- To: libc-alpha at sourceware dot org
- Cc: Jeff King <peff at peff dot net>, Rasmus Villemoes <rv at rasmusvillemoes dot dk>
- Date: Mon, 13 Apr 2015 14:28:37 +0200
- Subject: [RFC/PoC 4/4] getdelim: Allow a return value of SSIZE_MAX
- Authentication-results: sourceware.org; auth=none
- References: <1428928117-8643-1-git-send-email-rv at rasmusvillemoes dot dk>
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