OSDN Git Service

Do better error checking in read_boot_u16(), and simplify it.
authorPeter Jones <pjones@redhat.com>
Fri, 6 Sep 2013 15:02:13 +0000 (11:02 -0400)
committerPeter Jones <pjones@redhat.com>
Mon, 13 Jan 2014 21:29:01 +0000 (16:29 -0500)
Why am I even doing this stupid bitshifting?

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

index a774ee2..3581069 100644 (file)
@@ -361,16 +361,21 @@ static int
 read_boot_u16(const char *name)
 {
        efi_guid_t guid = EFI_GLOBAL_GUID;
-       uint8_t *data = NULL;
+       uint16_t *data = NULL;
        size_t data_size = 0;
        uint32_t attributes = 0;
        int rc;
 
-       rc = efi_get_variable(guid, name, &data, &data_size, &attributes);
+       rc = efi_get_variable(guid, name, (uint8_t **)&data, &data_size,
+                               &attributes);
        if (rc < 0)
                return rc;
+       if (data_size != 2) {
+               errno = EINVAL;
+               return -1;
+       }
 
-       rc = (data[0] & 0xff) | ((data[1] & 0xff) << 8);
+       rc = data[0];
        return rc;
 }