tests: add test case for parsing long option values.
[project/uci.git] / file.c
diff --git a/file.c b/file.c
index be75e54..cf0dfaf 100644 (file)
--- a/file.c
+++ b/file.c
@@ -33,7 +33,6 @@
 #include "uci_internal.h"
 
 #define LINEBUF        32
-#define LINEBUF_MAX    4096
 
 /*
  * Fetch a new line from the input stream and resize buffer if necessary
@@ -69,11 +68,10 @@ __private void uci_getln(struct uci_context *ctx, int offset)
                        return;
                }
 
-               if (pctx->bufsz > LINEBUF_MAX/2)
-                       uci_parse_error(ctx, "line too long");
-
                pctx->bufsz *= 2;
                pctx->buf = uci_realloc(ctx, pctx->buf, pctx->bufsz);
+               if (!pctx->buf)
+                       UCI_THROW(ctx, UCI_ERR_MEM);
        } while (1);
 }
 
@@ -278,10 +276,11 @@ 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) {
+               ctx->pctx->pos = 0;
                uci_getln(ctx, 0);
+       }
 
-       /*FIXME do we need to skip empty lines? */
        ofs_result = next_arg(ctx, false, false, false);
        *result = pctx_str(ctx->pctx, ofs_result);
        *str = pctx_cur_str(ctx->pctx);