From 3bedea1bddf0c2df7eddc1f1526949ded3978878 Mon Sep 17 00:00:00 2001 From: Stefan Weil Date: Thu, 19 Jan 2023 18:15:05 +0100 Subject: [PATCH] Fix FP division by zero in LanguageModel::ExtractFeaturesFromPath (issue #3995) Signed-off-by: Stefan Weil --- src/wordrec/language_model.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/wordrec/language_model.cpp b/src/wordrec/language_model.cpp index 629c4b84..1c96703c 100644 --- a/src/wordrec/language_model.cpp +++ b/src/wordrec/language_model.cpp @@ -1375,7 +1375,12 @@ void LanguageModel::ExtractFeaturesFromPath(const ViterbiStateEntry &vse, float // features[PTRAIN_NUM_BAD_FONT] = vse.consistency_info.inconsistent_font; // Classifier-related features. - features[PTRAIN_RATING_PER_CHAR] = vse.ratings_sum / vse.outline_length; + if (vse.outline_length > 0.0f) { + features[PTRAIN_RATING_PER_CHAR] = vse.ratings_sum / vse.outline_length; + } else { + // Avoid FP division by 0. + features[PTRAIN_RATING_PER_CHAR] = 0.0f; + } } WERD_CHOICE *LanguageModel::ConstructWord(ViterbiStateEntry *vse, WERD_RES *word_res,