]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
bcd: Use std alignof
authorJan Janssen <medhefgo@web.de>
Tue, 12 Jul 2022 07:52:29 +0000 (09:52 +0200)
committerJan Janssen <medhefgo@web.de>
Tue, 12 Jul 2022 09:29:18 +0000 (11:29 +0200)
src/boot/efi/bcd.c
src/boot/efi/bcd.h

index 93783cc51b2bde726c5a24684e9682cb0907adfd..730173b9118f1fb6de9feebb5df422273ca74027 100644 (file)
@@ -1,5 +1,6 @@
 /* SPDX-License-Identifier: LGPL-2.1-or-later */
 
+#include <stdalign.h>
 #ifdef SD_BOOT
 #  include <efi.h>
 #  include "macro-fundamental.h"
@@ -10,7 +11,6 @@
 #  include "efi-string.h"
 #  include "string-util-fundamental.h"
 
-#  define UINTN size_t
 #  define TEST_STATIC static
 #endif
 
@@ -177,7 +177,7 @@ static const KeyValue *get_key_value(const uint8_t *bcd, uint32_t bcd_len, const
                 return NULL;
 
         if (BAD_OFFSET(key->key_values_offset, sizeof(uint32_t) * (uint64_t) key->n_key_values, bcd_len) ||
-            (UINTN)(bcd + key->key_values_offset) % sizeof(uint32_t) != 0)
+            (uintptr_t) (bcd + key->key_values_offset) % alignof(uint32_t) != 0)
                 return NULL;
 
         const uint32_t *key_value_list = (const uint32_t *) (bcd + key->key_values_offset);
@@ -227,7 +227,7 @@ static const KeyValue *get_key_value(const uint8_t *bcd, uint32_t bcd_len, const
  * (it always has the GUID 9dea862c-5cdd-4e70-acc1-f32b344d4795). If it contains more than
  * one GUID, the BCD is multi-boot and we stop looking. Otherwise we take that GUID, look it
  * up, and return its description property. */
-TEST_STATIC char16_t *get_bcd_title(uint8_t *bcd, UINTN bcd_len) {
+TEST_STATIC char16_t *get_bcd_title(uint8_t *bcd, size_t bcd_len) {
         assert(bcd);
 
         if (HIVE_CELL_OFFSET >= bcd_len)
@@ -263,13 +263,13 @@ TEST_STATIC char16_t *get_bcd_title(uint8_t *bcd, UINTN bcd_len) {
         char order_guid[sizeof("{00000000-0000-0000-0000-000000000000}\0")];
         if (displayorder_value->data_type != REG_MULTI_SZ ||
             displayorder_value->data_size != sizeof(char16_t[sizeof(order_guid)]) ||
-            (UINTN)(bcd + displayorder_value->data_offset) % sizeof(char16_t) != 0)
+            (uintptr_t) (bcd + displayorder_value->data_offset) % alignof(char16_t) != 0)
                 /* BCD is multi-boot. */
                 return NULL;
 
         /* Keys are stored as ASCII in registry hives if the data fits (and GUIDS always should). */
         char16_t *order_guid_utf16 = (char16_t *) (bcd + displayorder_value->data_offset);
-        for (UINTN i = 0; i < sizeof(order_guid) - 2; i++) {
+        for (size_t i = 0; i < sizeof(order_guid) - 2; i++) {
                 char16_t c = order_guid_utf16[i];
                 switch (c) {
                 case '-':
@@ -305,7 +305,7 @@ TEST_STATIC char16_t *get_bcd_title(uint8_t *bcd, UINTN bcd_len) {
         if (description_value->data_type != REG_SZ ||
             description_value->data_size < sizeof(char16_t) ||
             description_value->data_size % sizeof(char16_t) != 0 ||
-            (UINTN)(bcd + description_value->data_offset) % sizeof(char16_t))
+            (uintptr_t) (bcd + description_value->data_offset) % alignof(char16_t))
                 return NULL;
 
         /* The data should already be NUL-terminated. */
index dd666e09e7b10db49052b06047f8598ae8655c3e..c27af55c1e3f802decded850d38ccd5eb52e2dd7 100644 (file)
@@ -1,7 +1,7 @@
 /* SPDX-License-Identifier: LGPL-2.1-or-later */
 #pragma once
 
-#include <efi.h>
+#include <stdint.h>
 #include <uchar.h>
 
-char16_t *get_bcd_title(uint8_t *bcd, UINTN bcd_len);
+char16_t *get_bcd_title(uint8_t *bcd, size_t bcd_len);