Skip to content

Commit

Permalink
export.c: don't use char16_t
Browse files Browse the repository at this point in the history
<uchar.h> is glibc-specific and it's not even guaranteed to be 2 bytes
long!

  typedef __uint_least16_t char16_t;

uint16_t seems much more appropriate here.

Signed-off-by: Sergii Dmytruk <[email protected]>
  • Loading branch information
SergiiDmytruk authored and vathpela committed Jan 29, 2024
1 parent 4a5dfbf commit 4f3da3d
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions src/export.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
#include <inttypes.h>
#include <stdint.h>
#include <stdlib.h>
#include <uchar.h>

#include "efivar.h"

Expand All @@ -26,7 +25,7 @@
* efi_guid_t guid;
* uint32_t name_len;
* uint32_t data_len;
* char16_t name[];
* uint16_t name[];
* uint8_t data[];
* uint32_t crc32;
* }
Expand All @@ -35,7 +34,7 @@
* struct {
* uint32_t name_size; // in bytes
* uint32_t data_size; // in bytes
* char16_t name[];
* uint16_t name[];
* efi_guid_t guid;
* uint32_t attr;
* unit8_t data[];
Expand All @@ -56,7 +55,7 @@ efi_variable_import_dmpstore(uint8_t *data, size_t size,
uint32_t datasz;
size_t min = sizeof (uint32_t) /* name size */
+ sizeof (uint32_t) /* data size */
+ sizeof (char16_t) /* two bytes of name */
+ sizeof (uint16_t) /* two bytes of name */
+ sizeof (efi_guid_t) /* guid */
+ sizeof (uint32_t) /* attr */
+ 1 /* one byte of data */
Expand Down Expand Up @@ -195,7 +194,7 @@ efi_variable_import_efivar(uint8_t *data, size_t datasz, efi_variable_t **var_ou
+ sizeof (uint64_t) /* attr */
+ sizeof (efi_guid_t) /* guid */
+ sizeof (uint32_t) * 2 /* name_len and data_len */
+ sizeof (char16_t) /* two bytes of name */
+ sizeof (uint16_t) /* two bytes of name */
+ 1 /* one byte of data */
+ 4; /* crc32 */
uint32_t crc;
Expand Down Expand Up @@ -276,7 +275,7 @@ efi_variable_import_efivar(uint8_t *data, size_t datasz, efi_variable_t **var_ou
return -1;
}

char16_t *wname = (char16_t *)ptr;
uint16_t *wname = (uint16_t *)ptr;
for (uint32_t i = 0; i < name_len; i++)
var.name[i] = wname[i] & 0xff;
ptr += name_len;
Expand Down

0 comments on commit 4f3da3d

Please sign in to comment.