Skip to content

Commit

Permalink
fix truncation warnings for strncpy(3)
Browse files Browse the repository at this point in the history
Problem: Modern compilers warn of possible truncation in calls to
strncpy(3) in the pdsh codebase.

Fix the warnings in hostlist.c and wcoll.c by reducing the size to
copy by one character.
  • Loading branch information
grondo committed Dec 19, 2023
1 parent f2d85e9 commit 38eda25
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/common/hostlist.c
Original file line number Diff line number Diff line change
Expand Up @@ -1512,7 +1512,7 @@ _hostlist_create_bracketed(const char *hostlist, char *sep, char *r_op)
}

while ((tok = _next_tok(sep, &str)) != NULL) {
strncpy(cur_tok, tok, 1024);
strncpy(cur_tok, tok, 1023);

if ((p = strchr(tok, '[')) != NULL) {
char *q, *prefix = tok;
Expand Down
4 changes: 2 additions & 2 deletions src/pdsh/wcoll.c
Original file line number Diff line number Diff line change
Expand Up @@ -187,10 +187,10 @@ static char * wcoll_ctx_resolve_path (struct wcoll_ctx *ctx,
const char *file, char *buf, int len)
{
if (file[0] == '/')
strncpy (buf, file, len);
strncpy (buf, file, len - 1);
else if ( file[0] == '.'
&& (file[1] == '/' || (file[1] == '.' && file[2] == '/')))
strncpy (buf, file, len);
strncpy (buf, file, len - 1);
else {
if (wcoll_ctx_path_lookup (ctx, file, buf, len) < 0)
return NULL;
Expand Down

0 comments on commit 38eda25

Please sign in to comment.