diff --git a/src/api/tesseractmain.cpp b/src/api/tesseractmain.cpp index ce261b1015..c0e5dfc931 100644 --- a/src/api/tesseractmain.cpp +++ b/src/api/tesseractmain.cpp @@ -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; diff --git a/src/ccutil/unicharset.cpp b/src/ccutil/unicharset.cpp index 85b1942028..d0af73581e 100644 --- a/src/ccutil/unicharset.cpp +++ b/src/ccutil/unicharset.cpp @@ -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; diff --git a/src/ccutil/unicharset.h b/src/ccutil/unicharset.h index be9db93592..68bea44e4b 100644 --- a/src/ccutil/unicharset.h +++ b/src/ccutil/unicharset.h @@ -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; }