Skip to content

Commit a49b8f1

Browse files
committed
Fix CID 1297960 (Dereference after null check)
Signed-off-by: Stefan Weil <sw@weilnetz.de>
1 parent 86eb4df commit a49b8f1

File tree

1 file changed

+30
-30
lines changed

1 file changed

+30
-30
lines changed

src/api/baseapi.cpp

+30-30
Original file line numberDiff line numberDiff line change
@@ -1998,39 +1998,39 @@ bool TessBaseAPI::AdaptToWordStr(PageSegMode mode, const char* wordstr) {
19981998
WERD_RES* word_res = it.word();
19991999
if (word_res != nullptr) {
20002000
word_res->word->set_text(wordstr);
2001+
// Check to see if text matches wordstr.
2002+
int w = 0;
2003+
int t;
2004+
for (t = 0; text[t] != '\0'; ++t) {
2005+
if (text[t] == '\n' || text[t] == ' ')
2006+
continue;
2007+
while (wordstr[w] == ' ') ++w;
2008+
if (text[t] != wordstr[w])
2009+
break;
2010+
++w;
2011+
}
2012+
if (text[t] != '\0' || wordstr[w] != '\0') {
2013+
// No match.
2014+
delete page_res_;
2015+
GenericVector<TBOX> boxes;
2016+
page_res_ = tesseract_->SetupApplyBoxes(boxes, block_list_);
2017+
tesseract_->ReSegmentByClassification(page_res_);
2018+
tesseract_->TidyUp(page_res_);
2019+
PAGE_RES_IT pr_it(page_res_);
2020+
if (pr_it.word() == nullptr)
2021+
success = false;
2022+
else
2023+
word_res = pr_it.word();
2024+
} else {
2025+
word_res->BestChoiceToCorrectText();
2026+
}
2027+
if (success) {
2028+
tesseract_->EnableLearning = true;
2029+
tesseract_->LearnWord(nullptr, word_res);
2030+
}
20012031
} else {
20022032
success = false;
20032033
}
2004-
// Check to see if text matches wordstr.
2005-
int w = 0;
2006-
int t = 0;
2007-
for (t = 0; text[t] != '\0'; ++t) {
2008-
if (text[t] == '\n' || text[t] == ' ')
2009-
continue;
2010-
while (wordstr[w] == ' ') ++w;
2011-
if (text[t] != wordstr[w])
2012-
break;
2013-
++w;
2014-
}
2015-
if (text[t] != '\0' || wordstr[w] != '\0') {
2016-
// No match.
2017-
delete page_res_;
2018-
GenericVector<TBOX> boxes;
2019-
page_res_ = tesseract_->SetupApplyBoxes(boxes, block_list_);
2020-
tesseract_->ReSegmentByClassification(page_res_);
2021-
tesseract_->TidyUp(page_res_);
2022-
PAGE_RES_IT pr_it(page_res_);
2023-
if (pr_it.word() == nullptr)
2024-
success = false;
2025-
else
2026-
word_res = pr_it.word();
2027-
} else {
2028-
word_res->BestChoiceToCorrectText();
2029-
}
2030-
if (success) {
2031-
tesseract_->EnableLearning = true;
2032-
tesseract_->LearnWord(nullptr, word_res);
2033-
}
20342034
} else {
20352035
success = false;
20362036
}

0 commit comments

Comments
 (0)