mirror of
https://codeberg.org/libreboot/lbmk.git
synced 2026-07-17 08:40:14 +02:00
util/nvmutil: use memcpy in word/set_word
alignment isn't an issue, but aliasing between uintX_t types in C means that this code may fail on some weird systems. using memcpy here is advisable. Signed-off-by: Leah Rowe <leah@libreboot.org>
This commit is contained in:
+12
-2
@@ -488,8 +488,14 @@ good_checksum(int partnum)
|
|||||||
static uint16_t
|
static uint16_t
|
||||||
word(int pos16, int p)
|
word(int pos16, int p)
|
||||||
{
|
{
|
||||||
|
uint16_t rval = 0;
|
||||||
check_bound(pos16, p);
|
check_bound(pos16, p);
|
||||||
return ((uint16_t *) (buf + (SIZE_4KB * p)))[pos16];
|
(void) memcpy(
|
||||||
|
(uint8_t *) &rval,
|
||||||
|
(uint8_t *) (buf + (SIZE_4KB * p) + (pos16 << 1)),
|
||||||
|
sizeof(uint16_t)
|
||||||
|
);
|
||||||
|
return rval;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
@@ -497,7 +503,11 @@ set_word(int pos16, int p, uint16_t val16)
|
|||||||
{
|
{
|
||||||
check_bound(pos16, p);
|
check_bound(pos16, p);
|
||||||
part_modified[p] = 1;
|
part_modified[p] = 1;
|
||||||
((uint16_t *) (buf + (SIZE_4KB * p)))[pos16] = val16;
|
(void) memcpy(
|
||||||
|
(uint8_t *) (buf + (SIZE_4KB * p) + (pos16 << 1)),
|
||||||
|
(uint8_t *) &val16,
|
||||||
|
sizeof(uint16_t)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
|||||||
Reference in New Issue
Block a user