summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLaurent Bercot <ska-skaware@skarnet.org>2024-01-30 02:22:27 +0000
committerLaurent Bercot <ska@appnovation.com>2024-01-30 02:22:27 +0000
commitbeed5320348ffe615e974684d166c17992c98144 (patch)
tree8e6d4965a99184c7c0131bd78044db9325d75fc8
parent83bcd1e5ed5eb5c4abc5154dae4dc6e133c8ddb4 (diff)
downloadskalibs-beed5320348ffe615e974684d166c17992c98144.tar.xz
bugfix: getlnmax must return 1 when the line just fits the out buffer
Signed-off-by: Laurent Bercot <ska@appnovation.com>
-rw-r--r--src/libstddjb/getlnmax.c7
1 files changed, 4 insertions, 3 deletions
diff --git a/src/libstddjb/getlnmax.c b/src/libstddjb/getlnmax.c
index a9e6146..700fd0d 100644
--- a/src/libstddjb/getlnmax.c
+++ b/src/libstddjb/getlnmax.c
@@ -2,17 +2,18 @@
#include <sys/uio.h>
#include <errno.h>
+
#include <skalibs/buffer.h>
#include <skalibs/siovec.h>
#include <skalibs/skamisc.h>
int getlnmax (buffer *b, char *d, size_t max, size_t *w, char sep)
{
- if (max < *w) return (errno = EINVAL, -1) ;
+ if (*w > max) return (errno = EINVAL, -1) ;
for (;;)
{
- struct iovec v[2] ;
size_t len = buffer_len(b) ;
+ struct iovec v[2] ;
size_t pos ;
ssize_t r ;
buffer_rpeek(b, v) ;
@@ -21,8 +22,8 @@ int getlnmax (buffer *b, char *d, size_t max, size_t *w, char sep)
if (pos > len) pos = len ;
r = pos < len ; pos += r ;
buffer_getnofill(b, d + *w, pos) ; *w += pos ;
- if (*w >= max) return (errno = ERANGE, -1) ;
if (r) return 1 ;
+ if (*w >= max) return (errno = ERANGE, -1) ;
r = buffer_fill(b) ;
if (r <= 0) return r ;
}