From d7190c222ff360d4e72ee5b103fd16c5b9a317a2 Mon Sep 17 00:00:00 2001 From: Luca Saiu Date: Tue, 9 Nov 2021 16:44:48 +0100 Subject: [PATCH] ENGINE-975: silence compiler warnings... ...at least under src. There should be much less noise about non-problems now. --- Makefile.conf | 8 +- codegen/gen_statemachine.ysl2 | 7 +- src/Makefile | 14 +-- src/engine_sql.c | 7 +- src/engine_sql.h | 200 +++++++++++++++++----------------- src/keymanagement.c | 3 +- src/map_asn1.c | 1 + src/message_api.c | 7 +- src/pgp_sequoia.c | 17 ++- src/platform_windows.h | 9 ++ 10 files changed, 151 insertions(+), 122 deletions(-) diff --git a/Makefile.conf b/Makefile.conf index c1fadb4e..414ad310 100644 --- a/Makefile.conf +++ b/Makefile.conf @@ -295,12 +295,14 @@ SEQUOIA_INC= # EXTRA_MACROS=-DDEFAULT_KEYSERVER=\"default-server.org\" -DCRASHDUMP_DEFAULT_LINES=23 EXTRA_MACROS= +# Notice the single quotes below: since user definitions can contain dollar +# signs it is important to prevent their expansion: shell variable references +# here must be expanded at run time, and not at compile time. ifdef PER_USER_DIRECTORY - EXTRA_MACROS+= -DPER_USER_DIRECTORY=\"$(PER_USER_DIRECTORY)\" + EXTRA_MACROS+= -DPER_USER_DIRECTORY='"$(PER_USER_DIRECTORY)"' endif - ifdef PER_MACHINE_DIRECTORY - EXTRA_MACROS+= -DPER_MACHINE_DIRECTORY=\"$(PER_MACHINE_DIRECTORY)\" + EXTRA_MACROS+= -DPER_MACHINE_DIRECTORY='"$(PER_MACHINE_DIRECTORY)"' endif CFLAGS+=$(EXTRA_MACROS) diff --git a/codegen/gen_statemachine.ysl2 b/codegen/gen_statemachine.ysl2 index 07019b6f..6d63ed46 100644 --- a/codegen/gen_statemachine.ysl2 +++ b/codegen/gen_statemachine.ysl2 @@ -533,8 +533,8 @@ tstylesheet { { PEP_STATUS status = PEP_STATUS_OK; - assert(session && fsm > None && message_type > None); - if (!(session && fsm > None && message_type > None)) + assert(session && (int) fsm > None && message_type > None); + if (!(session && (int) fsm > None && message_type > None)) return PEP_ILLEGAL_VALUE; time_t now = time(NULL); @@ -1653,6 +1653,7 @@ tstylesheet { * @retval PEP_ILLEGAL_VALUE if input error during logging * @retval PEP_STATUS_OK otherwise */ + __attribute__((__unused__)) static PEP_STATUS _«@name»_ERR_LOG_int(PEP_SESSION session, char *t, int n, bool hex) { char *_buf = _str(n, hex); @@ -1677,7 +1678,7 @@ tstylesheet { if (!session) return invalid_state; - if (state == None) + if ((int) state == None) state = «@name»_state_Init; switch (state) { diff --git a/src/Makefile b/src/Makefile index 36b297a2..01309322 100644 --- a/src/Makefile +++ b/src/Makefile @@ -5,17 +5,6 @@ include ../Makefile.conf -# Notice the single quotes below: since user definitions can contain dollar -# signs it is important to prevent their expansion: shell variable references -# here must be expanded at run time, and not at compile time. -ifdef PER_USER_DIRECTORY - EXTRA_MACROS+= -DPER_USER_DIRECTORY='"$(PER_USER_DIRECTORY)"' -endif - -ifdef PER_MACHINE_DIRECTORY - EXTRA_MACROS+= -DPER_MACHINE_DIRECTORY='"$(PER_MACHINE_DIRECTORY)"' -endif - ifneq ($(BUILD_ON),OS/390) LDFLAGS+= -shared endif @@ -155,3 +144,6 @@ uninstall: tags: $(wildcard *.c) $(wildcard *.h) ctags --sort=yes *.c *.h +# FIXME: this is a test I am using to debug the makefile itself +CFLAGS += -Wall -Werror +CXXFLAGS += -Wall -Werror diff --git a/src/engine_sql.c b/src/engine_sql.c index 344fb96d..a71b0ecd 100644 --- a/src/engine_sql.c +++ b/src/engine_sql.c @@ -929,7 +929,7 @@ PEP_STATUS get_db_user_version(PEP_SESSION session, int* version) { static PEP_STATUS _verify_version(PEP_SESSION session, int* version) { // Sometimes the user_version wasn't set correctly. bool version_changed = true; - int int_result; + int int_result __attribute__((__unused__)); if (table_contains_column(session, "identity", "username")) { *version = 17; } @@ -998,7 +998,8 @@ static PEP_STATUS _verify_version(PEP_SESSION session, int* version) { static PEP_STATUS _upgrade_DB_to_ver_2(PEP_SESSION session) { // N.B. addition of device_group column removed in DDL v10 - int int_result = sqlite3_exec( + int int_result __attribute__((__unused__)) + = sqlite3_exec( session->db, "alter table pgp_keypair\n" " add column flags integer default 0;\n", @@ -1653,7 +1654,7 @@ static PEP_STATUS _check_and_execute_upgrades(PEP_SESSION session, int version) } PEP_STATUS pEp_sql_init(PEP_SESSION session) { - bool very_first = false; + bool very_first __attribute__((__unused__)) = false; PEP_STATUS status = create_tables(session); if (status != PEP_STATUS_OK) return status; diff --git a/src/engine_sql.h b/src/engine_sql.h index 25d98ea4..9de7dae7 100644 --- a/src/engine_sql.h +++ b/src/engine_sql.h @@ -10,21 +10,26 @@ PEP_STATUS pEp_sql_init(PEP_SESSION session); PEP_STATUS pEp_prepare_sql_stmts(PEP_SESSION session); PEP_STATUS pEp_finalize_sql_stmts(PEP_SESSION session); +/* The strings below are not always all used in a C file, so it is normal that + a lot of these variables are unused: we do not want warnings, nor complicated + attribute declrations for every variable. */ +#define MAYBE_UNUSED __attribute__((__unused__)) + /** * Strings to feed into prepared statements */ -static const char *sql_log = +static const char *sql_log MAYBE_UNUSED = "insert into log (title, entity, description, comment)" "values (?1, ?2, ?3, ?4);"; -static const char *sql_trustword = +static const char *sql_trustword MAYBE_UNUSED = "select id, word from wordlist where lang = lower(?1) " "and id = ?2 ;"; // FIXME?: problems if we don't have a key for the user - we get nothing // Also: we've never used pgp_keypair.flags before now, but it seems to me that // having combination of those flags is a road to ruin. Changing this for now. -static const char *sql_get_identity = +static const char *sql_get_identity MAYBE_UNUSED = "select identity.main_key_id," " (case when (identity.flags & 1024 = 0) then ifnull(identity.username, person.username) " " else identity.username end)," @@ -45,7 +50,7 @@ static const char *sql_get_identity = " order by is_own desc, " " timestamp desc; "; -static const char *sql_get_identities_by_main_key_id = +static const char *sql_get_identities_by_main_key_id MAYBE_UNUSED = "select address, identity.user_id," " (case when (identity.flags & 1024 = 0) then ifnull(identity.username, person.username) " " else identity.username end)," @@ -61,7 +66,7 @@ static const char *sql_get_identities_by_main_key_id = " order by is_own desc, " " timestamp desc; "; -static const char *sql_get_identity_without_trust_check = +static const char *sql_get_identity_without_trust_check MAYBE_UNUSED = "select identity.main_key_id," " (case when (identity.flags & 1024 = 0) then ifnull(identity.username, person.username) " " else identity.username end)," @@ -77,7 +82,7 @@ static const char *sql_get_identity_without_trust_check = " order by is_own desc, " " timestamp desc; "; -static const char *sql_get_identities_by_address = +static const char *sql_get_identities_by_address MAYBE_UNUSED = "select user_id, identity.main_key_id," " (case when (identity.flags & 1024 = 0) then ifnull(identity.username, person.username) " " else identity.username end)," @@ -92,7 +97,7 @@ static const char *sql_get_identities_by_address = " order by is_own desc, " " timestamp desc; "; -static const char *sql_get_identities_by_userid = +static const char *sql_get_identities_by_userid MAYBE_UNUSED = "select address, identity.main_key_id," " (case when (identity.flags & 1024 = 0) then ifnull(identity.username, person.username) " " else identity.username end)," @@ -108,16 +113,16 @@ static const char *sql_get_identities_by_userid = " order by is_own desc, " " timestamp desc; "; -static const char *sql_replace_identities_fpr = +static const char *sql_replace_identities_fpr MAYBE_UNUSED = "update identity" " set main_key_id = ?1 " " where main_key_id = ?2 ;"; -static const char* sql_set_default_identity_fpr = +static const char* sql_set_default_identity_fpr MAYBE_UNUSED = "update identity set main_key_id = ?3 " " where user_id = ?1 and address = ?2; "; -static const char *sql_get_default_identity_fpr = +static const char *sql_get_default_identity_fpr MAYBE_UNUSED = "select main_key_id from identity" " where (case when (address = ?1) then (1)" " when (lower(address) = lower(?1)) then (1)" @@ -126,19 +131,19 @@ static const char *sql_get_default_identity_fpr = " end) = 1 " " and user_id = ?2 ;"; -static const char *sql_remove_fpr_as_identity_default = +static const char *sql_remove_fpr_as_identity_default MAYBE_UNUSED = "update identity set main_key_id = NULL where main_key_id = ?1 ;"; -static const char *sql_remove_fpr_as_user_default = +static const char *sql_remove_fpr_as_user_default MAYBE_UNUSED = "update person set main_key_id = NULL where main_key_id = ?1 ;"; // Set person, but if already exist, only update. // if main_key_id already set, don't touch. -static const char *sql_set_person = +static const char *sql_set_person MAYBE_UNUSED = "insert into person (id, username, lang, main_key_id)" " values (?1, ?2, ?3, ?4) ;"; -static const char *sql_update_person = +static const char *sql_update_person MAYBE_UNUSED = "update person " " set username = ?2, " " lang = ?3, " @@ -149,46 +154,46 @@ static const char *sql_update_person = " where id = ?1 ;"; // Will cascade. -static const char *sql_delete_person = +static const char *sql_delete_person MAYBE_UNUSED = "delete from person where id = ?1 ;"; -static const char *sql_set_as_pEp_user = +static const char *sql_set_as_pEp_user MAYBE_UNUSED = "update person set is_pEp_user = 1 " " where id = ?1 ; "; -static const char *sql_is_pEp_user = +static const char *sql_is_pEp_user MAYBE_UNUSED = "select is_pEp_user from person " " where id = ?1 ; "; -static const char* sql_exists_person = +static const char* sql_exists_person MAYBE_UNUSED = "select count(*) from person " " where id = ?1 ;"; // This will cascade to identity and trust -static const char* sql_replace_userid = +static const char* sql_replace_userid MAYBE_UNUSED = "update person set id = ?1 " " where id = ?2;"; // Hopefully this cascades and removes trust entries... -static const char *sql_delete_key = +static const char *sql_delete_key MAYBE_UNUSED = "delete from pgp_keypair " " where fpr = ?1 ; "; -static const char *sql_replace_main_user_fpr = +static const char *sql_replace_main_user_fpr MAYBE_UNUSED = "update person " " set main_key_id = ?1 " " where id = ?2 ;"; -static const char *sql_get_main_user_fpr = +static const char *sql_get_main_user_fpr MAYBE_UNUSED = "select main_key_id from person" " where id = ?1 ;"; -static const char *sql_replace_main_user_fpr_if_equal = +static const char *sql_replace_main_user_fpr_if_equal MAYBE_UNUSED = "update person " " set main_key_id = ?1 " " where id = ?2 and main_key_id = ?3;"; -static const char *sql_refresh_userid_default_key = +static const char *sql_refresh_userid_default_key MAYBE_UNUSED = "update person " " set main_key_id = " " (select identity.main_key_id from identity " @@ -200,23 +205,23 @@ static const char *sql_refresh_userid_default_key = " limit 1) " "where id = ?1 ; "; -static const char *sql_set_pgp_keypair = +static const char *sql_set_pgp_keypair MAYBE_UNUSED = "insert or ignore into pgp_keypair (fpr) " "values (upper(replace(?1,' ',''))) ;"; -static const char *sql_set_pgp_keypair_flags = +static const char *sql_set_pgp_keypair_flags MAYBE_UNUSED = "update pgp_keypair set flags = " " ((?1 & 65535) | (select flags from pgp_keypair " " where fpr = (upper(replace(?2,' ',''))))) " " where fpr = (upper(replace(?2,' ',''))) ;"; -static const char *sql_unset_pgp_keypair_flags = +static const char *sql_unset_pgp_keypair_flags MAYBE_UNUSED = "update pgp_keypair set flags = " " ( ~(?1 & 65535) & (select flags from pgp_keypair" " where fpr = (upper(replace(?2,' ',''))))) " " where fpr = (upper(replace(?2,' ',''))) ;"; -static const char* sql_exists_identity_entry = +static const char* sql_exists_identity_entry MAYBE_UNUSED = "select count(*) from identity " " where (case when (address = ?1) then (1)" " when (lower(address) = lower(?1)) then (1)" @@ -225,7 +230,7 @@ static const char* sql_exists_identity_entry = " end) = 1" " and user_id = ?2;"; -static const char *sql_set_identity_entry = +static const char *sql_set_identity_entry MAYBE_UNUSED = "insert into identity (" " address, main_key_id, " " user_id, " @@ -243,7 +248,7 @@ static const char *sql_set_identity_entry = " ?8 " " );"; -static const char* sql_update_identity_entry = +static const char* sql_update_identity_entry MAYBE_UNUSED = "update identity " " set main_key_id = upper(replace(?2,' ','')), " " username = coalesce(username, ?4), " @@ -258,7 +263,7 @@ static const char* sql_update_identity_entry = " end) = 1 " " and user_id = ?3 ;"; -static const char* sql_force_set_identity_username = +static const char* sql_force_set_identity_username MAYBE_UNUSED = "update identity " " set username = coalesce(username, ?3) " " where (case when (address = ?1) then (1)" @@ -278,7 +283,7 @@ static const char* sql_force_set_identity_username = // " ) | (?4 & 255)" /* set_identity ignores previous flags, and doesn't filter machine flags */ -static const char *sql_set_identity_flags = +static const char *sql_set_identity_flags MAYBE_UNUSED = "update identity set flags = " " ((?1 & 65535) | (select flags from identity" " where (case when (address = ?2) then (1)" @@ -294,7 +299,7 @@ static const char *sql_set_identity_flags = " end) = 1" " and user_id = ?3 ;"; -static const char *sql_unset_identity_flags = +static const char *sql_unset_identity_flags MAYBE_UNUSED = "update identity set flags = " " ( ~(?1 & 65535) & (select flags from identity" " where (case when (address = ?2) then (1)" @@ -310,7 +315,7 @@ static const char *sql_unset_identity_flags = " end) = 1" " and user_id = ?3 ;"; -static const char *sql_set_ident_enc_format = +static const char *sql_set_ident_enc_format MAYBE_UNUSED = "update identity " " set enc_format = ?1 " " where (case when (address = ?2) then (1)" @@ -320,7 +325,7 @@ static const char *sql_set_ident_enc_format = " end) = 1 " " and user_id = ?3 ;"; -static const char *sql_set_pEp_version = +static const char *sql_set_pEp_version MAYBE_UNUSED = "update identity " " set pEp_version_major = ?1, " " pEp_version_minor = ?2 " @@ -331,7 +336,7 @@ static const char *sql_set_pEp_version = " end) = 1 " " and user_id = ?4 ;"; -static const char *sql_upgrade_pEp_version_by_user_id = +static const char *sql_upgrade_pEp_version_by_user_id MAYBE_UNUSED = "update identity " " set pEp_version_major = ?1, " " pEp_version_minor = ?2 " @@ -342,19 +347,19 @@ static const char *sql_upgrade_pEp_version_by_user_id = " else 0 " " end) = 1 ;"; -static const char *sql_set_trust = +static const char *sql_set_trust MAYBE_UNUSED = "insert into trust (user_id, pgp_keypair_fpr, comm_type) " "values (?1, upper(replace(?2,' ','')), ?3) ;"; -static const char *sql_update_trust = +static const char *sql_update_trust MAYBE_UNUSED = "update trust set comm_type = ?3 " " where user_id = ?1 and pgp_keypair_fpr = upper(replace(?2,' ',''));"; -static const char *sql_clear_trust_info = +static const char *sql_clear_trust_info MAYBE_UNUSED = "delete from trust " " where user_id = ?1 and pgp_keypair_fpr = upper(replace(?2,' ',''));"; -static const char *sql_update_trust_to_pEp = +static const char *sql_update_trust_to_pEp MAYBE_UNUSED = "update trust set comm_type = comm_type + 71 " " where (user_id = ?1 " " and (case when (comm_type = 56) then (1) " @@ -362,54 +367,54 @@ static const char *sql_update_trust_to_pEp = " else 0" " end) = 1); "; -static const char* sql_exists_trust_entry = +static const char* sql_exists_trust_entry MAYBE_UNUSED = "select count(*) from trust " " where user_id = ?1 and pgp_keypair_fpr = upper(replace(?2,' ',''));"; -static const char *sql_update_trust_for_fpr = +static const char *sql_update_trust_for_fpr MAYBE_UNUSED = "update trust " "set comm_type = ?1 " "where pgp_keypair_fpr = upper(replace(?2,' ','')) ;"; -static const char *sql_get_trust = +static const char *sql_get_trust MAYBE_UNUSED = "select comm_type from trust where user_id = ?1 " "and pgp_keypair_fpr = upper(replace(?2,' ','')) ;"; -static const char *sql_get_trust_by_userid = +static const char *sql_get_trust_by_userid MAYBE_UNUSED = "select pgp_keypair_fpr, comm_type from trust where user_id = ?1 "; -static const char *sql_least_trust = +static const char *sql_least_trust MAYBE_UNUSED = "select min(comm_type) from trust where" " pgp_keypair_fpr = upper(replace(?1,' ',''))" " and comm_type != 0;"; // ignores PEP_ct_unknown // returns PEP_ct_unknown only when no known trust is recorded -static const char *sql_update_key_sticky_bit_for_user = +static const char *sql_update_key_sticky_bit_for_user MAYBE_UNUSED = "update trust set sticky = ?1 " " where user_id = ?2 and pgp_keypair_fpr = upper(replace(?3,' ','')) ;"; -static const char *sql_is_key_sticky_for_user = +static const char *sql_is_key_sticky_for_user MAYBE_UNUSED = "select sticky from trust " " where user_id = ?1 and pgp_keypair_fpr = upper(replace(?2,' ','')) ; "; -static const char *sql_mark_as_compromised = +static const char *sql_mark_as_compromised MAYBE_UNUSED = "update trust not indexed set comm_type = 15" " where pgp_keypair_fpr = upper(replace(?1,' ','')) ;"; -static const char *sql_crashdump = +static const char *sql_crashdump MAYBE_UNUSED = "select timestamp, title, entity, description, comment" " from log order by timestamp desc limit ?1 ;"; -static const char *sql_languagelist = +static const char *sql_languagelist MAYBE_UNUSED = "select i18n_language.lang, name, phrase" " from i18n_language join i18n_token using (lang) where i18n_token.id = 1000;" ; -static const char *sql_i18n_token = +static const char *sql_i18n_token MAYBE_UNUSED = "select phrase from i18n_token where lang = lower(?1) and id = ?2 ;"; // Own keys // We only care if it's 0 or non-zero -static const char *sql_own_key_is_listed = +static const char *sql_own_key_is_listed MAYBE_UNUSED = "select count(*) from (" " select pgp_keypair_fpr from trust" " join identity on trust.user_id = identity.user_id" @@ -417,7 +422,7 @@ static const char *sql_own_key_is_listed = " and identity.is_own = 1" ");"; -static const char *sql_is_own_address = +static const char *sql_is_own_address MAYBE_UNUSED = "select count(*) from (" " select address from identity" " where (case when (address = ?1) then (1)" @@ -428,7 +433,7 @@ static const char *sql_is_own_address = " and identity.is_own = 1" ");"; -static const char *sql_own_identities_retrieve = +static const char *sql_own_identities_retrieve MAYBE_UNUSED = "select address, identity.main_key_id, identity.user_id," " (case when (identity.flags & 1024 = 0) then ifnull(identity.username, person.username) " " else identity.username end)," @@ -443,174 +448,175 @@ static const char *sql_own_identities_retrieve = " where identity.is_own = 1" " and (identity.flags & ?1) = 0;"; -static const char *sql_own_keys_retrieve = +static const char *sql_own_keys_retrieve MAYBE_UNUSED = "select distinct pgp_keypair_fpr from trust" " join identity on trust.user_id = identity.user_id" " where identity.is_own = 1"; -static const char* sql_get_user_default_key = +static const char* sql_get_user_default_key MAYBE_UNUSED = "select main_key_id from person" " where id = ?1;"; -static const char* sql_get_all_keys_for_user = +static const char* sql_get_all_keys_for_user MAYBE_UNUSED = "select pgp_keypair_fpr from trust" " where user_id = ?1; "; -static const char* sql_get_default_own_userid = +static const char* sql_get_default_own_userid MAYBE_UNUSED = "select id from person" " join identity on id = identity.user_id" " where identity.is_own = 1"; // Sequence -static const char *sql_sequence_value1 = +static const char *sql_sequence_value1 MAYBE_UNUSED = "insert or replace into sequences (name, value) " "values (?1, " " (select coalesce((select value + 1 from sequences " " where name = ?1), 1 ))); "; -static const char *sql_sequence_value2 = +static const char *sql_sequence_value2 MAYBE_UNUSED = "select value from sequences where name = ?1 ;"; // Revocation tracking -static const char *sql_set_revoked = +static const char *sql_set_revoked MAYBE_UNUSED = "insert or replace into revoked_keys (" " revoked_fpr, replacement_fpr, revocation_date) " "values (upper(replace(?1,' ',''))," " upper(replace(?2,' ',''))," " ?3) ;"; -static const char *sql_get_revoked = +static const char *sql_get_revoked MAYBE_UNUSED = "select revoked_fpr, revocation_date from revoked_keys" " where replacement_fpr = upper(replace(?1,' ','')) ;"; -static const char *sql_get_replacement_fpr = +static const char *sql_get_replacement_fpr MAYBE_UNUSED = "select replacement_fpr, revocation_date from revoked_keys" " where revoked_fpr = upper(replace(?1,' ','')) ;"; -static const char *sql_get_userid_alias_default = +static const char *sql_get_userid_alias_default MAYBE_UNUSED = "select default_id from alternate_user_id " " where alternate_id = ?1 ; "; // Revocation tracking -static const char *sql_add_mistrusted_key = +static const char *sql_add_mistrusted_key MAYBE_UNUSED = "insert or replace into mistrusted_keys (fpr) " " values (upper(replace(?1,' ',''))) ;"; -static const char *sql_delete_mistrusted_key = +static const char *sql_delete_mistrusted_key MAYBE_UNUSED = "delete from mistrusted_keys where fpr = upper(replace(?1,' ','')) ;"; -static const char *sql_is_mistrusted_key = +static const char *sql_is_mistrusted_key MAYBE_UNUSED = "select count(*) from mistrusted_keys where fpr = upper(replace(?1,' ','')) ;"; -static const char *sql_add_userid_alias = +static const char *sql_add_userid_alias MAYBE_UNUSED = "insert or replace into alternate_user_id (alternate_id, default_id) " "values (?2, ?1) ;"; -static const char *sql_add_into_social_graph = +static const char *sql_add_into_social_graph MAYBE_UNUSED = "insert or replace into social_graph(own_userid, own_address, contact_userid) " "values (?1, ?2, ?3) ;"; -static const char *sql_get_own_address_binding_from_contact = +static const char *sql_get_own_address_binding_from_contact MAYBE_UNUSED = "select own_address from social_graph where own_userid = ?1 and contact_userid = ?2 ;"; -static const char *sql_set_revoke_contact_as_notified = +static const char *sql_set_revoke_contact_as_notified MAYBE_UNUSED = "insert or replace into revocation_contact_list(fpr, own_address, contact_id) values (?1, ?2, ?3) ;"; -static const char *sql_get_contacted_ids_from_revoke_fpr = +static const char *sql_get_contacted_ids_from_revoke_fpr MAYBE_UNUSED = "select * from revocation_contact_list where fpr = ?1 ;"; -static const char *sql_was_id_for_revoke_contacted = +static const char *sql_was_id_for_revoke_contacted MAYBE_UNUSED = "select count(*) from revocation_contact_list where fpr = ?1 and own_address = ?2 and contact_id = ?3 ;"; -static const char *sql_has_id_contacted_address = +static const char *sql_has_id_contacted_address MAYBE_UNUSED = "select count(*) from social_graph where own_address = ?1 and contact_userid = ?2 ;"; // We only need user_id and address, since in the main usage, we'll call update_identity // on this anyway when sending out messages. -static const char *sql_get_last_contacted = +static const char *sql_get_last_contacted MAYBE_UNUSED = "select user_id, address from identity where datetime('now') < datetime(timestamp, '+14 days') ; "; -static const char *sql_create_group = +static const char *sql_create_group MAYBE_UNUSED = "insert into groups (group_id, group_address, manager_userid, manager_address) " "VALUES (?1, ?2, ?3, ?4) ;"; -static const char *sql_enable_group = +static const char *sql_enable_group MAYBE_UNUSED = "update groups set active = 1 " " where group_id = ?1 and group_address = ?2 ;"; -static const char *sql_disable_group = +static const char *sql_disable_group MAYBE_UNUSED = "update groups set active = 0 " " where group_id = ?1 and group_address = ?2 ;"; -static const char *sql_exists_group_entry = +static const char *sql_exists_group_entry MAYBE_UNUSED = "select count(*) from groups " " where group_id = ?1 and group_address = ?2;"; -static const char *sql_group_add_member = +static const char *sql_group_add_member MAYBE_UNUSED = "insert or ignore into own_groups_members (group_id, group_address, member_id, member_address) " " values (?1, ?2, ?3, ?4) ;"; -static const char *sql_group_delete_member = +static const char *sql_group_delete_member MAYBE_UNUSED = "delete from own_groups_members " " where group_id = ?1 and group_address = ?2 and " " member_id = ?3 and member_address = ?4 ;"; -static const char *sql_set_group_member_status = +static const char *sql_set_group_member_status MAYBE_UNUSED = "update own_groups_members set active_member = ?1 " " where group_id = ?2 and group_address = ?3 and " " member_id = ?4 and member_address = ?5; "; -static const char *sql_group_join = +static const char *sql_group_join MAYBE_UNUSED = "update own_memberships set have_joined = 1 " " where group_id = ?1 and group_address = ?2 and " " own_id = ?3 and own_address = ?4; "; -static const char *sql_leave_group = +static const char *sql_leave_group MAYBE_UNUSED = "update own_memberships set have_joined = 0 " " where group_id = ?1 and group_address = ?2 and " " own_id = ?3 and own_address = ?4; "; -static const char *sql_get_all_members = +static const char *sql_get_all_members MAYBE_UNUSED = "select member_id, member_address, active_member from own_groups_members " " where group_id = ?1 and group_address = ?2; "; -static const char *sql_get_active_members = +static const char *sql_get_active_members MAYBE_UNUSED = "select member_id, member_address from own_groups_members " " where group_id = ?1 and group_address = ?2 and active_member = 1; "; -static const char *sql_get_group_manager = +static const char *sql_get_group_manager MAYBE_UNUSED = "select manager_userid, manager_address from groups " " where group_id = ?1 and group_address = ?2; "; -static const char *sql_is_invited_group_member = +static const char *sql_is_invited_group_member MAYBE_UNUSED = "select count(*) from own_groups_members " " where group_id = ?1 and group_address = ?2 and member_id = ?3 and member_address = ?4; "; -static const char *sql_is_active_group_member = +static const char *sql_is_active_group_member MAYBE_UNUSED = "select active_member from own_groups_members " " where group_id = ?1 and group_address = ?2 and member_id = ?3 and member_address = ?4; "; -static const char *sql_get_all_groups = +static const char *sql_get_all_groups MAYBE_UNUSED = "select group_id, group_address from own_memberships; "; -static const char *sql_get_active_groups = +static const char *sql_get_active_groups MAYBE_UNUSED = "select group_id, group_address from own_memberships where have_joined = 1; "; -static const char *sql_add_own_membership_entry = +static const char *sql_add_own_membership_entry MAYBE_UNUSED = "insert or replace into own_memberships (group_id, group_address, own_id, own_address, have_joined) " " values (?1, ?2, ?3, ?4, 0) ; "; -static const char *sql_is_group_active = +static const char *sql_is_group_active MAYBE_UNUSED = "select count(*) from groups " " where group_id = ?1 and group_address = ?2 and active = 1; "; // This below can return multiple entries for multiple idents in same group // FIXME: decide what we really need here -static const char *sql_retrieve_own_membership_info_for_group = +static const char *sql_retrieve_own_membership_info_for_group MAYBE_UNUSED = "select own_id, own_address, have_joined " " from own_memberships " " inner join groups using (group_id, group_address) " " where group_id = ?1 and group_address = ?2; "; -static const char *sql_retrieve_own_membership_info_for_group_and_ident = +static const char *sql_retrieve_own_membership_info_for_group_and_ident + MAYBE_UNUSED = "select have_joined, manager_userid, manager_address, active " " from own_memberships " " inner join groups using (group_id, group_address) " " where group_id = ?1 and group_address = ?2 and own_id = ?3 and own_address = ?4; "; // This will return all membership info for all identities -static const char *sql_retrieve_all_own_membership_info = +static const char *sql_retrieve_all_own_membership_info MAYBE_UNUSED = "select group_id, group_address, own_id, own_address, have_joined, manager_id, manager_address, active " " from own_memberships " " inner join using (group_id, group_address); "; -static const char* sql_get_own_membership_status = +static const char* sql_get_own_membership_status MAYBE_UNUSED = "select have_joined from own_memberships " " where group_id = ?1 and group_address = ?2 and " " own_id = ?3 and own_address = ?4; "; diff --git a/src/keymanagement.c b/src/keymanagement.c index a4bdecb7..7830ff90 100644 --- a/src/keymanagement.c +++ b/src/keymanagement.c @@ -772,7 +772,8 @@ DYNAMIC_API PEP_STATUS update_identity( // grab some information about the stored identity bool candidate_has_real_id = strstr(candidate_id, "TOFU_") != candidate_id; bool candidate_has_username = !EMPTYSTR(candidate->username); - bool candidate_name_is_addr = candidate_has_username ? strcmp(candidate->address, candidate->username) == 0 : false; + bool candidate_name_is_addr __attribute__((unused)) + = candidate_has_username ? strcmp(candidate->address, candidate->username) == 0 : false; // This is where the optimisation gets a little weird: // diff --git a/src/map_asn1.c b/src/map_asn1.c index cc52e7ae..cf643121 100644 --- a/src/map_asn1.c +++ b/src/map_asn1.c @@ -6,6 +6,7 @@ #include "pEp_internal.h" #include "map_asn1.h" +#include "message_codec.h" /* Expand to a statement checking that the given expression evaluates to a non-NULL result, first using an assert and then an explicit check in C. If diff --git a/src/message_api.c b/src/message_api.c index af77ac9e..7e6416bc 100644 --- a/src/message_api.c +++ b/src/message_api.c @@ -136,6 +136,7 @@ static const char * rating_to_string(PEP_rating rating) return "under_attack"; default: assert(0); + return "invalid rating (this should never happen)"; } } @@ -2176,7 +2177,7 @@ bool import_attached_keys( int i = 0; - bloblist_t* prev = NULL; + bloblist_t* prev __attribute__ ((__unused__)) = NULL; bool do_not_advance = false; const char* pubkey_header = "-----BEGIN PGP PUBLIC KEY BLOCK-----"; @@ -2752,7 +2753,7 @@ DYNAMIC_API PEP_STATUS encrypt_message( unsigned int max_version_minor = 0; pEp_version_major_minor(PEP_VERSION, &max_version_major, &max_version_minor); - identity_list * _il = NULL; + identity_list * _il __attribute__((__unused__)) = NULL; // // Update the identities and gather key and version information @@ -4437,6 +4438,7 @@ static PEP_STATUS reconcile_src_and_inner_messages(message* src, * * @retval bool */ +__attribute__ ((__unused__)) static bool is_trusted_own_priv_fpr(PEP_SESSION session, const char* own_id, const char* fpr @@ -4473,6 +4475,7 @@ static bool is_trusted_own_priv_fpr(PEP_SESSION session, * * @retval bool */ +__attribute__ ((__unused__)) static bool reject_fpr(PEP_SESSION session, const char* fpr) { bool reject = true; diff --git a/src/pgp_sequoia.c b/src/pgp_sequoia.c index 95807f07..a3d55a5e 100644 --- a/src/pgp_sequoia.c +++ b/src/pgp_sequoia.c @@ -11,7 +11,9 @@ */ -#pragma clang diagnostic ignored "-Wgnu-zero-variadic-macro-arguments" +#if defined (__clang__) +# pragma clang diagnostic ignored "-Wgnu-zero-variadic-macro-arguments" +#endif #define _GNU_SOURCE 1 @@ -3509,13 +3511,24 @@ static PEP_STATUS list_keys(PEP_SESSION session, *keyinfo_list = _keyinfo_list; if (status != PEP_STATUS_OK || (_keylist && !_keylist->value)) { + /* Here, when building with optimisation, some GCC versions (tested with + GCC Debian 10.3.0-10 on moore, as of 2021-11-09) give a spurious + warning about _keylist being used uninitialised. Let us silence + that. */ +#if defined (__GNUC__) +# pragma GCC diagnostic push +# pragma GCC diagnostic ignored "-Wmaybe-uninitialized" +#endif free_stringlist(_keylist); _keylist = NULL; +#if defined (__GNUC__) +# pragma GCC diagnostic pop +#endif } if (keylist) *keylist = _keylist; - int len = -1; + int len __attribute__ ((__unused__)) = -1; if (keylist) len = stringlist_length(*keylist); else if (keyinfo_list) diff --git a/src/platform_windows.h b/src/platform_windows.h index 5c253cb4..3c7be772 100644 --- a/src/platform_windows.h +++ b/src/platform_windows.h @@ -9,6 +9,15 @@ // Windows platform specifica +// The windows compiler used by default does not support GNU-style attributes; +// let us just disable them altogether with a CPP defintition, so that +// attributes become no-ops on windows but keep functioning on the other +// platforms. +// Notice that this definition is extremely conservative: supporting exactly +// one argument would suffice. +#define __attribute__(...) /* nothing */ +#define attribute __attribute__ + #ifndef _EXPORT_PEP_ENGINE_DLL #define _EXPORT_PEP_ENGINE_DLL #endif