OSDN Git Service

Don't depend on vendor-defined calloc(n, 0) behavior.
authorPeter Jones <pjones@redhat.com>
Mon, 12 Jan 2015 19:15:24 +0000 (14:15 -0500)
committerPeter Jones <pjones@redhat.com>
Mon, 12 Jan 2015 19:15:24 +0000 (14:15 -0500)
If we don't have any boot variables, we know that 0 is free, so just
return that.

Signed-off-by: Peter Jones <pjones@redhat.com>
src/efibootmgr/efibootmgr.c

index 319e732..9f1636a 100644 (file)
@@ -172,9 +172,13 @@ find_free_boot_var(list_t *boot_list)
        uint16_t *vars, free_number;
        list_t *pos;
        var_entry_t *boot;
-       list_for_each(pos, boot_list) {
+
+       list_for_each(pos, boot_list)
                num_vars++;
-       }
+
+       if (num_vars == 0)
+               return 0;
+
        vars = calloc(1, sizeof(uint16_t) * num_vars);
        if (!vars)
                return -1;