launch/nss-cache: avoid macro repetition
Avoid repetition of the C_ARRAY_SIZE() macro and use a local constant
instead. This silences warnings of gcc which otherwise cannot detect the
early function return for `n_usernames == 0`.
@@ -493,22 +493,23 @@ int nss_cache_get_gid(NSSCache *cache, uint32_t *gidp, const char *name) {
int nss_cache_resolve_system_console_users(NSSCache *nss_cache, uint32_t **uidsp, size_t *n_uidsp) {
static const char * const usernames[] = { SYSTEM_CONSOLE_USERS };
+ static const size_t n_usernames = C_ARRAY_SIZE(usernames);
_c_cleanup_(c_freep) uint32_t *uids = NULL;
size_t i, n_uids = 0;
uid_t uid;
int r;
- if (!C_ARRAY_SIZE(usernames)) {
+ if (!n_usernames) {
*uidsp = NULL;
*n_uidsp = 0;
return 0;
}
- uids = calloc(C_ARRAY_SIZE(usernames), sizeof(*uids));
+ uids = calloc(n_usernames, sizeof(*uids));
if (!uids)
return error_origin(-ENOMEM);
- for (i = 0; i < C_ARRAY_SIZE(usernames); ++i) {
+ for (i = 0; i < n_usernames; ++i) {
r = nss_cache_get_uid(nss_cache, &uid, NULL, usernames[i]);
if (r) {
if (r == NSS_CACHE_E_INVALID_NAME)
