From 77f5a945868e9a2bf9fe71bfdbe8bf54a2441699 Mon Sep 17 00:00:00 2001 From: Ruediger Meier Date: Thu, 1 Dec 2016 09:52:06 +0100 Subject: [PATCH] lslogins: remove useless strlen() strlen() is not smarter than strncpy(). Bytes that follow a null byte are not compared anyway. BTW avoid using the defined sizes. CC: Ondrej Oprala Signed-off-by: Ruediger Meier --- login-utils/lslogins.c | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/login-utils/lslogins.c b/login-utils/lslogins.c index 78d4ed46f4..4109876469 100644 --- a/login-utils/lslogins.c +++ b/login-utils/lslogins.c @@ -413,16 +413,14 @@ again: static struct utmp *get_last_wtmp(struct lslogins_control *ctl, const char *username) { size_t n = 0; - size_t len; if (!username) return NULL; - len = strlen(username); n = ctl->wtmp_size - 1; do { if (!strncmp(username, ctl->wtmp[n].ut_user, - len < UT_NAMESIZE ? len : UT_NAMESIZE)) + sizeof(ctl->wtmp[0].ut_user))) return ctl->wtmp + n; } while (n--); return NULL; @@ -450,16 +448,14 @@ static int require_btmp(void) static struct utmp *get_last_btmp(struct lslogins_control *ctl, const char *username) { size_t n = 0; - size_t len; if (!username) return NULL; - len = strlen(username); n = ctl->btmp_size - 1; do { if (!strncmp(username, ctl->btmp[n].ut_user, - len < UT_NAMESIZE ? len : UT_NAMESIZE)) + sizeof(ctl->wtmp[0].ut_user))) return ctl->btmp + n; }while (n--); return NULL; -- 2.47.3