Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix some issues which were reported by GitHub code scanning #4236

Merged
merged 1 commit into from
May 3, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions src/ccutil/ambigs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -270,10 +270,10 @@ bool UnicharAmbigs::ParseAmbiguityLine(int line_num, int version, int debug_leve
return true;
}
int i;
char *token;
char *next_token;
if (!(token = strtok_r(buffer, kAmbigDelimiters, &next_token)) ||
!sscanf(token, "%d", test_ambig_part_size) || *test_ambig_part_size <= 0) {
char *token = strtok_r(buffer, kAmbigDelimiters, &next_token);
if (!token || sscanf(token, "%d", test_ambig_part_size) != 1 ||
*test_ambig_part_size <= 0) {
if (debug_level) {
tprintf(kIllegalMsg, line_num);
}
Expand All @@ -300,7 +300,8 @@ bool UnicharAmbigs::ParseAmbiguityLine(int line_num, int version, int debug_leve
test_unichar_ids[i] = INVALID_UNICHAR_ID;

if (i != *test_ambig_part_size || !(token = strtok_r(nullptr, kAmbigDelimiters, &next_token)) ||
!sscanf(token, "%d", replacement_ambig_part_size) || *replacement_ambig_part_size <= 0) {
sscanf(token, "%d", replacement_ambig_part_size) != 1 ||
*replacement_ambig_part_size <= 0) {
if (debug_level) {
tprintf(kIllegalMsg, line_num);
}
Expand Down Expand Up @@ -341,7 +342,8 @@ bool UnicharAmbigs::ParseAmbiguityLine(int line_num, int version, int debug_leve
// Note that if m > 1, an ngram will be inserted into the
// modified word, not the individual unigrams. Tesseract
// has limited support for ngram unichar (e.g. dawg permuter).
if (!(token = strtok_r(nullptr, kAmbigDelimiters, &next_token)) || !sscanf(token, "%d", type)) {
token = strtok_r(nullptr, kAmbigDelimiters, &next_token);
if (!token || sscanf(token, "%d", type) != 1) {
if (debug_level) {
tprintf(kIllegalMsg, line_num);
}
Expand Down
Loading