]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
last: fix false positive compiler warning
authorSami Kerola <kerolasa@iki.fi>
Thu, 3 May 2018 21:57:59 +0000 (22:57 +0100)
committerKarel Zak <kzak@redhat.com>
Thu, 10 May 2018 09:29:17 +0000 (11:29 +0200)
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@iki.fi>
login-utils/last.c

index 80d77d20b28e8640bd680308a498e33dc057789c..59dfdb2f5e77ce7a383ae08efd75799ee7c25d4d 100644 (file)
@@ -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]))