Fix compiler warnings (-Wstringop-truncation)

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 <sw@weilnetz.de>
This commit is contained in:
Stefan Weil 2019-02-03 22:20:08 +01:00
parent ec8f02c0de
commit aa2dcca295
3 changed files with 3 additions and 3 deletions

View File

@ -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;

View File

@ -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;

View File

@ -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; }