From: Ruediger Meier Date: Thu, 1 Dec 2016 08:52:06 +0000 (+0100) Subject: lslogins: remove useless strlen() X-Git-Tag: v2.30-rc1~372 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=77f5a945868e9a2bf9fe71bfdbe8bf54a2441699;p=thirdparty%2Futil-linux.git 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 --- 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;