Skip to content

Commit

Permalink
Fix some issues which were reported by GitHub code scanning
Browse files Browse the repository at this point in the history
GitHub code scanning report:

    Incorrect return-value check for a 'scanf'-like function

Signed-off-by: Stefan Weil <sw@weilnetz.de>
  • Loading branch information
stweil committed May 3, 2024
1 parent 0f9d507 commit 6648d5b
Showing 1 changed file with 7 additions and 5 deletions.
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

0 comments on commit 6648d5b

Please sign in to comment.