From 9781fcd532f30afe174239a22816a83c40528b27 Mon Sep 17 00:00:00 2001 From: Paul Eggert Date: Thu, 3 May 2018 13:03:34 -0700 Subject: [PATCH] maint: port to GCC 8 MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit * src/chown-core.h (chopt_free, gid_to_name, uid_to_name): No longer const. * src/make-prime-list.c (xalloc): Add malloc attribute. * src/who.c (make_id_equals_comment): Work around GCC bug 85602 by using mempcpy rather than strncat. Although the old code was correct, strncat raises so many hackles that it’s not worth maintaining its use here. --- src/chown-core.h | 9 +++------ src/make-prime-list.c | 2 +- src/who.c | 12 ++++++++---- 3 files changed, 12 insertions(+), 11 deletions(-) diff --git a/src/chown-core.h b/src/chown-core.h index 26d702e2c7..346b1cea4a 100644 --- a/src/chown-core.h +++ b/src/chown-core.h @@ -68,14 +68,11 @@ struct Chown_option void chopt_init (struct Chown_option *); -void _GL_ATTRIBUTE_PURE _GL_ATTRIBUTE_CONST -chopt_free (struct Chown_option *); +void chopt_free (struct Chown_option *); -char * -gid_to_name (gid_t); +char *gid_to_name (gid_t) _GL_ATTRIBUTE_MALLOC; -char * _GL_ATTRIBUTE_PURE -uid_to_name (uid_t); +char *uid_to_name (uid_t) _GL_ATTRIBUTE_MALLOC; bool chown_files (char **files, int bit_flags, diff --git a/src/make-prime-list.c b/src/make-prime-list.c index b41f9837c9..1fb1677bf3 100644 --- a/src/make-prime-list.c +++ b/src/make-prime-list.c @@ -157,7 +157,7 @@ output_primes (const struct prime *primes, unsigned nprimes) printf ("#define FIRST_OMITTED_PRIME %u\n", p); } -static void * +static void * _GL_ATTRIBUTE_MALLOC xalloc (size_t s) { void *p = malloc (s); diff --git a/src/who.c b/src/who.c index 6d9e267d93..3719baec58 100644 --- a/src/who.c +++ b/src/who.c @@ -447,10 +447,14 @@ print_boottime (const STRUCT_UTMP *utmp_ent) static char * make_id_equals_comment (STRUCT_UTMP const *utmp_ent) { - char *comment = xmalloc (strlen (_("id=")) + sizeof UT_ID (utmp_ent) + 1); - - strcpy (comment, _("id=")); - strncat (comment, UT_ID (utmp_ent), sizeof UT_ID (utmp_ent)); + char const *ideq = _("id="); + char const *ut_id = UT_ID (utmp_ent); + size_t ideqlen = strlen (ideq); + size_t ut_idlen = strnlen (ut_id, sizeof UT_ID (utmp_ent)); + char *comment = xmalloc (ideqlen + ut_idlen + 1); + char *rhs = mempcpy (comment, ideq, ideqlen); + char *z = mempcpy (rhs, ut_id, ut_idlen); + *z = '\0'; return comment; } -- 2.47.2