mirror of
https://github.com/systemd/systemd.git
synced 2025-01-25 10:04:04 +03:00
sd-boot: Don't use magic integer constants
This commit is contained in:
parent
8aba0eec49
commit
b2cf9922a4
@ -101,7 +101,7 @@ EFI_STATUS efivar_set(const EFI_GUID *vendor, const CHAR16 *name, const CHAR16 *
|
|||||||
EFI_STATUS efivar_set_uint_string(const EFI_GUID *vendor, const CHAR16 *name, UINTN i, UINT32 flags) {
|
EFI_STATUS efivar_set_uint_string(const EFI_GUID *vendor, const CHAR16 *name, UINTN i, UINT32 flags) {
|
||||||
CHAR16 str[32];
|
CHAR16 str[32];
|
||||||
|
|
||||||
SPrint(str, 32, L"%u", i);
|
SPrint(str, ELEMENTSOF(str), L"%u", i);
|
||||||
return efivar_set(vendor, name, str, flags);
|
return efivar_set(vendor, name, str, flags);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -132,35 +132,35 @@ EFI_STATUS efivar_set_uint64_le(const EFI_GUID *vendor, const CHAR16 *name, UINT
|
|||||||
}
|
}
|
||||||
|
|
||||||
EFI_STATUS efivar_get(const EFI_GUID *vendor, const CHAR16 *name, CHAR16 **value) {
|
EFI_STATUS efivar_get(const EFI_GUID *vendor, const CHAR16 *name, CHAR16 **value) {
|
||||||
_cleanup_freepool_ CHAR8 *buf = NULL;
|
_cleanup_freepool_ CHAR16 *buf = NULL;
|
||||||
EFI_STATUS err;
|
EFI_STATUS err;
|
||||||
CHAR16 *val;
|
CHAR16 *val;
|
||||||
UINTN size;
|
UINTN size;
|
||||||
|
|
||||||
err = efivar_get_raw(vendor, name, &buf, &size);
|
err = efivar_get_raw(vendor, name, (CHAR8**)&buf, &size);
|
||||||
if (EFI_ERROR(err))
|
if (EFI_ERROR(err))
|
||||||
return err;
|
return err;
|
||||||
|
|
||||||
/* Make sure there are no incomplete characters in the buffer */
|
/* Make sure there are no incomplete characters in the buffer */
|
||||||
if ((size % 2) != 0)
|
if ((size % sizeof(CHAR16)) != 0)
|
||||||
return EFI_INVALID_PARAMETER;
|
return EFI_INVALID_PARAMETER;
|
||||||
|
|
||||||
if (!value)
|
if (!value)
|
||||||
return EFI_SUCCESS;
|
return EFI_SUCCESS;
|
||||||
|
|
||||||
/* Return buffer directly if it happens to be NUL terminated already */
|
/* Return buffer directly if it happens to be NUL terminated already */
|
||||||
if (size >= 2 && buf[size-2] == 0 && buf[size-1] == 0) {
|
if (size >= sizeof(CHAR16) && buf[size/sizeof(CHAR16)] == 0) {
|
||||||
*value = (CHAR16*) TAKE_PTR(buf);
|
*value = TAKE_PTR(buf);
|
||||||
return EFI_SUCCESS;
|
return EFI_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Make sure a terminating NUL is available at the end */
|
/* Make sure a terminating NUL is available at the end */
|
||||||
val = AllocatePool(size + 2);
|
val = AllocatePool(size + sizeof(CHAR16));
|
||||||
if (!val)
|
if (!val)
|
||||||
return EFI_OUT_OF_RESOURCES;
|
return EFI_OUT_OF_RESOURCES;
|
||||||
|
|
||||||
CopyMem(val, buf, size);
|
CopyMem(val, buf, size);
|
||||||
val[size/2] = 0; /* NUL terminate */
|
val[size / sizeof(CHAR16)] = 0; /* NUL terminate */
|
||||||
|
|
||||||
*value = val;
|
*value = val;
|
||||||
return EFI_SUCCESS;
|
return EFI_SUCCESS;
|
||||||
@ -255,7 +255,7 @@ VOID efivar_set_time_usec(const EFI_GUID *vendor, const CHAR16 *name, UINT64 use
|
|||||||
if (usec == 0)
|
if (usec == 0)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
SPrint(str, 32, L"%ld", usec);
|
SPrint(str, ELEMENTSOF(str), L"%ld", usec);
|
||||||
efivar_set(vendor, name, str, 0);
|
efivar_set(vendor, name, str, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user