Skip to content

Commit aa2dcca

Browse files
committed
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>
1 parent ec8f02c commit aa2dcca

File tree

3 files changed

+3
-3
lines changed

3 files changed

+3
-3
lines changed

src/api/tesseractmain.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,7 @@ static void SetVariablesFromCLArgs(tesseract::TessBaseAPI* api, int argc,
249249
exit(EXIT_FAILURE);
250250
}
251251
*p = 0;
252-
strncpy(opt2, strchr(argv[i + 1], '=') + 1, 255);
252+
strncpy(opt2, strchr(argv[i + 1], '=') + 1, sizeof(opt2) - 1);
253253
opt2[254] = 0;
254254
++i;
255255

src/ccutil/unicharset.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -803,7 +803,7 @@ bool UNICHARSET::load_via_fgets(
803803
unsigned int properties;
804804
char script[64];
805805

806-
strncpy(script, null_script, sizeof(script));
806+
strncpy(script, null_script, sizeof(script) - 1);
807807
int min_bottom = 0;
808808
int max_bottom = UINT8_MAX;
809809
int min_top = 0;

src/ccutil/unicharset.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ class CHAR_FRAGMENT {
6363
set_natural(natural);
6464
}
6565
inline void set_unichar(const char *uch) {
66-
strncpy(this->unichar, uch, UNICHAR_LEN);
66+
strncpy(this->unichar, uch, sizeof(this->unichar));
6767
this->unichar[UNICHAR_LEN] = '\0';
6868
}
6969
inline void set_pos(int p) { this->pos = p; }

0 commit comments

Comments
 (0)