From: Ruediger Meier <ruediger.meier@xxxxxxxxxxx> 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 <ooprala@xxxxxxxxxx> Signed-off-by: Ruediger Meier <ruediger.meier@xxxxxxxxxxx> --- 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 78d4ed4..4109876 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; -- 1.8.5.6 -- 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