Browse Source

file: fix EOF check.

Signed-off-by: Yousong Zhou <yszhou4tech@gmail.com>
Yousong Zhou 9 years ago
parent
commit
def58eba24
1 changed files with 2 additions and 2 deletions
  1. 2 2
      file.c

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