Skip to content

Commit

Permalink
wordrec: Fix compiler warning (-Wstringop-truncation) (#1398)
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
stweil authored and zdenop committed Mar 18, 2018
1 parent 860dd10 commit c222145
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions wordrec/language_model.cpp
Expand Up @@ -953,10 +953,10 @@ float LanguageModel::ComputeNgramCost(const char *unichar,
// unless use_only_first_uft8_step is true.
if (unichar_ptr < unichar_end) {
if (modified_context == NULL) {
int context_len = strlen(context);
size_t context_len = strlen(context);
modified_context =
new char[context_len + strlen(unichar_ptr) + step + 1];
strncpy(modified_context, context, context_len);
memcpy(modified_context, context, context_len);
modified_context_end = modified_context + context_len;
context_ptr = modified_context;
}
Expand Down

0 comments on commit c222145

Please sign in to comment.