Commit 4cf00a61 authored by Emil Gydesen's avatar Emil Gydesen Committed by Anas Nashif
Browse files

zephyr: Add zero-len check for utf8_trunc



The function did not check if the provided string had a zero
length before starting to truncate, which meant that last_byte_p
could possible have pointed to the value before the string.

Signed-off-by: default avatarEmil Gydesen <emil.gydesen@nordicsemi.no>
parent a895abab
Loading
Loading
Loading
Loading
+8 −1
Original line number Diff line number Diff line
@@ -16,7 +16,14 @@

char *utf8_trunc(char *utf8_str)
{
	char *last_byte_p = utf8_str + strlen(utf8_str) - 1;
	const size_t len = strlen(utf8_str);

	if (len == 0U) {
		/* no-op */
		return utf8_str;
	}

	char *last_byte_p = utf8_str + len - 1U;
	uint8_t bytes_truncated;
	char seq_start_byte;