add a few missing null pointer checks, and fix check vs dereference order in some...
[project/uci.git] / file.c
diff --git a/file.c b/file.c
index d23e9108be5b8cedbc72835ec90531d952674d55..4eb35b184ff84b9868b3b4ba1f8ddd08e1b6cc4e 100644 (file)
--- a/file.c
+++ b/file.c
@@ -508,7 +508,7 @@ invalid:
 /*
  * escape an uci string for export
  */
-static char *uci_escape(struct uci_context *ctx, const char *str)
+static const char *uci_escape(struct uci_context *ctx, const char *str)
 {
        const char *end;
        int ofs = 0;
@@ -516,6 +516,9 @@ static char *uci_escape(struct uci_context *ctx, const char *str)
        if (!ctx->buf) {
                ctx->bufsz = LINEBUF;
                ctx->buf = malloc(LINEBUF);
+
+               if (!ctx->buf)
+                       return str;
        }
 
        while (1) {
@@ -616,7 +619,7 @@ int uci_import(struct uci_context *ctx, FILE *stream, const char *name, struct u
        uci_alloc_parse_context(ctx);
        pctx = ctx->pctx;
        pctx->file = stream;
-       if (*package && single) {
+       if (package && *package && single) {
                pctx->package = *package;
                pctx->merge = true;
        }