Skip to content

Commit c222145

Browse files
stweilzdenop
authored andcommitted
wordrec: Fix compiler warning (-Wstringop-truncation) (#1398)
gcc warning: wordrec/language_model.cpp:959:16: warning: ‘char* strncpy(char*, const char*, size_t)’ output truncated before terminating nul copying as many bytes from a string as its length [-Wstringop-truncation] memcpy could also be a little bit faster than strncpy. Signed-off-by: Stefan Weil <sw@weilnetz.de>
1 parent 860dd10 commit c222145

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

wordrec/language_model.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -953,10 +953,10 @@ float LanguageModel::ComputeNgramCost(const char *unichar,
953953
// unless use_only_first_uft8_step is true.
954954
if (unichar_ptr < unichar_end) {
955955
if (modified_context == NULL) {
956-
int context_len = strlen(context);
956+
size_t context_len = strlen(context);
957957
modified_context =
958958
new char[context_len + strlen(unichar_ptr) + step + 1];
959-
strncpy(modified_context, context, context_len);
959+
memcpy(modified_context, context, context_len);
960960
modified_context_end = modified_context + context_len;
961961
context_ptr = modified_context;
962962
}

0 commit comments

Comments
 (0)