Skip to content

Commit

Permalink
Fix: some Wstringop-truncation warnings during compile.
Browse files Browse the repository at this point in the history
Changing strncpy to memcpy does the trick.
  • Loading branch information
k21971 committed Oct 31, 2024
1 parent 15fa993 commit ecb975d
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/pager.c
Original file line number Diff line number Diff line change
Expand Up @@ -656,7 +656,7 @@ char *supplemental_name;
(note: strncpy() only terminates output string if the specified
count is bigger than the length of the substring being copied) */
if (!strncmp(dbase_str, "moist towel", 11))
(void) strncpy(dbase_str += 2, "wet", 3); /* skip "mo" replace "ist" */
memcpy(dbase_str += 2, "wet", 3); /* skip "mo" replace "ist" */

/* Make sure the name is non-empty. */
if (*dbase_str) {
Expand Down
2 changes: 1 addition & 1 deletion src/pline.c
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ VA_DECL(const char *, line)
/* truncate, preserving the final 3 characters:
"___ extremely long text" -> "___ extremely l...ext"
(this may be suboptimal if overflow is less than 3) */
(void) strncpy(pbuf + BUFSZ - 1 - 6, "...", 3);
memcpy(pbuf + BUFSZ - 1 - 6, "...", 3);
/* avoid strncpy; buffers could overlap if excess is small */
pbuf[BUFSZ - 1 - 3] = line[ln - 3];
pbuf[BUFSZ - 1 - 2] = line[ln - 2];
Expand Down
2 changes: 1 addition & 1 deletion src/write.c
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ register struct obj *pen;
nm += 3;

if ((bp = strstri(nm, " armour")) != 0) {
(void) strncpy(bp, " armor ", 7); /* won't add '\0' */
memcpy(bp, " armor ", 7); /* won't add '\0' */
(void) mungspaces(bp + 1); /* remove the extra space */
}

Expand Down

0 comments on commit ecb975d

Please sign in to comment.