mirror of
https://github.com/tesseract-ocr/tesseract.git
synced 2025-01-19 06:53:36 +08:00
Fix CID 1297960 (Dereference after null check)
Signed-off-by: Stefan Weil <sw@weilnetz.de>
This commit is contained in:
parent
86eb4dfcdc
commit
a49b8f1d21
@ -1998,39 +1998,39 @@ bool TessBaseAPI::AdaptToWordStr(PageSegMode mode, const char* wordstr) {
|
||||
WERD_RES* word_res = it.word();
|
||||
if (word_res != nullptr) {
|
||||
word_res->word->set_text(wordstr);
|
||||
// Check to see if text matches wordstr.
|
||||
int w = 0;
|
||||
int t;
|
||||
for (t = 0; text[t] != '\0'; ++t) {
|
||||
if (text[t] == '\n' || text[t] == ' ')
|
||||
continue;
|
||||
while (wordstr[w] == ' ') ++w;
|
||||
if (text[t] != wordstr[w])
|
||||
break;
|
||||
++w;
|
||||
}
|
||||
if (text[t] != '\0' || wordstr[w] != '\0') {
|
||||
// No match.
|
||||
delete page_res_;
|
||||
GenericVector<TBOX> boxes;
|
||||
page_res_ = tesseract_->SetupApplyBoxes(boxes, block_list_);
|
||||
tesseract_->ReSegmentByClassification(page_res_);
|
||||
tesseract_->TidyUp(page_res_);
|
||||
PAGE_RES_IT pr_it(page_res_);
|
||||
if (pr_it.word() == nullptr)
|
||||
success = false;
|
||||
else
|
||||
word_res = pr_it.word();
|
||||
} else {
|
||||
word_res->BestChoiceToCorrectText();
|
||||
}
|
||||
if (success) {
|
||||
tesseract_->EnableLearning = true;
|
||||
tesseract_->LearnWord(nullptr, word_res);
|
||||
}
|
||||
} else {
|
||||
success = false;
|
||||
}
|
||||
// Check to see if text matches wordstr.
|
||||
int w = 0;
|
||||
int t = 0;
|
||||
for (t = 0; text[t] != '\0'; ++t) {
|
||||
if (text[t] == '\n' || text[t] == ' ')
|
||||
continue;
|
||||
while (wordstr[w] == ' ') ++w;
|
||||
if (text[t] != wordstr[w])
|
||||
break;
|
||||
++w;
|
||||
}
|
||||
if (text[t] != '\0' || wordstr[w] != '\0') {
|
||||
// No match.
|
||||
delete page_res_;
|
||||
GenericVector<TBOX> boxes;
|
||||
page_res_ = tesseract_->SetupApplyBoxes(boxes, block_list_);
|
||||
tesseract_->ReSegmentByClassification(page_res_);
|
||||
tesseract_->TidyUp(page_res_);
|
||||
PAGE_RES_IT pr_it(page_res_);
|
||||
if (pr_it.word() == nullptr)
|
||||
success = false;
|
||||
else
|
||||
word_res = pr_it.word();
|
||||
} else {
|
||||
word_res->BestChoiceToCorrectText();
|
||||
}
|
||||
if (success) {
|
||||
tesseract_->EnableLearning = true;
|
||||
tesseract_->LearnWord(nullptr, word_res);
|
||||
}
|
||||
} else {
|
||||
success = false;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user