diff mbox

[OpenWrt-Devel,v2,04/16] file: fix EOF check.

Message ID 1418713218-16300-5-git-send-email-yszhou4tech@gmail.com
State Accepted
Headers show

Commit Message

Yousong Zhou Dec. 16, 2014, 7 a.m. UTC
Signed-off-by: Yousong Zhou <yszhou4tech@gmail.com>
---
 file.c |    4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
diff mbox

Patch

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);
 	}