From 570a68c586733e1b590ce17e9bbd9854371bb2d0 Mon Sep 17 00:00:00 2001 From: javalsai Date: Wed, 27 Aug 2025 22:21:21 +0200 Subject: [PATCH] fix: satify all clang code requirements --- Makefile | 4 ++-- include/pam.h | 8 ++++---- src/desktop.c | 1 + src/pam.c | 31 ++++++++++++++----------------- src/sessions.c | 1 + 5 files changed, 22 insertions(+), 23 deletions(-) diff --git a/Makefile b/Makefile index 5d34097..5e0e561 100644 --- a/Makefile +++ b/Makefile @@ -138,8 +138,8 @@ pre-commit: prettier -c "**/*.md" git ls-files "*.sh" "*/PKGBUILD" | xargs shellcheck --shell=bash clang-format -i $$(git ls-files "*.c" "*.h") - git ls-files -z "*.h" | \ - parallel -j$$(nproc) -q0 --no-notice --will-cite --tty clang-tidy --quiet |& \ + git ls-files -z "*.c" "*.h" | \ + parallel -j$$(nproc) -q0 --no-notice --will-cite --tty clang-tidy -warnings-as-errors=\* --quiet |& \ grep -v "warnings generated." || true print-version: diff --git a/include/pam.h b/include/pam.h index 5210da3..80a3a76 100644 --- a/include/pam.h +++ b/include/pam.h @@ -17,17 +17,17 @@ struct pamh_getenv_status { char error_flag; union { - char** envlist; - const char* errfn; + char* NULLABLE* NNULLABLE envlist; + const char* NNULLABLE errfn; }; }; // Doesn't include `source`s -struct pamh_getenv_status pamh_get_complete_env(pam_handle_t* handle, +struct pamh_getenv_status pamh_get_complete_env(pam_handle_t* NNULLABLE handle, struct passwd* NNULLABLE pw, enum SessionType session_typ); -void free_envlist(char** NNULLABLE envlist); +void free_envlist(char* NULLABLE* NNULLABLE envlist); pam_handle_t* NULLABLE get_pamh(char* NNULLABLE user, char* NNULLABLE passwd); #endif /* PAM_H */ diff --git a/src/desktop.c b/src/desktop.c index 3499323..dce69bd 100644 --- a/src/desktop.c +++ b/src/desktop.c @@ -19,6 +19,7 @@ char* trim_str(char* str) { return str; } +// NOLINTNEXTLINE(readability-function-cognitive-complexity) int read_desktop(FILE* fd, void* ctx, struct status (*cb)(void* ctx, char* table, char* key, char* value)) { diff --git a/src/pam.c b/src/pam.c index 4af5942..bd3edee 100644 --- a/src/pam.c +++ b/src/pam.c @@ -76,24 +76,20 @@ char* NULLABLE xdg_ssession_type_str(enum SessionType typ) { return xdg_session_type; } -#define FAIL_ALLOC(status) \ - { \ - (status).error_flag = PAMH_ERR_ALLOC; \ - return (status); \ +#define FAIL_ALLOC() \ + { \ + return (struct pamh_getenv_status){.error_flag = PAMH_ERR_ALLOC}; \ } -#define FAIL(status, ERR, ERRFN) \ - { \ - (status).error_flag = (ERR); \ - (status).errfn = (ERRFN); \ - return (status); \ +#define FAIL(ERR, ERRFN) \ + { \ + return (struct pamh_getenv_status){.error_flag = (ERR), .errfn = (ERRFN)}; \ } struct pamh_getenv_status pamh_get_complete_env(pam_handle_t* handle, struct passwd* NNULLABLE pw, enum SessionType session_typ) { - struct pamh_getenv_status status; - char** envlist = pam_getenvlist(handle); - if (!envlist) FAIL(status, PAMH_ERR_ERRNO, "pam_getenvlist"); + char** raw_envlist = pam_getenvlist(handle); + if (!raw_envlist) FAIL(PAMH_ERR_ERRNO, "pam_getenvlist"); struct envpair extra_env[] = { {"TERM", getenv("TERM")}, @@ -104,11 +100,12 @@ struct pamh_getenv_status pamh_get_complete_env(pam_handle_t* handle, {"LOGNAME", pw->pw_name}, {"XDG_SESSION_TYPE", xdg_ssession_type_str(session_typ)}}; - status.error_flag = PAMH_ERR_NOERR; - status.envlist = merge_envlist(envlist, extra_env, LEN(extra_env)); - if (!status.envlist) FAIL_ALLOC(status); - - return status; + char** envlist = merge_envlist(raw_envlist, extra_env, LEN(extra_env)); + if (!envlist) FAIL_ALLOC(); + return (struct pamh_getenv_status){ + .error_flag = PAMH_ERR_NOERR, + .envlist = envlist, + }; } #undef FAIL diff --git a/src/sessions.c b/src/sessions.c index 5707da5..2372f25 100644 --- a/src/sessions.c +++ b/src/sessions.c @@ -118,6 +118,7 @@ static int fn(const char* fpath, const struct stat* sb, int typeflag) { int parse_status = parse_exec_string(ctx.exec, &arg_count, &args); if (parse_status != 0 || arg_count == 0 || !args[0]) { log_printf("[E] parsing exec string '%s': %d\n", ctx.exec, parse_status); + free(this_session); goto err_parsing; } free(ctx.exec);