file: preserve original file mode after commit
[oweals/uci.git] / cli.c
diff --git a/cli.c b/cli.c
index f8b45dba091f088f84e22dc98503fe9e6e1fd7e3..6ba97ea0742494831edf468f6b16ddd33ea2f479 100644 (file)
--- a/cli.c
+++ b/cli.c
@@ -113,8 +113,16 @@ uci_lookup_section_ref(struct uci_section *s)
                maxlen = strlen(s->type) + 1 + 2 + 10;
                if (!typestr) {
                        typestr = malloc(maxlen);
+                       if (!typestr)
+                               return NULL;
                } else {
-                       typestr = realloc(typestr, maxlen);
+                       void *p = realloc(typestr, maxlen);
+                       if (!p) {
+                               free(typestr);
+                               return NULL;
+                       }
+
+                       typestr = p;
                }
 
                if (typestr)
@@ -177,6 +185,7 @@ static void cli_perror(void)
        uci_perror(ctx, appname);
 }
 
+__attribute__((format(printf, 1, 2)))
 static void cli_error(const char *fmt, ...)
 {
        va_list ap;
@@ -563,7 +572,7 @@ static int uci_batch_cmd(void)
                        return 1;
                }
                argv[i] = NULL;
-               if ((ret = uci_parse_argument(ctx, input, &str, &argv[i])) != UCI_OK) {
+               if (uci_parse_argument(ctx, input, &str, &argv[i]) != UCI_OK) {
                        cli_perror();
                        i = 0;
                        break;