[PATCH 3/3] last: fix false positive compiler warning

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



login-utils/last.c: In function ‘list’:
login-utils/last.c:398:36: warning: argument to ‘sizeof’ in ‘strncat’ call
is the same expression as the source; did you mean to use the size of the
destination?  [-Wsizeof-pointer-memaccess]
  strncat(utline, p->ut_line, sizeof(p->ut_line));

The sizeof(utline) is defined as sizeof(p->ut_line) + 1, so the compiler got
that wrong.  Lets truncate strncat() otherway around to keep gcc 8.1 happy.

Signed-off-by: Sami Kerola <kerolasa@xxxxxx>
---
 login-utils/last.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/login-utils/last.c b/login-utils/last.c
index 80d77d20b..59dfdb2f5 100644
--- a/login-utils/last.c
+++ b/login-utils/last.c
@@ -395,7 +395,7 @@ static int list(const struct last_control *ctl, struct utmpx *p, time_t logout_t
 	 *	uucp and ftp have special-type entries
 	 */
 	utline[0] = 0;
-	strncat(utline, p->ut_line, sizeof(p->ut_line));
+	strncat(utline, p->ut_line, sizeof(utline) - 1);
 	if (strncmp(utline, "ftp", 3) == 0 && isdigit(utline[3]))
 		utline[3] = 0;
 	if (strncmp(utline, "uucp", 4) == 0 && isdigit(utline[4]))
-- 
2.17.0

--
To unsubscribe from this list: send the line "unsubscribe util-linux" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html



[Index of Archives]     [Netdev]     [Ethernet Bridging]     [Linux Wireless]     [Kernel Newbies]     [Security]     [Linux for Hams]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux Admin]     [Samba]

  Powered by Linux