Signed-off-by: Yousong Zhou <yszhou4tech@gmail.com>
pctx->buf = uci_malloc(ctx, LINEBUF);
pctx->bufsz = LINEBUF;
}
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);
}
pctx->bufsz *= 2;
pctx->buf = uci_realloc(ctx, pctx->buf, pctx->bufsz);
}