]> git.ozlabs.org Git - petitboot/blobdiff - discover/grub2/script.c
discover: Fix potentially-uninitialised variables
[petitboot] / discover / grub2 / script.c
index 75b8aaaae474fc6348215dea26d7e963f31e4562..e29d43702b1e0099435ab76b2f3966ad559cee90 100644 (file)
@@ -23,8 +23,8 @@
        container_of(stmt, struct grub2_statement_conditional, st)
 
 struct env_entry {
-       const char              *name;
-       const char              *value;
+       char                    *name;
+       char                    *value;
        struct list_item        list;
 };
 
@@ -75,11 +75,13 @@ void script_env_set(struct grub2_script *script,
 
        if (!entry) {
                entry = talloc(script, struct env_entry);
-               entry->name = name;
+               entry->name = talloc_strdup(entry, name);
                list_add(&script->environment, &entry->list);
+       } else {
+               talloc_free(entry->value);
        }
 
-       entry->value = value;
+       entry->value = talloc_strdup(entry, value);
 }
 
 static bool expand_var(struct grub2_script *script, struct grub2_word *word)
@@ -318,7 +320,7 @@ int statement_if_execute(struct grub2_script *script,
        struct grub2_statement_if *st = to_stmt_if(statement);
        struct grub2_statement *conditional;
        bool executed;
-       int rc;
+       int rc = 0;
 
        list_for_each_entry(&st->conditionals->list, conditional, list) {
                rc = statement_conditional_execute(script,