From f93d57195dfa072ca6fea0c76428fde5337bcabc Mon Sep 17 00:00:00 2001 From: Jonathan McDowell Date: Sun, 24 Apr 2011 18:33:13 -0700 Subject: [PATCH] Fix buffer_getchar to only error if we'd exceed the buffer size We were erroring when we retrieved the end of the buffer, and not if we overflowed past the end. Check if we'd overflow and return an error only in that case. --- charfuncs.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/charfuncs.c b/charfuncs.c index fea0a99..8448aee 100644 --- a/charfuncs.c +++ b/charfuncs.c @@ -25,11 +25,15 @@ int buffer_fetchchar(void *ctx, size_t count, void *c) struct buffer_ctx *buf = NULL; buf = (struct buffer_ctx *) ctx; + + if (buf->offset + count > buf->size) { + return 1; + } memcpy(c, &buf->buffer[buf->offset], count); buf->offset += count; - return (((buf->offset) == (buf->size)) ? 1 : 0); + return 0; } /** -- 2.39.5