some extra null pointer checks
[project/uci.git] / file.c
diff --git a/file.c b/file.c
index 7188a90..416422d 100644 (file)
--- a/file.c
+++ b/file.c
@@ -210,6 +210,9 @@ static void parse_str(struct uci_context *ctx, char **str, char **target)
                case '"':
                        parse_double_quote(ctx, str, target);
                        break;
+               case '#':
+                       **str = 0;
+                       /* fall through */
                case 0:
                        goto done;
                case '\\':
@@ -450,7 +453,12 @@ static void uci_parse_line(struct uci_context *ctx, bool single)
                char *pbrk = NULL;
                word = strtok_r(word, " \t", &pbrk);
 
+               if (!word)
+                       continue;
+
                switch(word[0]) {
+                       case '#':
+                               return;
                        case 'p':
                                if ((word[1] == 0) || !strcmp(word + 1, "ackage"))
                                        uci_parse_package(ctx, &word, single);
@@ -907,8 +915,14 @@ int uci_commit(struct uci_context *ctx, struct uci_package **package, bool overw
                if (!overwrite) {
                        name = uci_strdup(ctx, p->e.name);
                        path = uci_strdup(ctx, p->path);
+                       /* dump our own changes to the history file */
                        if (!uci_list_empty(&p->history))
                                UCI_INTERNAL(uci_save, ctx, p);
+
+                       /* 
+                        * other processes might have modified the config 
+                        * as well. dump and reload 
+                        */
                        uci_free_package(&p);
                        uci_file_cleanup(ctx);
                        UCI_INTERNAL(uci_import, ctx, f, name, &p, true);