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: Emil Gydesen <emil.gydesen@nordicsemi.no>
This commit is contained in:
parent
a895abab86
commit
4cf00a6125
1 changed files with 8 additions and 1 deletions
|
|
@ -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;
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue