This is the mail archive of the
libc-alpha@sourceware.org
mailing list for the glibc project.
Re: [Patch] Use memcpy instead of strncpy in nscd/nscd.h to fix build problem with ToT GCC
- From: Ramana Radhakrishnan <ramana dot gcc at googlemail dot com>
- To: sellcey at cavium dot com
- Cc: libc-alpha <libc-alpha at sourceware dot org>
- Date: Tue, 12 Dec 2017 21:29:38 +0000
- Subject: Re: [Patch] Use memcpy instead of strncpy in nscd/nscd.h to fix build problem with ToT GCC
- Authentication-results: sourceware.org; auth=none
- References: <1513112247.23303.55.camel@cavium.com>
On Tue, Dec 12, 2017 at 8:57 PM, Steve Ellcey <sellcey@cavium.com> wrote:
> The latest ToT GCC is warning about the use of strncpy in nscd/nscd.h.
> The strncpy is intentionally truncating a string so the warning is not
> really useful in this instance. Joseph suggested changing it to
> a memcpy and that seems to work fine. I built glibc with ToT GCC
> using this patch and ran the glibc test with no regressions on aarch64.
>
> OK to checkin?
>
> Steve Ellcey
> sellcey@cavium.com
>
>
> 2017-12-12 Steve Ellcey <sellcey@cavium.com>
>
> * nscd/nscd.h (init_traced_file): Change strncpy to memcpy.
>
>
> diff --git a/nscd/nscd.h b/nscd/nscd.h
> index c6b0a3c..edcb5b6 100644
> --- a/nscd/nscd.h
> +++ b/nscd/nscd.h
> @@ -108,7 +108,7 @@ init_traced_file(struct traced_file *file, const char *fname, int crinit)
> size_t len = (size_t)(dname - fname);
> if (len > sizeof (file->dname))
> abort ();
> - strncpy (file->dname, file->fname, len);
> + memcpy (file->dname, file->fname, len);
> file->dname[len] = '\0';
> }
> /* The basename is the name just after the last forward slash. */
Looks good to me FWIW.
Ramana