From aa2dcca295394740c014e592f72c7009f93a209c Mon Sep 17 00:00:00 2001 From: Stefan Weil Date: Sun, 3 Feb 2019 22:20:08 +0100 Subject: [PATCH] Fix compiler warnings (-Wstringop-truncation) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- src/api/tesseractmain.cpp | 2 +- src/ccutil/unicharset.cpp | 2 +- src/ccutil/unicharset.h | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) 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; }