From: Lennart Poettering Date: Thu, 10 Aug 2023 08:46:05 +0000 (+0200) Subject: file-io: let's use offsetof() rather than sizeof() for determining EFI_FILE_INFO... X-Git-Tag: v255-rc1~757 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=490b4486a752d8d2a10eb4c10d5af523ea539f5e;p=thirdparty%2Fsystemd.git file-io: let's use offsetof() rather than sizeof() for determining EFI_FILE_INFO prefix size The gnu-efi definition of the struct uses [1], our local one [0] to size the filename array. Let's avoid an ambiguity and use offsetof() so that this difference doesn't matter. Also, doing it this way makes very clear to the read what happens here: it's a structure with a variable size suffix. --- diff --git a/src/boot/efi/proto/file-io.h b/src/boot/efi/proto/file-io.h index 57df9e111c1..001ad486752 100644 --- a/src/boot/efi/proto/file-io.h +++ b/src/boot/efi/proto/file-io.h @@ -35,7 +35,7 @@ typedef struct { * position when returning EFI_BUFFER_TOO_SMALL, effectively skipping over any files when * the buffer was too small. Therefore, we always start with a buffer that should handle FAT32 * max file name length. */ -#define EFI_FILE_INFO_MIN_SIZE (sizeof(EFI_FILE_INFO) + 256 * sizeof(char16_t)) +#define EFI_FILE_INFO_MIN_SIZE (offsetof(EFI_FILE_INFO, FileName) + 256U * sizeof(char16_t)) typedef struct EFI_SIMPLE_FILE_SYSTEM_PROTOCOL EFI_SIMPLE_FILE_SYSTEM_PROTOCOL; struct EFI_SIMPLE_FILE_SYSTEM_PROTOCOL {