Prevent undefined behaviour

This commit is contained in:
Přemysl Eric Janouch 2022-09-24 18:42:59 +02:00
parent 0570a4d050
commit d13b4a793d
Signed by: p
GPG Key ID: A0420B94F92B9493
1 changed files with 4 additions and 0 deletions

View File

@ -1014,6 +1014,10 @@ stardict_longest_common_collation_prefix (StardictDict *sd,
u_strFromUTF8 (NULL, 0, &uc2_len, s2, -1, &error); u_strFromUTF8 (NULL, 0, &uc2_len, s2, -1, &error);
error = U_ZERO_ERROR; error = U_ZERO_ERROR;
// Prevent undefined behaviour with VLAs.
if (!uc1_len || !uc2_len)
return 0;
UChar uc1[uc1_len]; UChar uc1[uc1_len];
UChar uc2[uc2_len]; UChar uc2[uc2_len];
u_strFromUTF8 (uc1, uc1_len, NULL, s1, -1, &error); u_strFromUTF8 (uc1, uc1_len, NULL, s1, -1, &error);