On 26 Apr 2021, at 18:08, Sergey Bugaev <buga...@gmail.com> wrote: > > This fixes Wstringop-overflow and Wstringop-truncation GCC warnings. > See https://gcc.gnu.org/bugzilla//show_bug.cgi?id=88059 > > Also, fix a bug where a string was not properly null-terminated. > --- > lib.c | 4 ++-- > stow.c | 5 +++-- > 2 files changed, 5 insertions(+), 4 deletions(-) > > diff --git a/lib.c b/lib.c > index 01cdbd0..717979b 100644 > --- a/lib.c > +++ b/lib.c > @@ -151,8 +151,8 @@ make_filepath (char *path, char *filename) > if (filepath == NULL) > return NULL; > > - strncpy (filepath, path, length); > - strncat (filepath, filename, strlen (filename)); > + strcpy (filepath, path); > + strcat (filepath, filename);
This is dubious. We should be using safe interfaces where possible. > return filepath; > } > diff --git a/stow.c b/stow.c > index 812d33b..adfcf53 100644 > --- a/stow.c > +++ b/stow.c > @@ -282,14 +282,15 @@ stow_diradd (char *dir, int flags, struct patternlist > *patternlist, > { > char *tmp; > > - tmp = (char *) malloc (dir_len + 1); > + tmp = (char *) malloc (dir_len + 2); > > if (tmp == NULL) > return ENOMEM; > > - strncpy (tmp, dir, dir_len); > + strcpy (tmp, dir); > > tmp[dir_len] = '/'; > + tmp[dir_len + 1] = 0; Similarly dubious dropping of explicit lengths. Jess