delta: fix outputing of delta entries occupying multiple lines.
[project/uci.git] / file.c
diff --git a/file.c b/file.c
index 1d2718a..5be2e66 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);
        }
@@ -157,7 +157,6 @@ static void parse_double_quote(struct uci_context *ctx, int *target)
                        break;
                }
        }
-       uci_parse_error(ctx, "unterminated \"");
 }
 
 /*
@@ -180,14 +179,13 @@ static void parse_single_quote(struct uci_context *ctx, int *target)
                        /* Multi-line str value */
                        uci_getln(ctx, pctx->pos);
                        if (!pctx_cur_char(pctx))
-                               uci_parse_error(ctx, "EOF with unterminated \"");
+                               uci_parse_error(ctx, "EOF with unterminated '");
 
                        break;
                default:
                        addc(ctx, target, &pctx->pos);
                }
        }
-       uci_parse_error(ctx, "unterminated '");
 }
 
 /*
@@ -280,13 +278,8 @@ int uci_parse_argument(struct uci_context *ctx, FILE *stream, char **str, char *
                uci_alloc_parse_context(ctx);
 
        ctx->pctx->file = stream;
-
-       if (!*str) {
+       if (!*str)
                uci_getln(ctx, 0);
-               *str = ctx->pctx->buf;
-       } else {
-               UCI_ASSERT(ctx, ctx->pctx->pos == *str - ctx->pctx->buf);
-       }
 
        /*FIXME do we need to skip empty lines? */
        ofs_result = next_arg(ctx, false, false);