From f22ca217cdcdde5eae610b2fd982a93252c30f86 Mon Sep 17 00:00:00 2001 From: Alejandro Colomar Date: Mon, 5 Feb 2024 12:40:51 +0100 Subject: [PATCH] lib/chkname.c: is_valid_user_name(): Avoid a cast By using a temporary vairable, we can remove a cast. Reviewed-by: Iker Pedrosa Cc: Tobias Stoeckmann Cc: Serge Hallyn Signed-off-by: Alejandro Colomar --- lib/chkname.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/lib/chkname.c b/lib/chkname.c index 79fa29c36..fbd6ba889 100644 --- a/lib/chkname.c +++ b/lib/chkname.c @@ -76,17 +76,21 @@ static bool is_valid_name (const char *name) bool is_valid_user_name(const char *name) { - long maxsize; + long conf; + size_t maxsize; errno = 0; - maxsize = sysconf(_SC_LOGIN_NAME_MAX); - if (maxsize == -1 && errno != 0) + conf = sysconf(_SC_LOGIN_NAME_MAX); + + if (conf == -1 && errno != 0) maxsize = LOGIN_NAME_MAX; + else + maxsize = conf; - if (strlen(name) >= (size_t)maxsize) + if (strlen(name) >= maxsize) return false; - return is_valid_name (name); + return is_valid_name(name); }