Jacob Garber has uploaded this change for review. ( https://review.coreboot.org/c/coreboot/+/33793
Change subject: libpayload/libc: Tidy utf16le_to_ascii ......................................................................
libpayload/libc: Tidy utf16le_to_ascii
- Constify the string argument - Change int to size_t, which is what xmalloc expects
Change-Id: I8b5a13319ded4025f883760f2b6d4d7a9ad9fb8b Signed-off-by: Jacob Garber jgarber1@ualberta.ca --- M payloads/libpayload/include/string.h M payloads/libpayload/libc/string.c 2 files changed, 3 insertions(+), 4 deletions(-)
git pull ssh://review.coreboot.org:29418/coreboot refs/changes/93/33793/1
diff --git a/payloads/libpayload/include/string.h b/payloads/libpayload/include/string.h index 4aff0e8..52379a0 100644 --- a/payloads/libpayload/include/string.h +++ b/payloads/libpayload/include/string.h @@ -73,7 +73,7 @@ * @defgroup string Unicode functions * @{ */ -char *utf16le_to_ascii(uint16_t *utf16_string, int maxlen); +char *utf16le_to_ascii(const uint16_t *utf16_string, size_t maxlen); /** @} */
/** diff --git a/payloads/libpayload/libc/string.c b/payloads/libpayload/libc/string.c index 9a5a1ea..fd88a88 100644 --- a/payloads/libpayload/libc/string.c +++ b/payloads/libpayload/libc/string.c @@ -645,12 +645,11 @@ * @param maxlen Maximum possible length of the string in code points * @return Newly allocated ASCII string */ -char *utf16le_to_ascii(uint16_t *utf16_string, int maxlen) +char *utf16le_to_ascii(const uint16_t *utf16_string, size_t maxlen) { char *ascii_string = xmalloc(maxlen + 1); /* +1 for trailing \0 */ ascii_string[maxlen] = '\0'; - int i; - for (i = 0; i < maxlen; i++) { + for (size_t i = 0; i < maxlen; i++) { uint16_t wchar = utf16_string[i]; ascii_string[i] = wchar > 0x7f ? '?' : (char)wchar; }