[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH] maint: avoid strncat warning on GCC 10.1.1
From: |
Pádraig Brady |
Subject: |
[PATCH] maint: avoid strncat warning on GCC 10.1.1 |
Date: |
Sat, 7 Nov 2020 21:33:27 +0000 |
User-agent: |
Mozilla/5.0 (X11; Linux x86_64; rv:83.0) Gecko/20100101 Thunderbird/83.0 |
GCC 10 without optimization gives:
error: ‘strncat’ argument 2 declared attribute ‘nonstring’
[-Werror=stringop-overflow=]
strncat (comment, UT_ID (utmp_ent), utmpsize);
Note the strncat man page says that:
"src does not need to be null-terminated
if it contains n or more bytes."
And the POSIX spec says that the second (source) parameter
is an array not a string.
So I think it's incorrect for strncat to require src be a string type.
This constraint seems to be being added to the gcc builtin strncat,
as specifiying -fno-builtin also avoids the warning.
Note specifying any optimization level also avoids the warning.
* src/who.c (make_id_equals_comment): Avoid the issue by using
stpcpy + stzncpy, instead of strcpy + strncat.
This pattern is used elsewhere in who.c
---
src/who.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/src/who.c b/src/who.c
index abf3bc734..a03927247 100644
--- a/src/who.c
+++ b/src/who.c
@@ -450,8 +450,8 @@ make_id_equals_comment (STRUCT_UTMP const *utmp_ent)
size_t utmpsize = sizeof UT_ID (utmp_ent);
char *comment = xmalloc (strlen (_("id=")) + utmpsize + 1);
- strcpy (comment, _("id="));
- strncat (comment, UT_ID (utmp_ent), utmpsize);
+ char *p = stpcpy (comment, _("id="));
+ stzncpy (p, UT_ID (utmp_ent), utmpsize);
return comment;
}
--
2.26.2
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [PATCH] maint: avoid strncat warning on GCC 10.1.1,
Pádraig Brady <=