Skip to content

Commit

Permalink
Avoid FP overflow in NormEvidenceOf (fixes issue #4257)
Browse files Browse the repository at this point in the history
Signed-off-by: Stefan Weil <[email protected]>
  • Loading branch information
stweil committed Jun 9, 2024
1 parent b0a10bb commit dac6b18
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions src/classify/normmatch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,13 +105,17 @@ float Classify::ComputeNormMatch(CLASS_ID ClassId, const FEATURE_STRUCT &feature
return (1 - NormEvidenceOf(Match));
}

float BestMatch = FLT_MAX;
LIST Protos = NormProtos->Protos[ClassId];

if (DebugMatch) {
tprintf("\nChar norm for class %s\n", unicharset.id_to_unichar(ClassId));
}

LIST Protos = NormProtos->Protos[ClassId];
if (Protos == nullptr) {
// Avoid FP overflow in NormEvidenceOf.
return 1.0f;
}

float BestMatch = FLT_MAX;
iterate(Protos) {
auto Proto = reinterpret_cast<PROTOTYPE *>(Protos->first_node());
float Delta = feature.Params[CharNormY] - Proto->Mean[CharNormY];
Expand Down

0 comments on commit dac6b18

Please sign in to comment.