Skip to content

Commit

Permalink
use memcpy (recommended) instead of stpncpy to avoid spurious gcc war…
Browse files Browse the repository at this point in the history
…nings
  • Loading branch information
alex-courtis committed Dec 13, 2024
1 parent 93008bb commit 0f6b118
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions src/util.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,17 +31,20 @@ char *string_replace(const char * const src, const char * const target, const ch
while ((match = strstr(s, target))) {

// copy up to match
r = stpncpy(r, s, match - s);
memcpy(r, s, match - s);
r += match - s;

// copy replacement
r = stpncpy(r, replacement, len_replacement);
memcpy(r, replacement, len_replacement);
r += len_replacement;

// advance src to after match
s = match + len_target;
}

// copy remainder
r = stpncpy(r, s, len_res - (r - res) - 1);
// copy remainder, ensuring terminated
memcpy(r, s, len_res - (r - res) - 1);
res[len_res - 1] = '\0';

return res;
}

0 comments on commit 0f6b118

Please sign in to comment.