file: fix EOF check.
authorYousong Zhou <yszhou4tech@gmail.com>
Tue, 16 Dec 2014 07:00:06 +0000 (15:00 +0800)
committerFelix Fietkau <nbd@openwrt.org>
Thu, 18 Dec 2014 11:38:15 +0000 (12:38 +0100)
Signed-off-by: Yousong Zhou <yszhou4tech@gmail.com>
file.c

diff --git a/file.c b/file.c
index 1d2718ace8397fe636e6574a046b0befacc01bcc..3f02c119905febdc52508f6cc79cb5182ea75263 100644 (file)
--- 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);
        }