From: Jonathan McDowell Date: Thu, 14 Sep 2023 08:20:10 +0000 (+0530) Subject: Mark unused function parameters X-Git-Tag: onak-0.6.3~22 X-Git-Url: https://the.earth.li/gitweb/?a=commitdiff_plain;h=9d8830c7ea9fd00ded77072cdfd333c5c4e39813;p=onak.git Mark unused function parameters Do a pass-through with "gcc -Werror -Wunused-parameter" and mark up all the unused function parameters (and remove a few unused variables). Also add a CMake check to ensure we have __attribute__((unused)) available to us. --- diff --git a/CMakeLists.txt b/CMakeLists.txt index f755cf4..30e5929 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -23,6 +23,21 @@ option(KEYD set(CMAKE_POSITION_INDEPENDENT_CODE ON) TEST_BIG_ENDIAN(WORDS_BIGENDIAN) +include(CheckCSourceCompiles) +check_c_source_compiles( + " + #include + static void f(__attribute__((unused))) {} + int main(void) { f(); return 0;} + " + HAVE___ATTRIBUTE__UNUSED +) +if (HAVE___ATTRIBUTE__UNUSED) + set(UNUSED_ATTRIB "__attribute__((unused))") +else() + set(UNUSED_ATTRIB "") +endif() + # Pick up a git based version number for development builds find_package(Git) if (GIT_FOUND AND EXISTS "${CMAKE_SOURCE_DIR}/.git") diff --git a/build-config.h.in b/build-config.h.in index 7da2d83..9d08234 100644 --- a/build-config.h.in +++ b/build-config.h.in @@ -11,4 +11,6 @@ #cmakedefine HAVE_SYSTEMD 1 #cmakedefine WORDS_BIGENDIAN 1 +#define __unused @UNUSED_ATTRIB@ + #endif /* __CONFIG_H__ */ diff --git a/cgi/hashquery.c b/cgi/hashquery.c index a8ca3d0..84efe97 100644 --- a/cgi/hashquery.c +++ b/cgi/hashquery.c @@ -23,6 +23,7 @@ #include #include +#include "build-config.h" #include "charfuncs.h" #include "cleanup.h" #include "keydb.h" @@ -40,7 +41,7 @@ void doerror(char *error) exit(EXIT_FAILURE); } -int main(int argc, char *argv[]) +int main(__unused int argc, __unused char *argv[]) { char *request_method, *env; int count, found, i; diff --git a/cgi/lookup.c b/cgi/lookup.c index 5977ad0..632a0a8 100644 --- a/cgi/lookup.c +++ b/cgi/lookup.c @@ -50,7 +50,7 @@ void find_keys(struct onak_dbctx *dbctx, char *search, uint64_t keyid, struct openpgp_fingerprint *fingerprint, bool ishex, bool isfp, bool dispfp, bool skshash, - bool exact, bool verbose, bool mrhkp) + __unused bool exact, bool verbose, bool mrhkp) { struct openpgp_publickey *publickey = NULL; int count = 0; diff --git a/charfuncs.c b/charfuncs.c index 49b6801..3aee0b0 100644 --- a/charfuncs.c +++ b/charfuncs.c @@ -20,6 +20,7 @@ #include #include +#include "build-config.h" #include "charfuncs.h" /* @@ -94,7 +95,7 @@ int file_putchar(void *fd, size_t count, void *c) /* * Gets a char from stdin. */ -int stdin_getchar(void *ctx, size_t count, void *c) +int stdin_getchar(__unused void *ctx, size_t count, void *c) { return (fread(c, 1, count, stdin) != count); } @@ -102,7 +103,7 @@ int stdin_getchar(void *ctx, size_t count, void *c) /* * Puts a char to stdout. */ -int stdout_putchar(void *ctx, size_t count, void *c) +int stdout_putchar(__unused void *ctx, size_t count, void *c) { return (fwrite(c, 1, count, stdout) != count); } diff --git a/keydb/keydb_db4.c b/keydb/keydb_db4.c index d9c45a9..35fcdd1 100644 --- a/keydb/keydb_db4.c +++ b/keydb/keydb_db4.c @@ -31,6 +31,7 @@ #include +#include "build-config.h" #include "charfuncs.h" #include "keyarray.h" #include "keydb.h" @@ -92,7 +93,7 @@ DB *keydb_fp(struct onak_db4_dbctx *privctx, struct openpgp_fingerprint *fp) #if (DB_VERSION_MAJOR == 4) && (DB_VERSION_MINOR < 3) static void db4_errfunc(const char *errpfx, const char *errmsg) #else -static void db4_errfunc(const DB_ENV *edbenv, const char *errpfx, +static void db4_errfunc(__unused const DB_ENV *edbenv, const char *errpfx, const char *errmsg) #endif { diff --git a/keydb/keydb_file.c b/keydb/keydb_file.c index 91b42c5..8989d3c 100644 --- a/keydb/keydb_file.c +++ b/keydb/keydb_file.c @@ -28,6 +28,7 @@ #include #include +#include "build-config.h" #include "charfuncs.h" #include "key-store.h" #include "keydb.h" @@ -44,7 +45,7 @@ * * This is just a no-op for flat file access. */ -static bool file_starttrans(struct onak_dbctx *dbctx) +static bool file_starttrans(__unused struct onak_dbctx *dbctx) { return true; } @@ -54,7 +55,7 @@ static bool file_starttrans(struct onak_dbctx *dbctx) * * This is just a no-op for flat file access. */ -static void file_endtrans(struct onak_dbctx *dbctx) +static void file_endtrans(__unused struct onak_dbctx *dbctx) { return; } @@ -74,7 +75,7 @@ static void file_endtrans(struct onak_dbctx *dbctx) static int file_fetch_key_id(struct onak_dbctx *dbctx, uint64_t keyid, struct openpgp_publickey **publickey, - bool intrans) + __unused bool intrans) { char *db_dir = (char *) dbctx->priv; struct openpgp_packet_list *packets = NULL; @@ -106,8 +107,8 @@ static int file_fetch_key_id(struct onak_dbctx *dbctx, * the file. */ static int file_store_key(struct onak_dbctx *dbctx, - struct openpgp_publickey *publickey, bool intrans, - bool update) + struct openpgp_publickey *publickey, __unused bool intrans, + __unused bool update) { char *db_dir = (char *) dbctx->priv; struct openpgp_packet_list *packets = NULL; @@ -149,7 +150,7 @@ static int file_store_key(struct onak_dbctx *dbctx, * are using. Returns 0 if the key existed. */ static int file_delete_key(struct onak_dbctx *dbctx, - struct openpgp_fingerprint *fp, bool intrans) + struct openpgp_fingerprint *fp, __unused bool intrans) { char *db_dir = (char *) dbctx->priv; char keyfile[1024]; @@ -170,9 +171,9 @@ static int file_delete_key(struct onak_dbctx *dbctx, * * TODO: Write for flat file access. Some sort of grep? */ -static int file_fetch_key_text(struct onak_dbctx *dbctx, - const char *search, - struct openpgp_publickey **publickey) +static int file_fetch_key_text(__unused struct onak_dbctx *dbctx, + __unused const char *search, + __unused struct openpgp_publickey **publickey) { return 0; } @@ -265,7 +266,8 @@ static void file_cleanupdb(struct onak_dbctx *dbctx) * * This is just a no-op for flat file access. */ -struct onak_dbctx *keydb_file_init(struct onak_db_config *dbcfg, bool readonly) +struct onak_dbctx *keydb_file_init(struct onak_db_config *dbcfg, + __unused bool readonly) { struct onak_dbctx *dbctx; diff --git a/keydb/keydb_fs.c b/keydb/keydb_fs.c index 565cfe8..921c978 100644 --- a/keydb/keydb_fs.c +++ b/keydb/keydb_fs.c @@ -622,9 +622,10 @@ static int fs_fetch_key_skshash(struct onak_dbctx *dbctx, * * Returns the number of keys we iterated over. */ -static int fs_iterate_keys(struct onak_dbctx *dbctx, - void (*iterfunc)(void *ctx, - struct openpgp_publickey *key), void *ctx) +static int fs_iterate_keys(__unused struct onak_dbctx *dbctx, + __unused void (*iterfunc)(void *ctx, + struct openpgp_publickey *key), + __unused void *ctx) { return 0; } diff --git a/keydb/keydb_hkp.c b/keydb/keydb_hkp.c index ab33f49..fd235d3 100644 --- a/keydb/keydb_hkp.c +++ b/keydb/keydb_hkp.c @@ -107,7 +107,7 @@ static size_t hkp_curl_recv_data(void *buffer, size_t size, size_t nmemb, static int hkp_fetch_key_url(struct onak_dbctx *dbctx, char *url, struct openpgp_publickey **publickey, - bool intrans) + __unused bool intrans) { struct onak_hkp_dbctx *privctx = (struct onak_hkp_dbctx *) dbctx->priv; struct openpgp_packet_list *packets = NULL; @@ -149,7 +149,7 @@ static int hkp_fetch_key_url(struct onak_dbctx *dbctx, static int hkp_fetch_key_fp(struct onak_dbctx *dbctx, struct openpgp_fingerprint *fingerprint, struct openpgp_publickey **publickey, - bool intrans) + __unused bool intrans) { struct onak_hkp_dbctx *privctx = (struct onak_hkp_dbctx *) dbctx->priv; char keyurl[1024]; @@ -223,8 +223,9 @@ static int hkp_fetch_key_text(struct onak_dbctx *dbctx, * */ static int hkp_store_key(struct onak_dbctx *dbctx, - struct openpgp_publickey *publickey, bool intrans, - bool update) + struct openpgp_publickey *publickey, + __unused bool intrans, + __unused bool update) { struct onak_hkp_dbctx *privctx = (struct onak_hkp_dbctx *) dbctx->priv; struct openpgp_packet_list *packets = NULL; @@ -276,8 +277,8 @@ static int hkp_store_key(struct onak_dbctx *dbctx, * * No op for HKP. */ -static int hkp_delete_key(struct onak_dbctx *dbctx, - struct openpgp_fingerprint *fp, bool intrans) +static int hkp_delete_key(__unused struct onak_dbctx *dbctx, + __unused struct openpgp_fingerprint *fp, __unused bool intrans) { return -1; } @@ -289,9 +290,9 @@ static int hkp_delete_key(struct onak_dbctx *dbctx, * * Not applicable for HKP backend. */ -static int hkp_iterate_keys(struct onak_dbctx *dbctx, - void (*iterfunc)(void *ctx, struct openpgp_publickey *key), - void *ctx) +static int hkp_iterate_keys(__unused struct onak_dbctx *dbctx, + __unused void (*iterfunc)(void *ctx, struct openpgp_publickey *key), + __unused void *ctx) { return 0; } @@ -301,7 +302,7 @@ static int hkp_iterate_keys(struct onak_dbctx *dbctx, * * This is just a no-op for HKP access. */ -static bool hkp_starttrans(struct onak_dbctx *dbctx) +static bool hkp_starttrans(__unused struct onak_dbctx *dbctx) { return true; } @@ -311,7 +312,7 @@ static bool hkp_starttrans(struct onak_dbctx *dbctx) * * This is just a no-op for HKP access. */ -static void hkp_endtrans(struct onak_dbctx *dbctx) +static void hkp_endtrans(__unused struct onak_dbctx *dbctx) { return; } @@ -348,7 +349,8 @@ static void hkp_cleanupdb(struct onak_dbctx *dbctx) * * We initialize CURL here. */ -struct onak_dbctx *keydb_hkp_init(struct onak_db_config *dbcfg, bool readonly) +struct onak_dbctx *keydb_hkp_init(struct onak_db_config *dbcfg, + __unused bool readonly) { struct onak_dbctx *dbctx; struct onak_hkp_dbctx *privctx; diff --git a/keydb/keydb_keyd.c b/keydb/keydb_keyd.c index baf04e1..05b1487 100644 --- a/keydb/keydb_keyd.c +++ b/keydb/keydb_keyd.c @@ -28,6 +28,7 @@ #include #include +#include "build-config.h" #include "charfuncs.h" #include "keyd.h" #include "keydb.h" @@ -46,7 +47,7 @@ * operations on the database to help speed it all up, or if we want * something to only succeed if all relevant operations are successful. */ -static bool keyd_starttrans(struct onak_dbctx *dbctx) +static bool keyd_starttrans(__unused struct onak_dbctx *dbctx) { return true; } @@ -56,7 +57,7 @@ static bool keyd_starttrans(struct onak_dbctx *dbctx) * * Ends a transaction. */ -static void keyd_endtrans(struct onak_dbctx *dbctx) +static void keyd_endtrans(__unused struct onak_dbctx *dbctx) { return; } @@ -95,7 +96,7 @@ static bool keyd_send_cmd(int fd, enum keyd_ops _cmd) static int keyd_fetch_key(struct onak_dbctx *dbctx, struct openpgp_fingerprint *fingerprint, struct openpgp_publickey **publickey, - bool intrans) + __unused bool intrans) { int keyd_fd = (intptr_t) dbctx->priv; struct buffer_ctx keybuf; @@ -144,7 +145,7 @@ static int keyd_fetch_key(struct onak_dbctx *dbctx, static int keyd_fetch_key_fp(struct onak_dbctx *dbctx, struct openpgp_fingerprint *fingerprint, struct openpgp_publickey **publickey, - bool intrans) + __unused bool intrans) { int keyd_fd = (intptr_t) dbctx->priv; struct buffer_ctx keybuf; @@ -193,7 +194,7 @@ static int keyd_fetch_key_fp(struct onak_dbctx *dbctx, static int keyd_fetch_key_id(struct onak_dbctx *dbctx, uint64_t keyid, struct openpgp_publickey **publickey, - bool intrans) + __unused bool intrans) { int keyd_fd = (intptr_t) dbctx->priv; struct buffer_ctx keybuf; @@ -241,7 +242,8 @@ static int keyd_fetch_key_id(struct onak_dbctx *dbctx, * are using. Returns 0 if the key existed. */ static int keyd_delete_key(struct onak_dbctx *dbctx, - struct openpgp_fingerprint *fp, bool intrans) + struct openpgp_fingerprint *fp, + __unused bool intrans) { int keyd_fd = (intptr_t) dbctx->priv; @@ -267,7 +269,8 @@ static int keyd_delete_key(struct onak_dbctx *dbctx, * it? */ static int keyd_store_key(struct onak_dbctx *dbctx, - struct openpgp_publickey *publickey, bool intrans, + struct openpgp_publickey *publickey, + __unused bool intrans, bool update) { int keyd_fd = (intptr_t) dbctx->priv; @@ -527,7 +530,8 @@ static void keyd_cleanupdb(struct onak_dbctx *dbctx) * this file are called in order to allow the DB to be initialized ready * for access. */ -struct onak_dbctx *keydb_keyd_init(struct onak_db_config *dbcfg, bool readonly) +struct onak_dbctx *keydb_keyd_init(struct onak_db_config *dbcfg, + __unused bool readonly) { struct sockaddr_un sock; uint32_t cmd = KEYD_CMD_UNKNOWN; diff --git a/keydb/keydb_keyring.c b/keydb/keydb_keyring.c index 8e4790f..7f6d494 100644 --- a/keydb/keydb_keyring.c +++ b/keydb/keydb_keyring.c @@ -29,6 +29,7 @@ #include #include +#include "build-config.h" #include "charfuncs.h" #include "keyarray.h" #include "keydb.h" @@ -57,7 +58,7 @@ struct onak_keyring_dbctx { * * This is just a no-op for keyring file access. */ -static bool keyring_starttrans(struct onak_dbctx *dbctx) +static bool keyring_starttrans(__unused struct onak_dbctx *dbctx) { return true; } @@ -67,7 +68,7 @@ static bool keyring_starttrans(struct onak_dbctx *dbctx) * * This is just a no-op for keyring file access. */ -static void keyring_endtrans(struct onak_dbctx *dbctx) +static void keyring_endtrans(__unused struct onak_dbctx *dbctx) { return; } @@ -104,7 +105,7 @@ static int keyring_fetch_key_idx(struct onak_keyring_dbctx *privctx, static int keyring_fetch_key(struct onak_dbctx *dbctx, struct openpgp_fingerprint *fingerprint, struct openpgp_publickey **publickey, - bool intrans) + __unused bool intrans) { struct onak_keyring_dbctx *privctx = (struct onak_keyring_dbctx *) dbctx->priv; @@ -131,7 +132,7 @@ static int keyring_fetch_key(struct onak_dbctx *dbctx, static int keyring_fetch_key_id(struct onak_dbctx *dbctx, uint64_t keyid, struct openpgp_publickey **publickey, - bool intrans) + __unused bool intrans) { struct onak_keyring_dbctx *privctx = (struct onak_keyring_dbctx *) dbctx->priv; @@ -156,9 +157,10 @@ static int keyring_fetch_key_id(struct onak_dbctx *dbctx, * * We don't support storing keys into a keyring file. */ -static int keyring_store_key(struct onak_dbctx *dbctx, - struct openpgp_publickey *publickey, bool intrans, - bool update) +static int keyring_store_key(__unused struct onak_dbctx *dbctx, + __unused struct openpgp_publickey *publickey, + __unused bool intrans, + __unused bool update) { return 0; } @@ -170,8 +172,8 @@ static int keyring_store_key(struct onak_dbctx *dbctx, * * We don't support removing keys from a keyring file. */ -static int keyring_delete_key(struct onak_dbctx *dbctx, - struct openpgp_fingerprint *fp, bool intrans) +static int keyring_delete_key(__unused struct onak_dbctx *dbctx, + __unused struct openpgp_fingerprint *fp, __unused bool intrans) { return 1; } @@ -186,9 +188,9 @@ static int keyring_delete_key(struct onak_dbctx *dbctx, * * TODO: Write for flat file access. Some sort of grep? */ -static int keyring_fetch_key_text(struct onak_dbctx *dbctx, - const char *search, - struct openpgp_publickey **publickey) +static int keyring_fetch_key_text(__unused struct onak_dbctx *dbctx, + __unused const char *search, + __unused struct openpgp_publickey **publickey) { return 0; } @@ -225,11 +227,11 @@ static int keyring_iterate_keys(struct onak_dbctx *dbctx, return count; } -static int keyring_update_keys(struct onak_dbctx *dbctx, - struct openpgp_publickey **keys, - struct keyarray *blacklist, - bool updateonly, - bool sendsync) +static int keyring_update_keys(__unused struct onak_dbctx *dbctx, + __unused struct openpgp_publickey **keys, + __unused struct keyarray *blacklist, + __unused bool updateonly, + __unused bool sendsync) { return 0; } @@ -379,7 +381,7 @@ static void keyring_cleanupdb(struct onak_dbctx *dbctx) * This is just a no-op for flat file access. */ struct onak_dbctx *keydb_keyring_init(struct onak_db_config *dbcfg, - bool readonly) + __unused bool readonly) { struct onak_keyring_dbctx *privctx; struct onak_dbctx *dbctx; diff --git a/keydb/keydb_pg.c b/keydb/keydb_pg.c index 1b58c1a..c8392f7 100644 --- a/keydb/keydb_pg.c +++ b/keydb/keydb_pg.c @@ -28,6 +28,7 @@ #include #include +#include "build-config.h" #include "hash.h" #include "keydb.h" #include "keyid.h" @@ -671,7 +672,8 @@ static void pg_cleanupdb(struct onak_dbctx *dbctx) * this file are called in order to allow the DB to be initialized ready * for access. */ -struct onak_dbctx *keydb_pg_init(struct onak_db_config *dbcfg, bool readonly) +struct onak_dbctx *keydb_pg_init(struct onak_db_config *dbcfg, + __unused bool readonly) { struct onak_dbctx *dbctx; PGconn *dbconn; diff --git a/sigcheck.c b/sigcheck.c index 2c1fc4c..74c2e2b 100644 --- a/sigcheck.c +++ b/sigcheck.c @@ -116,7 +116,7 @@ static void onak_free_key_material(struct onak_key_material *key) static onak_status_t onak_parse_key_material(struct openpgp_packet *pk, struct onak_key_material *key) { - int i, len, ofs; + int len, ofs; enum onak_oid oid; mpz_t x, y; onak_status_t ret = ONAK_E_OK; @@ -288,7 +288,6 @@ onak_status_t onak_check_hash_sig(struct openpgp_publickey *sigkey, struct dsa_signature dsasig; uint8_t sigkeytype; uint8_t edsig[64]; - uint64_t keyid; int len, ofs; mpz_t s; @@ -530,7 +529,6 @@ onak_status_t calculate_packet_sighash(struct openpgp_publickey *key, uint8_t keyheader[5]; uint8_t packetheader[5]; uint8_t trailer[10]; - int i; uint64_t keyid; onak_status_t res;