* 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 26d702e2c..346b1cea4 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 b41f9837c..1fb1677bf 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 6d9e267d9..3719baec5 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.17.0