From f352f1e43f6a61303f9da485f009841c2571af39 Mon Sep 17 00:00:00 2001 From: Samuel Thibault Date: Fri, 1 Apr 2022 20:12:58 +0200 Subject: [PATCH] CheckThousandsGroup: Avoid reading uninitialized data For the case when word is smaller than 4 characters, we should not look at the 3rd or 4th character before checking the previous ones, otherwise we'd at best read uninitialized data, at worse non-existing data. --- src/libespeak-ng/numbers.c | 7 ++++--- tests/translate.test | 3 +++ 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/libespeak-ng/numbers.c b/src/libespeak-ng/numbers.c index 5da8632e..780fa4e1 100644 --- a/src/libespeak-ng/numbers.c +++ b/src/libespeak-ng/numbers.c @@ -1719,13 +1719,14 @@ static bool CheckThousandsGroup(char *word, int group_len) // Is this a group of 3 digits which looks like a thousands group? int ix; - if (IsDigit09(word[group_len]) || IsDigit09(-1)) - return false; - for (ix = 0; ix < group_len; ix++) { if (!IsDigit09(word[ix])) return false; } + + if (IsDigit09(word[group_len]) || IsDigit09(-1)) + return false; + return true; } diff --git a/tests/translate.test b/tests/translate.test index 7b754f5e..55ec2f65 100755 --- a/tests/translate.test +++ b/tests/translate.test @@ -83,3 +83,6 @@ test_phon en "r'oUlIN 0nD@ fl'o@ l'aafIN" "🤣" # skip words # bug: https://github.com/espeak-ng/espeak-ng/issues/471 test_phon sk "sm'eju:tsa s'a tv'a:R" "☺" test_phon sk "bl'ax sm'eju:tsa s'a tv'a:R" "blah ☺" + +# https://github.com/espeak-ng/espeak-ng/pull/1148 +test_phon fr "dY mil v'E~" "2020"