Skip to content

Commit

Permalink
Fix function ComputeChiSquared (issue tesseract-ocr#3925)
Browse files Browse the repository at this point in the history
mftraining crashed if the search did not find anything.

Signed-off-by: Stefan Weil <sw@weilnetz.de>
  • Loading branch information
stweil authored and GerHobbelt committed Jan 27, 2023
1 parent 295d7e2 commit 071ddfe
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/classify/cluster.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2774,8 +2774,8 @@ static double ComputeChiSquared(uint16_t DegreesOfFreedom, double Alpha)
for the specified number of degrees of freedom. Search the list for
the desired chi-squared. */
CHISTRUCT SearchKey(0.0, Alpha);
auto OldChiSquared = reinterpret_cast<CHISTRUCT *>(
search(ChiWith[DegreesOfFreedom], &SearchKey, AlphaMatch)->first_node());
auto *found = search(ChiWith[DegreesOfFreedom], &SearchKey, AlphaMatch);
auto OldChiSquared = reinterpret_cast<CHISTRUCT *>(found ? found->first_node() : nullptr);

if (OldChiSquared == nullptr) {
OldChiSquared = new CHISTRUCT(DegreesOfFreedom, Alpha);
Expand Down

0 comments on commit 071ddfe

Please sign in to comment.