Skip to content

Commit

Permalink
Fix compiler warnings (-Wstringop-truncation)
Browse files Browse the repository at this point in the history
gcc warnings:

    src/api/tesseractmain.cpp:252:14: warning:
        ‘char* strncpy(char*, const char*, size_t)’ specified bound 255
        equals destination size [-Wstringop-truncation]
    src/ccutil/unicharset.h:66:12: warning:
        ‘char* strncpy(char*, const char*, size_t)’ output may be truncated copying 30 bytes from a string of length 30 [-Wstringop-truncation]
    src/ccutil/unicharset.cpp:806:12: warning:
        ‘char* strncpy(char*, const char*, size_t)’ specified bound 64 equals destination size [-Wstringop-truncation]

Signed-off-by: Stefan Weil <[email protected]>
  • Loading branch information
stweil committed Feb 9, 2019
1 parent ec8f02c commit aa2dcca
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/api/tesseractmain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ static void SetVariablesFromCLArgs(tesseract::TessBaseAPI* api, int argc,
exit(EXIT_FAILURE);
}
*p = 0;
strncpy(opt2, strchr(argv[i + 1], '=') + 1, 255);
strncpy(opt2, strchr(argv[i + 1], '=') + 1, sizeof(opt2) - 1);
opt2[254] = 0;
++i;

Expand Down
2 changes: 1 addition & 1 deletion src/ccutil/unicharset.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -803,7 +803,7 @@ bool UNICHARSET::load_via_fgets(
unsigned int properties;
char script[64];

strncpy(script, null_script, sizeof(script));
strncpy(script, null_script, sizeof(script) - 1);
int min_bottom = 0;
int max_bottom = UINT8_MAX;
int min_top = 0;
Expand Down
2 changes: 1 addition & 1 deletion src/ccutil/unicharset.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ class CHAR_FRAGMENT {
set_natural(natural);
}
inline void set_unichar(const char *uch) {
strncpy(this->unichar, uch, UNICHAR_LEN);
strncpy(this->unichar, uch, sizeof(this->unichar));
this->unichar[UNICHAR_LEN] = '\0';
}
inline void set_pos(int p) { this->pos = p; }
Expand Down

0 comments on commit aa2dcca

Please sign in to comment.