From: Yousong Zhou Date: Tue, 16 Dec 2014 07:00:06 +0000 (+0800) Subject: file: fix EOF check. X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=def58eba24cc53f8761903145fef8db65e6e4760;p=oweals%2Fuci.git file: fix EOF check. Signed-off-by: Yousong Zhou --- diff --git a/file.c b/file.c index 1d2718a..3f02c11 100644 --- a/file.c +++ b/file.c @@ -48,8 +48,8 @@ __private void uci_getln(struct uci_context *ctx, int offset) pctx->buf = uci_malloc(ctx, LINEBUF); pctx->bufsz = LINEBUF; } - /* `offset' may off by one */ - if (offset >= pctx->bufsz) { + /* It takes 2 slots for fgets to read 1 char. */ + if (offset >= pctx->bufsz - 1) { pctx->bufsz *= 2; pctx->buf = uci_realloc(ctx, pctx->buf, pctx->bufsz); }