From dae1ad0fc1cd83e06ac69b26c3ccea34f6556019 Mon Sep 17 00:00:00 2001 From: Russ Allbery Date: Mon, 25 Dec 2023 13:29:50 -0800 Subject: [PATCH] Fix cppcheck errors Fix a few legitimate cppcheck errors and suppress three new false positives due to cppcheck apparently misparsing noreturn annotations. --- plugin/classes.c | 4 ++-- plugin/heimdal.c | 4 ++-- plugin/sqlite.c | 2 +- tests/data/cppcheck.supp | 9 +++++++-- tests/tap/kerberos.c | 4 ++-- 5 files changed, 14 insertions(+), 9 deletions(-) diff --git a/plugin/classes.c b/plugin/classes.c index f7c985a..ed6c76a 100644 --- a/plugin/classes.c +++ b/plugin/classes.c @@ -4,7 +4,7 @@ * Checks whether the password satisfies a set of character class rules. * * Written by Russ Allbery - * Copyright 2016 Russ Allbery + * Copyright 2016, 2023 Russ Allbery * Copyright 2013-2014 * The Board of Trustees of the Leland Stanford Junior University * @@ -66,7 +66,7 @@ analyze_password(const char *password, struct password_classes *classes) */ static krb5_error_code check_rule(krb5_context ctx, struct class_rule *rule, size_t length, - struct password_classes *classes) + const struct password_classes *classes) { if (length < rule->min || (rule->max > 0 && length > rule->max)) return 0; diff --git a/plugin/heimdal.c b/plugin/heimdal.c index 0ca38b4..8ace00a 100644 --- a/plugin/heimdal.c +++ b/plugin/heimdal.c @@ -61,8 +61,8 @@ convert_error(krb5_context ctx, krb5_error_code code, const char *prefix, */ static int heimdal_pwcheck(krb5_context ctx, krb5_principal principal, - krb5_data *password, const char *tuning UNUSED, - char *message, size_t length) + krb5_data *password, const char *tuning UNUSED, char *message, + size_t length) { krb5_pwqual_moddata data = NULL; char *pastring; diff --git a/plugin/sqlite.c b/plugin/sqlite.c index db73aef..fae8a63 100644 --- a/plugin/sqlite.c +++ b/plugin/sqlite.c @@ -147,7 +147,7 @@ common_prefix_length(const char *a, const char *b) { size_t i; - for (i = 0; a[i] == b[i] && a[i] != '\0' && b[i] != '\0'; i++) + for (i = 0; a[i] == b[i] && a[i] != '\0'; i++) ; return i; } diff --git a/tests/data/cppcheck.supp b/tests/data/cppcheck.supp index c9f8ff1..257cece 100644 --- a/tests/data/cppcheck.supp +++ b/tests/data/cppcheck.supp @@ -1,4 +1,4 @@ -// Suppressions file for cppcheck. -*- conf -*- +// Suppressions file for cppcheck. // // This includes suppressions for all of my projects, including files that // aren't in rra-c-util, for ease of sharing between projects. The ones that @@ -8,7 +8,7 @@ // with the --xml flag and then add a suppression for the error id, file // location, and line. // -// Copyright 2018-2022 Russ Allbery +// Copyright 2018-2023 Russ Allbery // // Copying and distribution of this file, with or without modification, are // permitted in any medium without royalty provided the copyright notice and @@ -51,6 +51,11 @@ nullPointerRedundantCheck:portable/krb5-profile.c:61 nullPointerRedundantCheck:portable/krb5-renew.c:82 nullPointerRedundantCheck:portable/krb5-renew.c:83 +// (krb5-strength) Bug in cppcheck 2.12.0. +nullPointerRedundantCheck:tests/plugin/heimdal-t.c:81 +nullPointerRedundantCheck:tests/plugin/mit-t.c:91 +nullPointerRedundantCheck:tests/plugin/mit-t.c:97 + // Setting the variable to NULL explicitly after deallocation. redundantAssignment:tests/pam-util/options-t.c diff --git a/tests/tap/kerberos.c b/tests/tap/kerberos.c index ae571dc..5e97f07 100644 --- a/tests/tap/kerberos.c +++ b/tests/tap/kerberos.c @@ -15,7 +15,7 @@ * which can be found at . * * Written by Russ Allbery - * Copyright 2017, 2022 Russ Allbery + * Copyright 2017, 2022, 2023 Russ Allbery * Copyright 2006-2007, 2009-2014 * The Board of Trustees of the Leland Stanford Junior University * @@ -167,7 +167,7 @@ kerberos_kinit(void) char *path; char principal[BUFSIZ], *command; size_t i; - int status; + int status = 0; /* Read the principal corresponding to the keytab. */ path = test_file_path("config/principal"); -- 2.39.2