Skip to content

Commit

Permalink
use memcpy to avoid compiler warning
Browse files Browse the repository at this point in the history
strncpy is not needed, fixes #306
  • Loading branch information
mwarning committed Oct 2, 2018
1 parent 996dca7 commit e735416
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/template.c
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ int tmpl_parse(struct template *vars, char *dst, size_t dst_len, const char *src
if (varlen > (sizeof(varname) - 1)) {
/* we already parsed the varname and can skip these chars
* but we need to copy these first to the output buffer */
strncpy(dst + dst_i, varnameptr, (varlen > (dst_len - dst_i)) ? (dst_len - dst_i) : varlen);
memcpy(dst + dst_i, varnameptr, (varlen > (dst_len - dst_i)) ? (dst_len - dst_i) : varlen);
src_i += varlen;
dst_i += varlen;
continue;
Expand All @@ -74,15 +74,15 @@ int tmpl_parse(struct template *vars, char *dst, size_t dst_len, const char *src
/* check if varname was found in valid variable names */
if (value == NULL) {
/* we already parsed the varname and can skip these chars */
strncpy(dst + dst_i, varnameptr, (varlen > (dst_len - dst_i)) ? (dst_len - dst_i) : varlen);
memcpy(dst + dst_i, varnameptr, (varlen > (dst_len - dst_i)) ? (dst_len - dst_i) : varlen);
src_i += varlen;
dst_i += varlen;
continue;
}

/* it's a valid varname and contains a variable replace it */
valuelen = strlen(value);
strncpy(dst + dst_i, value, (valuelen > (dst_len - dst_i)) ? (dst_len - dst_i) : valuelen);
memcpy(dst + dst_i, value, (valuelen > (dst_len - dst_i)) ? (dst_len - dst_i) : valuelen);
dst_i += valuelen;
src_i += varlen;
}
Expand Down

1 comment on commit e735416

@bluewavenet
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Interestingly, I was not getting the warning with the OpenWrt 18 sdk. Probably a compiler flag somewhere.

Please sign in to comment.