From ded6d9fcb47fededa8cb2dd835772eb3036ef36d Mon Sep 17 00:00:00 2001 From: Nick Mathewson Date: Wed, 11 Sep 2019 18:47:19 -0400 Subject: Run test_operator_cleanup on our unit tests Coccinelle doesn't understand it when we use "==" and "!=" and so on as arguments to macros. To solve this, we prefer OP_EQ, OP_NE, and so on. This commit is automatically generated by running ./scripts/coccinelle/test_operator_cleanup over all of the source code in src. --- src/test/hs_test_helpers.c | 28 ++++++++++++------------- src/test/test_router.c | 10 ++++----- src/test/test_scheduler.c | 52 +++++++++++++++++++++++----------------------- 3 files changed, 45 insertions(+), 45 deletions(-) (limited to 'src') diff --git a/src/test/hs_test_helpers.c b/src/test/hs_test_helpers.c index 0a21fe576b..22be4aea23 100644 --- a/src/test/hs_test_helpers.c +++ b/src/test/hs_test_helpers.c @@ -53,7 +53,7 @@ hs_helper_build_intro_point(const ed25519_keypair_t *signing_kp, time_t now, } ret = ed25519_keypair_generate(&auth_kp, 0); - tt_int_op(ret, ==, 0); + tt_int_op(ret, OP_EQ, 0); ip->auth_key_cert = tor_cert_create(signing_kp, CERT_TYPE_AUTH_HS_IP_KEY, &auth_kp.pubkey, now, HS_DESC_CERT_LIFETIME, @@ -64,7 +64,7 @@ hs_helper_build_intro_point(const ed25519_keypair_t *signing_kp, time_t now, ip->legacy.key = crypto_pk_new(); tt_assert(ip->legacy.key); ret = crypto_pk_generate_key(ip->legacy.key); - tt_int_op(ret, ==, 0); + tt_int_op(ret, OP_EQ, 0); ssize_t cert_len = tor_make_rsa_ed25519_crosscert( &signing_kp->pubkey, ip->legacy.key, now + HS_DESC_CERT_LIFETIME, @@ -82,7 +82,7 @@ hs_helper_build_intro_point(const ed25519_keypair_t *signing_kp, time_t now, tor_cert_t *cross_cert; ret = curve25519_keypair_generate(&curve25519_kp, 0); - tt_int_op(ret, ==, 0); + tt_int_op(ret, OP_EQ, 0); ed25519_keypair_from_curve25519_keypair(&ed25519_kp, &signbit, &curve25519_kp); cross_cert = tor_cert_create(signing_kp, CERT_TYPE_CROSS_HS_IP_KEYS, @@ -140,7 +140,7 @@ hs_helper_build_hs_desc_impl(unsigned int no_ip, /* Setup superencrypted data section. */ ret = curve25519_keypair_generate(&auth_ephemeral_kp, 0); - tt_int_op(ret, ==, 0); + tt_int_op(ret, OP_EQ, 0); memcpy(&desc->superencrypted_data.auth_ephemeral_pubkey, &auth_ephemeral_kp.pubkey, sizeof(curve25519_public_key_t)); @@ -224,7 +224,7 @@ hs_helper_desc_equal(const hs_descriptor_t *desc1, tt_mem_op(desc1->plaintext_data.blinded_pubkey.pubkey, OP_EQ, desc2->plaintext_data.blinded_pubkey.pubkey, ED25519_PUBKEY_LEN); - tt_u64_op(desc1->plaintext_data.revision_counter, ==, + tt_u64_op(desc1->plaintext_data.revision_counter, OP_EQ, desc2->plaintext_data.revision_counter); /* NOTE: We can't compare the encrypted blob because when encoding the @@ -241,7 +241,7 @@ hs_helper_desc_equal(const hs_descriptor_t *desc1, { tt_assert(desc1->superencrypted_data.clients); tt_assert(desc2->superencrypted_data.clients); - tt_int_op(smartlist_len(desc1->superencrypted_data.clients), ==, + tt_int_op(smartlist_len(desc1->superencrypted_data.clients), OP_EQ, smartlist_len(desc2->superencrypted_data.clients)); for (int i=0; i < smartlist_len(desc1->superencrypted_data.clients); @@ -259,15 +259,15 @@ hs_helper_desc_equal(const hs_descriptor_t *desc1, } /* Encrypted data section. */ - tt_uint_op(desc1->encrypted_data.create2_ntor, ==, + tt_uint_op(desc1->encrypted_data.create2_ntor, OP_EQ, desc2->encrypted_data.create2_ntor); /* Authentication type. */ - tt_int_op(!!desc1->encrypted_data.intro_auth_types, ==, + tt_int_op(!!desc1->encrypted_data.intro_auth_types, OP_EQ, !!desc2->encrypted_data.intro_auth_types); if (desc1->encrypted_data.intro_auth_types && desc2->encrypted_data.intro_auth_types) { - tt_int_op(smartlist_len(desc1->encrypted_data.intro_auth_types), ==, + tt_int_op(smartlist_len(desc1->encrypted_data.intro_auth_types), OP_EQ, smartlist_len(desc2->encrypted_data.intro_auth_types)); for (int i = 0; i < smartlist_len(desc1->encrypted_data.intro_auth_types); @@ -281,7 +281,7 @@ hs_helper_desc_equal(const hs_descriptor_t *desc1, { tt_assert(desc1->encrypted_data.intro_points); tt_assert(desc2->encrypted_data.intro_points); - tt_int_op(smartlist_len(desc1->encrypted_data.intro_points), ==, + tt_int_op(smartlist_len(desc1->encrypted_data.intro_points), OP_EQ, smartlist_len(desc2->encrypted_data.intro_points)); for (int i=0; i < smartlist_len(desc1->encrypted_data.intro_points); i++) { hs_desc_intro_point_t *ip1 = smartlist_get(desc1->encrypted_data @@ -296,12 +296,12 @@ hs_helper_desc_equal(const hs_descriptor_t *desc1, tt_mem_op(&ip1->enc_key, OP_EQ, &ip2->enc_key, CURVE25519_PUBKEY_LEN); } - tt_int_op(smartlist_len(ip1->link_specifiers), ==, + tt_int_op(smartlist_len(ip1->link_specifiers), OP_EQ, smartlist_len(ip2->link_specifiers)); for (int j = 0; j < smartlist_len(ip1->link_specifiers); j++) { link_specifier_t *ls1 = smartlist_get(ip1->link_specifiers, j), *ls2 = smartlist_get(ip2->link_specifiers, j); - tt_int_op(link_specifier_get_ls_type(ls1), ==, + tt_int_op(link_specifier_get_ls_type(ls1), OP_EQ, link_specifier_get_ls_type(ls2)); switch (link_specifier_get_ls_type(ls1)) { case LS_IPV4: @@ -311,7 +311,7 @@ hs_helper_desc_equal(const hs_descriptor_t *desc1, tt_int_op(addr1, OP_EQ, addr2); uint16_t port1 = link_specifier_get_un_ipv4_port(ls1); uint16_t port2 = link_specifier_get_un_ipv4_port(ls2); - tt_int_op(port1, ==, port2); + tt_int_op(port1, OP_EQ, port2); } break; case LS_IPV6: @@ -326,7 +326,7 @@ hs_helper_desc_equal(const hs_descriptor_t *desc1, link_specifier_getlen_un_ipv6_addr(ls1)); uint16_t port1 = link_specifier_get_un_ipv6_port(ls1); uint16_t port2 = link_specifier_get_un_ipv6_port(ls2); - tt_int_op(port1, ==, port2); + tt_int_op(port1, OP_EQ, port2); } break; case LS_LEGACY_ID: diff --git a/src/test/test_router.c b/src/test/test_router.c index 5477ab51e9..24c7d32bc1 100644 --- a/src/test/test_router.c +++ b/src/test/test_router.c @@ -92,13 +92,13 @@ test_router_dump_router_to_string_no_bridge_distribution_method(void *arg) options->BridgeRelay = 1; /* Generate keys which router_dump_router_to_string() expects to exist. */ - tt_int_op(0, ==, curve25519_keypair_generate(&ntor_keypair, 0)); - tt_int_op(0, ==, ed25519_keypair_generate(&signing_keypair, 0)); + tt_int_op(0, OP_EQ, curve25519_keypair_generate(&ntor_keypair, 0)); + tt_int_op(0, OP_EQ, ed25519_keypair_generate(&signing_keypair, 0)); /* Set up part of our routerinfo_t so that we don't trigger any other * assertions in router_dump_router_to_string(). */ router = (routerinfo_t*)router_get_my_routerinfo(); - tt_ptr_op(router, !=, NULL); + tt_ptr_op(router, OP_NE, NULL); /* The real router_get_my_routerinfo() looks up onion_curve25519_pkey using * get_current_curve25519_keypair(), but we don't initialise static data in @@ -115,9 +115,9 @@ test_router_dump_router_to_string_no_bridge_distribution_method(void *arg) &ntor_keypair, &signing_keypair); crypto_pk_free(onion_pkey); - tt_ptr_op(desc, !=, NULL); + tt_ptr_op(desc, OP_NE, NULL); found = strstr(desc, needle); - tt_ptr_op(found, !=, NULL); + tt_ptr_op(found, OP_NE, NULL); done: NS_UNMOCK(router_get_my_routerinfo); diff --git a/src/test/test_scheduler.c b/src/test/test_scheduler.c index bf9c6a49cd..39c4963fce 100644 --- a/src/test/test_scheduler.c +++ b/src/test/test_scheduler.c @@ -848,8 +848,8 @@ test_scheduler_initfree(void *arg) { (void)arg; - tt_ptr_op(channels_pending, ==, NULL); - tt_ptr_op(run_sched_ev, ==, NULL); + tt_ptr_op(channels_pending, OP_EQ, NULL); + tt_ptr_op(run_sched_ev, OP_EQ, NULL); MOCK(get_options, mock_get_options); set_scheduler_options(SCHEDULER_KIST); @@ -858,17 +858,17 @@ test_scheduler_initfree(void *arg) scheduler_init(); - tt_ptr_op(channels_pending, !=, NULL); - tt_ptr_op(run_sched_ev, !=, NULL); + tt_ptr_op(channels_pending, OP_NE, NULL); + tt_ptr_op(run_sched_ev, OP_NE, NULL); /* We have specified nothing in the torrc and there's no consensus so the * KIST scheduler is what should be in use */ - tt_ptr_op(the_scheduler, ==, get_kist_scheduler()); - tt_int_op(sched_run_interval, ==, 10); + tt_ptr_op(the_scheduler, OP_EQ, get_kist_scheduler()); + tt_int_op(sched_run_interval, OP_EQ, 10); scheduler_free_all(); - tt_ptr_op(channels_pending, ==, NULL); - tt_ptr_op(run_sched_ev, ==, NULL); + tt_ptr_op(channels_pending, OP_EQ, NULL); + tt_ptr_op(run_sched_ev, OP_EQ, NULL); done: UNMOCK(get_options); @@ -890,11 +890,11 @@ test_scheduler_can_use_kist(void *arg) res_should = scheduler_can_use_kist(); res_freq = kist_scheduler_run_interval(); #ifdef HAVE_KIST_SUPPORT - tt_int_op(res_should, ==, 1); + tt_int_op(res_should, OP_EQ, 1); #else /* HAVE_KIST_SUPPORT */ - tt_int_op(res_should, ==, 0); + tt_int_op(res_should, OP_EQ, 0); #endif /* HAVE_KIST_SUPPORT */ - tt_int_op(res_freq, ==, 1234); + tt_int_op(res_freq, OP_EQ, 1234); /* Test defer to consensus, but no consensus available */ clear_options(); @@ -902,11 +902,11 @@ test_scheduler_can_use_kist(void *arg) res_should = scheduler_can_use_kist(); res_freq = kist_scheduler_run_interval(); #ifdef HAVE_KIST_SUPPORT - tt_int_op(res_should, ==, 1); + tt_int_op(res_should, OP_EQ, 1); #else /* HAVE_KIST_SUPPORT */ - tt_int_op(res_should, ==, 0); + tt_int_op(res_should, OP_EQ, 0); #endif /* HAVE_KIST_SUPPORT */ - tt_int_op(res_freq, ==, 10); + tt_int_op(res_freq, OP_EQ, 10); /* Test defer to consensus, and kist consensus available */ MOCK(networkstatus_get_param, mock_kist_networkstatus_get_param); @@ -915,11 +915,11 @@ test_scheduler_can_use_kist(void *arg) res_should = scheduler_can_use_kist(); res_freq = kist_scheduler_run_interval(); #ifdef HAVE_KIST_SUPPORT - tt_int_op(res_should, ==, 1); + tt_int_op(res_should, OP_EQ, 1); #else /* HAVE_KIST_SUPPORT */ - tt_int_op(res_should, ==, 0); + tt_int_op(res_should, OP_EQ, 0); #endif /* HAVE_KIST_SUPPORT */ - tt_int_op(res_freq, ==, 12); + tt_int_op(res_freq, OP_EQ, 12); UNMOCK(networkstatus_get_param); /* Test defer to consensus, and vanilla consensus available */ @@ -928,8 +928,8 @@ test_scheduler_can_use_kist(void *arg) mocked_options.KISTSchedRunInterval = 0; res_should = scheduler_can_use_kist(); res_freq = kist_scheduler_run_interval(); - tt_int_op(res_should, ==, 0); - tt_int_op(res_freq, ==, 0); + tt_int_op(res_should, OP_EQ, 0); + tt_int_op(res_freq, OP_EQ, 0); UNMOCK(networkstatus_get_param); done: @@ -956,7 +956,7 @@ test_scheduler_ns_changed(void *arg) set_scheduler_options(SCHEDULER_KIST); set_scheduler_options(SCHEDULER_VANILLA); - tt_ptr_op(the_scheduler, ==, NULL); + tt_ptr_op(the_scheduler, OP_EQ, NULL); /* Change from vanilla to kist via consensus */ the_scheduler = get_vanilla_scheduler(); @@ -964,9 +964,9 @@ test_scheduler_ns_changed(void *arg) scheduler_notify_networkstatus_changed(); UNMOCK(networkstatus_get_param); #ifdef HAVE_KIST_SUPPORT - tt_ptr_op(the_scheduler, ==, get_kist_scheduler()); + tt_ptr_op(the_scheduler, OP_EQ, get_kist_scheduler()); #else - tt_ptr_op(the_scheduler, ==, get_vanilla_scheduler()); + tt_ptr_op(the_scheduler, OP_EQ, get_vanilla_scheduler()); #endif /* Change from kist to vanilla via consensus */ @@ -974,7 +974,7 @@ test_scheduler_ns_changed(void *arg) MOCK(networkstatus_get_param, mock_vanilla_networkstatus_get_param); scheduler_notify_networkstatus_changed(); UNMOCK(networkstatus_get_param); - tt_ptr_op(the_scheduler, ==, get_vanilla_scheduler()); + tt_ptr_op(the_scheduler, OP_EQ, get_vanilla_scheduler()); /* Doesn't change when using KIST */ the_scheduler = get_kist_scheduler(); @@ -982,9 +982,9 @@ test_scheduler_ns_changed(void *arg) scheduler_notify_networkstatus_changed(); UNMOCK(networkstatus_get_param); #ifdef HAVE_KIST_SUPPORT - tt_ptr_op(the_scheduler, ==, get_kist_scheduler()); + tt_ptr_op(the_scheduler, OP_EQ, get_kist_scheduler()); #else - tt_ptr_op(the_scheduler, ==, get_vanilla_scheduler()); + tt_ptr_op(the_scheduler, OP_EQ, get_vanilla_scheduler()); #endif /* Doesn't change when using vanilla */ @@ -992,7 +992,7 @@ test_scheduler_ns_changed(void *arg) MOCK(networkstatus_get_param, mock_vanilla_networkstatus_get_param); scheduler_notify_networkstatus_changed(); UNMOCK(networkstatus_get_param); - tt_ptr_op(the_scheduler, ==, get_vanilla_scheduler()); + tt_ptr_op(the_scheduler, OP_EQ, get_vanilla_scheduler()); done: UNMOCK(get_options); -- cgit v1.2.3-54-g00ecf From 9871fcbcd9e2c729c46570d6794d3ddcf37aeeb6 Mon Sep 17 00:00:00 2001 From: Nick Mathewson Date: Wed, 9 Oct 2019 09:37:21 -0400 Subject: Use #warning instead of #warn: one is C and one isn't. --- src/lib/log/log.c | 2 +- src/lib/malloc/map_anon.c | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/lib/log/log.c b/src/lib/log/log.c index 56f016eae4..012e25193e 100644 --- a/src/lib/log/log.c +++ b/src/lib/log/log.c @@ -526,7 +526,7 @@ logfile_deliver(logfile_t *lf, const char *buf, size_t msg_len, * pass them, and some very old ones do not detect overflow so well. * Regrettably, they call their maximum line length MAXLINE. */ #if MAXLINE < 64 -#warn "MAXLINE is a very low number; it might not be from syslog.h after all" +#warning "MAXLINE is a very low number; it might not be from syslog.h." #endif char *m = msg_after_prefix; if (msg_len >= MAXLINE) diff --git a/src/lib/malloc/map_anon.c b/src/lib/malloc/map_anon.c index 0f6a4150c7..4e38cb642c 100644 --- a/src/lib/malloc/map_anon.c +++ b/src/lib/malloc/map_anon.c @@ -75,8 +75,8 @@ #endif /* defined(HAVE_MINHERIT) || ... */ #if defined(HAVE_MINHERIT) && !defined(FLAG_ZERO) && !defined(FLAG_NOINHERIT) -#warn "minherit() is defined, but we couldn't find the right flag for it." -#warn "This is probably a bug in Tor's support for this platform." +#warning "minherit() is defined, but we couldn't find the right flag for it." +#warning "This is probably a bug in Tor's support for this platform." #endif /** -- cgit v1.2.3-54-g00ecf From 630d8c7a1acda53b640b018039f7ec586e048ad7 Mon Sep 17 00:00:00 2001 From: Nick Mathewson Date: Wed, 9 Oct 2019 10:16:08 -0400 Subject: With coccinelle, avoid includes in the middle of an expression. --- src/app/config/config.c | 6 ++++++ src/feature/dirparse/authcert_parse.c | 2 ++ src/feature/dirparse/ns_parse.c | 2 ++ src/lib/tls/tortls_openssl.c | 2 ++ src/lib/version/git_revision.c | 4 ++++ src/test/test_config.c | 2 ++ 6 files changed, 18 insertions(+) (limited to 'src') diff --git a/src/app/config/config.c b/src/app/config/config.c index b4bccd9351..93cf5427cd 100644 --- a/src/app/config/config.c +++ b/src/app/config/config.c @@ -765,7 +765,9 @@ static const config_var_t option_vars_[] = { /** List of default directory authorities */ static const char *default_authorities[] = { +#ifndef COCCI #include "auth_dirs.inc" +#endif NULL }; @@ -773,7 +775,9 @@ static const char *default_authorities[] = { * relays that meet certain stability criteria. */ static const char *default_fallbacks[] = { +#ifndef COCCI #include "fallback_dirs.inc" +#endif NULL }; @@ -783,7 +787,9 @@ static const struct { const char *k; const char *v; } testing_tor_network_defaults[] = { +#ifndef COCCI #include "testnet.inc" +#endif { NULL, NULL } }; diff --git a/src/feature/dirparse/authcert_parse.c b/src/feature/dirparse/authcert_parse.c index 8ba5a53981..5e4b12c76c 100644 --- a/src/feature/dirparse/authcert_parse.c +++ b/src/feature/dirparse/authcert_parse.c @@ -16,7 +16,9 @@ /** List of tokens recognized in V3 authority certificates. */ static token_rule_t dir_key_certificate_table[] = { +#ifndef COCCI #include "feature/dirparse/authcert_members.i" +#endif T1("fingerprint", K_FINGERPRINT, CONCAT_ARGS, NO_OBJ ), END_OF_TABLE }; diff --git a/src/feature/dirparse/ns_parse.c b/src/feature/dirparse/ns_parse.c index d5405e6464..0cf2a6f789 100644 --- a/src/feature/dirparse/ns_parse.c +++ b/src/feature/dirparse/ns_parse.c @@ -84,7 +84,9 @@ static token_rule_t networkstatus_token_table[] = { T01("required-relay-protocols", K_REQUIRED_RELAY_PROTOCOLS, CONCAT_ARGS, NO_OBJ ), +#ifndef COCCI #include "feature/dirparse/authcert_members.i" +#endif T0N("opt", K_OPT, CONCAT_ARGS, OBJ_OK ), T1( "contact", K_CONTACT, CONCAT_ARGS, NO_OBJ ), diff --git a/src/lib/tls/tortls_openssl.c b/src/lib/tls/tortls_openssl.c index 86f0ac42cc..42db05460e 100644 --- a/src/lib/tls/tortls_openssl.c +++ b/src/lib/tls/tortls_openssl.c @@ -464,7 +464,9 @@ static const char UNRESTRICTED_SERVER_CIPHER_LIST[] = /** List of ciphers that clients should advertise, omitting items that * our OpenSSL doesn't know about. */ static const char CLIENT_CIPHER_LIST[] = +#ifndef COCCI #include "lib/tls/ciphers.inc" +#endif /* Tell it not to use SSLv2 ciphers, so that it can select an SSLv3 version * of any cipher we say. */ "!SSLv2" diff --git a/src/lib/version/git_revision.c b/src/lib/version/git_revision.c index 900a1e12a0..338ba2bc3d 100644 --- a/src/lib/version/git_revision.c +++ b/src/lib/version/git_revision.c @@ -11,14 +11,18 @@ * src/core/include.am, and is usually right. */ const char tor_git_revision[] = +#ifndef COCCI #ifndef _MSC_VER #include "micro-revision.i" +#endif #endif ""; const char tor_bug_suffix[] = " (on Tor " VERSION +#ifndef COCCI #ifndef _MSC_VER " " #include "micro-revision.i" +#endif #endif ")"; diff --git a/src/test/test_config.c b/src/test/test_config.c index 9b715b2ecf..162a499900 100644 --- a/src/test/test_config.c +++ b/src/test/test_config.c @@ -3815,7 +3815,9 @@ static void test_config_default_fallback_dirs(void *arg) { const char *fallback[] = { +#ifndef COCCI #include "app/config/fallback_dirs.inc" +#endif NULL }; -- cgit v1.2.3-54-g00ecf From 48be9221609ceafa259db6f4c32cf947e9395e30 Mon Sep 17 00:00:00 2001 From: Nick Mathewson Date: Tue, 22 Oct 2019 09:31:31 -0400 Subject: COCCI: disable DOWLOAD_SCHEDULE macro --- src/app/config/config.c | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'src') diff --git a/src/app/config/config.c b/src/app/config/config.c index 93cf5427cd..f6eae6e97b 100644 --- a/src/app/config/config.c +++ b/src/app/config/config.c @@ -186,8 +186,12 @@ static const char unix_q_socket_prefix[] = "unix:\""; /** macro to help with the bulk rename of *DownloadSchedule to * *DowloadInitialDelay . */ +#ifndef COCCI #define DOWNLOAD_SCHEDULE(name) \ { #name "DownloadSchedule", #name "DownloadInitialDelay", 0, 1 } +#else +#define DOWNLOAD_SCHEDULE(name) { NULL, NULL, 0, 1 } +#endif /** A list of abbreviations and aliases to map command-line options, obsolete * option names, or alternative option names, to their current values. */ -- cgit v1.2.3-54-g00ecf From b867e97ce6825e3d7f33a3c3dce8c65f11fe15ec Mon Sep 17 00:00:00 2001 From: Nick Mathewson Date: Wed, 9 Oct 2019 10:34:43 -0400 Subject: With COCCI defined, avoid PERIODIC_EVENT. Coccinelle doesn't understand the particular pattern of token pasting we have going on here. --- src/core/mainloop/mainloop.c | 4 +++- src/core/mainloop/periodic.h | 2 ++ src/core/or/or_periodic.c | 2 ++ src/feature/dirauth/dirauth_periodic.c | 2 ++ src/feature/relay/relay_periodic.c | 2 ++ 5 files changed, 11 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/core/mainloop/mainloop.c b/src/core/mainloop/mainloop.c index c051b11566..6e78a5bb26 100644 --- a/src/core/mainloop/mainloop.c +++ b/src/core/mainloop/mainloop.c @@ -1363,8 +1363,10 @@ CALLBACK(second_elapsed); #undef CALLBACK /* Now we declare an array of periodic_event_item_t for each periodic event */ -#define CALLBACK(name, r, f) \ +#ifndef COCCI +#define CALLBACK(name, r, f) \ PERIODIC_EVENT(name, PERIODIC_EVENT_ROLE_ ## r, f) +#endif #define FL(name) (PERIODIC_EVENT_FLAG_ ## name) STATIC periodic_event_item_t mainloop_periodic_events[] = { diff --git a/src/core/mainloop/periodic.h b/src/core/mainloop/periodic.h index a9aa461969..0f80748f55 100644 --- a/src/core/mainloop/periodic.h +++ b/src/core/mainloop/periodic.h @@ -71,8 +71,10 @@ typedef struct periodic_event_item_t { } periodic_event_item_t; /** events will get their interval from first execution */ +#ifndef COCCI #define PERIODIC_EVENT(fn, r, f) { fn##_callback, 0, NULL, #fn, r, f, 0 } #define END_OF_PERIODIC_EVENTS { NULL, 0, NULL, NULL, 0, 0, 0 } +#endif /* Return true iff the given event was setup before thus is enabled to be * scheduled. */ diff --git a/src/core/or/or_periodic.c b/src/core/or/or_periodic.c index fe28c99192..879d142cb2 100644 --- a/src/core/or/or_periodic.c +++ b/src/core/or/or_periodic.c @@ -20,11 +20,13 @@ #include "feature/relay/routermode.h" +#ifndef COCCI #define DECLARE_EVENT(name, roles, flags) \ static periodic_event_item_t name ## _event = \ PERIODIC_EVENT(name, \ PERIODIC_EVENT_ROLE_##roles, \ flags) +#endif #define FL(name) (PERIODIC_EVENT_FLAG_ ## name) diff --git a/src/feature/dirauth/dirauth_periodic.c b/src/feature/dirauth/dirauth_periodic.c index 02727d61b4..c02b9ac862 100644 --- a/src/feature/dirauth/dirauth_periodic.c +++ b/src/feature/dirauth/dirauth_periodic.c @@ -18,11 +18,13 @@ #include "core/mainloop/periodic.h" +#ifndef COCCI #define DECLARE_EVENT(name, roles, flags) \ static periodic_event_item_t name ## _event = \ PERIODIC_EVENT(name, \ PERIODIC_EVENT_ROLE_##roles, \ flags) +#endif #define FL(name) (PERIODIC_EVENT_FLAG_##name) diff --git a/src/feature/relay/relay_periodic.c b/src/feature/relay/relay_periodic.c index b48b495895..7dc4cb4530 100644 --- a/src/feature/relay/relay_periodic.c +++ b/src/feature/relay/relay_periodic.c @@ -31,11 +31,13 @@ #include "feature/nodelist/routerinfo_st.h" #include "feature/control/control_events.h" +#ifndef COCCI #define DECLARE_EVENT(name, roles, flags) \ static periodic_event_item_t name ## _event = \ PERIODIC_EVENT(name, \ PERIODIC_EVENT_ROLE_##roles, \ flags) +#endif #define FL(name) (PERIODIC_EVENT_FLAG_##name) -- cgit v1.2.3-54-g00ecf From b03c8c74ce87e44fc74e84183fe883018b43f088 Mon Sep 17 00:00:00 2001 From: Nick Mathewson Date: Tue, 22 Oct 2019 09:28:35 -0400 Subject: COCCI: Disable some buffers.c macros that coccinelle can't handle. --- src/lib/buf/buffers.c | 2 ++ 1 file changed, 2 insertions(+) (limited to 'src') diff --git a/src/lib/buf/buffers.c b/src/lib/buf/buffers.c index 4d026bd37d..3828583855 100644 --- a/src/lib/buf/buffers.c +++ b/src/lib/buf/buffers.c @@ -99,6 +99,7 @@ #define DBG_S(s) (void)0 #endif +#ifndef COCCI #ifdef DISABLE_MEMORY_SENTINELS #define CHUNK_SET_SENTINEL(chunk, alloclen) STMT_NIL #else @@ -109,6 +110,7 @@ memset(a,0,SENTINEL_LEN); \ } while (0) #endif /* defined(DISABLE_MEMORY_SENTINELS) */ +#endif /** Move all bytes stored in chunk to the front of chunk->mem, * to free up space at the end. */ -- cgit v1.2.3-54-g00ecf From c1e8e5bb3223b950f79bce5bd3540566fc1fdc7b Mon Sep 17 00:00:00 2001 From: Nick Mathewson Date: Wed, 9 Oct 2019 10:47:05 -0400 Subject: Apparently coccinelle can't handle multiline #errors. --- src/lib/crypt_ops/crypto_openssl_mgt.c | 6 ++++-- src/lib/log/log.h | 2 ++ 2 files changed, 6 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/lib/crypt_ops/crypto_openssl_mgt.c b/src/lib/crypt_ops/crypto_openssl_mgt.c index 9ec59e7c81..917ef4597b 100644 --- a/src/lib/crypt_ops/crypto_openssl_mgt.c +++ b/src/lib/crypt_ops/crypto_openssl_mgt.c @@ -121,9 +121,11 @@ crypto_openssl_get_header_version_str(void) return crypto_openssl_header_version_str; } +#ifndef COCCI #ifndef OPENSSL_THREADS -#error OpenSSL has been built without thread support. Tor requires an \ - OpenSSL library with thread support enabled. +#error "OpenSSL has been built without thread support. Tor requires an \ + OpenSSL library with thread support enabled." +#endif #endif #ifndef NEW_THREAD_API diff --git a/src/lib/log/log.h b/src/lib/log/log.h index c4a27782c3..c2b20fc228 100644 --- a/src/lib/log/log.h +++ b/src/lib/log/log.h @@ -23,9 +23,11 @@ #include #define LOG_WARN LOG_WARNING #if LOG_DEBUG < LOG_ERR +#ifndef COCCI #error "Your syslog.h thinks high numbers are more important. " \ "We aren't prepared to deal with that." #endif +#endif #else /* !(defined(HAVE_SYSLOG_H)) */ /* Note: Syslog's logging code refers to priorities, with 0 being the most * important. Thus, all our comparisons needed to be reversed when we added -- cgit v1.2.3-54-g00ecf From 4fad456148738712e48582b22496e6baf0dfc1f8 Mon Sep 17 00:00:00 2001 From: Nick Mathewson Date: Wed, 9 Oct 2019 10:58:03 -0400 Subject: test: Hide some test-declaration macro definitions to COCCI. (These ones cause parsing failures.) --- src/test/test_addr.c | 2 ++ src/test/test_confparse.c | 2 ++ src/test/test_connection.c | 2 ++ src/test/test_controller.c | 4 ++++ src/test/test_crypto.c | 2 ++ src/test/test_crypto_slow.c | 2 ++ src/test/test_dir.c | 2 ++ src/test/test_entrynodes.c | 2 ++ src/test/test_link_handshake.c | 2 ++ src/test/test_options.c | 2 ++ src/test/test_util.c | 4 ++++ 11 files changed, 26 insertions(+) (limited to 'src') diff --git a/src/test/test_addr.c b/src/test/test_addr.c index 0f50a43615..50543293c4 100644 --- a/src/test/test_addr.c +++ b/src/test/test_addr.c @@ -1662,8 +1662,10 @@ test_addr_rfc6598(void *arg) ; } +#ifndef COCCI #define ADDR_LEGACY(name) \ { #name, test_addr_ ## name , 0, NULL, NULL } +#endif struct testcase_t addr_tests[] = { ADDR_LEGACY(basic), diff --git a/src/test/test_confparse.c b/src/test/test_confparse.c index bd2b5cdf1b..454b38c646 100644 --- a/src/test/test_confparse.c +++ b/src/test/test_confparse.c @@ -1027,12 +1027,14 @@ test_confparse_find_option_name(void *arg) config_mgr_free(mgr); } +#ifndef COCCI #define CONFPARSE_TEST(name, flags) \ { #name, test_confparse_ ## name, flags, NULL, NULL } #define BADVAL_TEST(name) \ { "badval_" #name, test_confparse_assign_badval, 0, \ &passthrough_setup, (void*)&bv_ ## name } +#endif struct testcase_t confparse_tests[] = { CONFPARSE_TEST(init, 0), diff --git a/src/test/test_connection.c b/src/test/test_connection.c index ebe7c6d36f..3148c1af66 100644 --- a/src/test/test_connection.c +++ b/src/test/test_connection.c @@ -881,12 +881,14 @@ test_failed_orconn_tracker(void *arg) ; } +#ifndef COCCI #define CONNECTION_TESTCASE(name, fork, setup) \ { #name, test_conn_##name, fork, &setup, NULL } /* where arg is an expression (constant, variable, compound expression) */ #define CONNECTION_TESTCASE_ARG(name, fork, setup, arg) \ { #name "_" #arg, test_conn_##name, fork, &setup, (void *)arg } +#endif struct testcase_t connection_tests[] = { CONNECTION_TESTCASE(get_basic, TT_FORK, test_conn_get_basic_st), diff --git a/src/test/test_controller.c b/src/test/test_controller.c index b9cbe0a14d..df595055f5 100644 --- a/src/test/test_controller.c +++ b/src/test/test_controller.c @@ -119,6 +119,7 @@ test_controller_parse_cmd(void *arg) control_cmd_args_free(result); } +#ifndef COCCI #define OK(inp, out) \ { inp "\r\n", out, NULL } #define ERR(inp, err) \ @@ -128,6 +129,7 @@ test_controller_parse_cmd(void *arg) { &syntax, \ ARRAY_LENGTH(array), \ array } +#endif static const parser_testcase_t one_to_three_tests[] = { ERR("", "Need at least 1 argument(s)"), @@ -1818,9 +1820,11 @@ test_getinfo_md_all(void *arg) return; } +#ifndef COCCI #define PARSER_TEST(type) \ { "parse/" #type, test_controller_parse_cmd, 0, &passthrough_setup, \ (void*)&parse_ ## type ## _params } +#endif struct testcase_t controller_tests[] = { PARSER_TEST(one_to_three), diff --git a/src/test/test_crypto.c b/src/test/test_crypto.c index 178a9a5097..7288e6ee89 100644 --- a/src/test/test_crypto.c +++ b/src/test/test_crypto.c @@ -2971,6 +2971,7 @@ test_crypto_failure_modes(void *arg) ; } +#ifndef COCCI #define CRYPTO_LEGACY(name) \ { #name, test_crypto_ ## name , 0, NULL, NULL } @@ -2981,6 +2982,7 @@ test_crypto_failure_modes(void *arg) #define ED25519_TEST(name, fl) \ ED25519_TEST_ONE(name, (fl), "donna"), \ ED25519_TEST_ONE(name, (fl), "ref10") +#endif struct testcase_t crypto_tests[] = { CRYPTO_LEGACY(formats), diff --git a/src/test/test_crypto_slow.c b/src/test/test_crypto_slow.c index 3b20dfa587..4f0cfbc641 100644 --- a/src/test/test_crypto_slow.c +++ b/src/test/test_crypto_slow.c @@ -584,6 +584,7 @@ test_crypto_ed25519_fuzz_donna(void *arg) ; } +#ifndef COCCI #define CRYPTO_LEGACY(name) \ { #name, test_crypto_ ## name , 0, NULL, NULL } @@ -594,6 +595,7 @@ test_crypto_ed25519_fuzz_donna(void *arg) #define ED25519_TEST(name, fl) \ ED25519_TEST_ONE(name, (fl), "donna"), \ ED25519_TEST_ONE(name, (fl), "ref10") +#endif struct testcase_t slow_crypto_tests[] = { CRYPTO_LEGACY(s2k_rfc2440), diff --git a/src/test/test_dir.c b/src/test/test_dir.c index 17d6db1e4d..bdcd785451 100644 --- a/src/test/test_dir.c +++ b/src/test/test_dir.c @@ -7210,6 +7210,7 @@ test_dir_format_versions_list(void *arg) teardown_capture_of_logs(); } +#ifndef COCCI #define DIR_LEGACY(name) \ { #name, test_dir_ ## name , TT_FORK, NULL, NULL } @@ -7219,6 +7220,7 @@ test_dir_format_versions_list(void *arg) /* where arg is a string constant */ #define DIR_ARG(name,flags,arg) \ { #name "_" arg, test_dir_##name, (flags), &passthrough_setup, (void*) arg } +#endif struct testcase_t dir_tests[] = { DIR_LEGACY(nicknames), diff --git a/src/test/test_entrynodes.c b/src/test/test_entrynodes.c index c8dd4b03ea..81d9eb9ab3 100644 --- a/src/test/test_entrynodes.c +++ b/src/test/test_entrynodes.c @@ -3038,6 +3038,7 @@ static const struct testcase_setup_t upgrade_circuits = { upgrade_circuits_setup, upgrade_circuits_cleanup }; +#ifndef COCCI #define NO_PREFIX_TEST(name) \ { #name, test_ ## name, 0, NULL, NULL } @@ -3060,6 +3061,7 @@ static const struct testcase_setup_t upgrade_circuits = { &upgrade_circuits, (void*)(arg REASONABLY_FUTURE) }, \ { #name "_reasonably_past", test_entry_guard_ ## name, TT_FORK, \ &upgrade_circuits, (void*)(arg REASONABLY_PAST) } +#endif struct testcase_t entrynodes_tests[] = { NO_PREFIX_TEST(node_preferred_orport), diff --git a/src/test/test_link_handshake.c b/src/test/test_link_handshake.c index 5e78e1ce4d..1371e1ef74 100644 --- a/src/test/test_link_handshake.c +++ b/src/test/test_link_handshake.c @@ -1492,6 +1492,7 @@ AUTHENTICATE_FAIL(missing_ed_auth, "authentication certificate"; }) +#ifndef COCCI #define TEST_RSA(name, flags) \ { #name , test_link_handshake_ ## name, (flags), \ &passthrough_setup, (void*)"RSA" } @@ -1527,6 +1528,7 @@ AUTHENTICATE_FAIL(missing_ed_auth, #define TEST_AUTHENTICATE_ED(name) \ { "authenticate/" #name "_ed25519" , test_link_handshake_auth_ ## name, \ TT_FORK, &setup_authenticate, (void*)3 } +#endif struct testcase_t link_handshake_tests[] = { TEST_RSA(certs_ok, TT_FORK), diff --git a/src/test/test_options.c b/src/test/test_options.c index a6bccdc524..62d477a635 100644 --- a/src/test/test_options.c +++ b/src/test/test_options.c @@ -4163,8 +4163,10 @@ test_options_validate__accel(void *ignored) tor_free(msg); } +#ifndef COCCI #define LOCAL_VALIDATE_TEST(name) \ { "validate__" #name, test_options_validate__ ## name, TT_FORK, NULL, NULL } +#endif struct testcase_t options_tests[] = { { "validate", test_options_validate, TT_FORK, NULL, NULL }, diff --git a/src/test/test_util.c b/src/test/test_util.c index c56d3488ba..b34a9e0ab9 100644 --- a/src/test/test_util.c +++ b/src/test/test_util.c @@ -304,6 +304,7 @@ test_util_write_chunks_to_file(void *arg) tor_free(temp_str); } +#ifndef COCCI #define _TFE(a, b, f) tt_int_op((a).f, OP_EQ, (b).f) /** test the minimum set of struct tm fields needed for a unique epoch value * this is also the set we use to test tor_timegm */ @@ -316,6 +317,7 @@ test_util_write_chunks_to_file(void *arg) _TFE(a, b, tm_min ); \ _TFE(a, b, tm_sec ); \ TT_STMT_END +#endif static void test_util_time(void *arg) @@ -6256,6 +6258,7 @@ test_util_map_anon_nofork(void *arg) #endif /* defined(_WIN32) */ } +#ifndef COCCI #define UTIL_LEGACY(name) \ { #name, test_util_ ## name , 0, NULL, NULL } @@ -6280,6 +6283,7 @@ test_util_map_anon_nofork(void *arg) { "compress_dos/" #name, test_util_decompress_dos, 0, \ &compress_setup, \ (char*)(identifier) } +#endif #ifdef _WIN32 #define UTIL_TEST_NO_WIN(n, f) { #n, NULL, TT_SKIP, NULL, NULL } -- cgit v1.2.3-54-g00ecf From 67247fa9ac7c2c5b19c0a2b6884ab21f83cc5e5d Mon Sep 17 00:00:00 2001 From: Nick Mathewson Date: Wed, 9 Oct 2019 11:07:18 -0400 Subject: Use various COCCI tests to get mainloop.c to parse. --- src/core/mainloop/mainloop.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/core/mainloop/mainloop.c b/src/core/mainloop/mainloop.c index 6e78a5bb26..dae82fba67 100644 --- a/src/core/mainloop/mainloop.c +++ b/src/core/mainloop/mainloop.c @@ -1338,9 +1338,11 @@ get_signewnym_epoch(void) static int periodic_events_initialized = 0; /* Declare all the timer callback functions... */ +#ifndef COCCI #undef CALLBACK #define CALLBACK(name) \ static int name ## _callback(time_t, const or_options_t *) + CALLBACK(add_entropy); CALLBACK(check_expired_networkstatus); CALLBACK(clean_caches); @@ -1363,11 +1365,10 @@ CALLBACK(second_elapsed); #undef CALLBACK /* Now we declare an array of periodic_event_item_t for each periodic event */ -#ifndef COCCI #define CALLBACK(name, r, f) \ PERIODIC_EVENT(name, PERIODIC_EVENT_ROLE_ ## r, f) -#endif #define FL(name) (PERIODIC_EVENT_FLAG_ ## name) +#endif STATIC periodic_event_item_t mainloop_periodic_events[] = { @@ -1418,8 +1419,10 @@ STATIC periodic_event_item_t mainloop_periodic_events[] = { END_OF_PERIODIC_EVENTS }; +#ifndef COCCI #undef CALLBACK #undef FL +#endif /* These are pointers to members of periodic_events[] that are used to * implement particular callbacks. We keep them separate here so that we @@ -1518,8 +1521,10 @@ initialize_periodic_events(void) /* Set up all periodic events. We'll launch them by roles. */ +#ifndef COCCI #define NAMED_CALLBACK(name) \ STMT_BEGIN name ## _event = periodic_events_find( #name ); STMT_END +#endif NAMED_CALLBACK(prune_old_routers); NAMED_CALLBACK(fetch_networkstatus); -- cgit v1.2.3-54-g00ecf From d9bad0203bb0926883d8d1513ddc966e84fcc734 Mon Sep 17 00:00:00 2001 From: Nick Mathewson Date: Wed, 9 Oct 2019 11:10:08 -0400 Subject: Disable a couple of iterator macros when COCCI is defined. --- src/core/or/circuitpadding.c | 2 ++ src/feature/hs/hs_service.c | 2 ++ 2 files changed, 4 insertions(+) (limited to 'src') diff --git a/src/core/or/circuitpadding.c b/src/core/or/circuitpadding.c index 99c68d5f6b..d561b63ffd 100644 --- a/src/core/or/circuitpadding.c +++ b/src/core/or/circuitpadding.c @@ -116,6 +116,7 @@ STATIC smartlist_t *origin_padding_machines = NULL; * runtime and as long as circuits are alive. */ STATIC smartlist_t *relay_padding_machines = NULL; +#ifndef COCCI /** Loop over the current padding state machines using loop_var as the * loop variable. */ #define FOR_EACH_CIRCUIT_MACHINE_BEGIN(loop_var) \ @@ -130,6 +131,7 @@ STATIC smartlist_t *relay_padding_machines = NULL; if (!(circ)->padding_info[loop_var]) \ continue; #define FOR_EACH_ACTIVE_CIRCUIT_MACHINE_END } STMT_END ; +#endif /** * Free the machineinfo at an index diff --git a/src/feature/hs/hs_service.c b/src/feature/hs/hs_service.c index 7021190903..600d64cacc 100644 --- a/src/feature/hs/hs_service.c +++ b/src/feature/hs/hs_service.c @@ -67,6 +67,7 @@ #include #endif +#ifndef COCCI /* Helper macro. Iterate over every service in the global map. The var is the * name of the service pointer. */ #define FOR_EACH_SERVICE_BEGIN(var) \ @@ -88,6 +89,7 @@ (var = service->desc_next); \ if (var == NULL) continue; #define FOR_EACH_DESCRIPTOR_END } STMT_END ; +#endif /* Onion service directory file names. */ static const char fname_keyfile_prefix[] = "hs_ed25519"; -- cgit v1.2.3-54-g00ecf From ef5d1e6b656e752c79bb5df26f64aef51550594f Mon Sep 17 00:00:00 2001 From: Nick Mathewson Date: Wed, 9 Oct 2019 11:12:41 -0400 Subject: consdiff disable a macro when running with COCCI --- src/feature/dircommon/consdiff.c | 2 ++ 1 file changed, 2 insertions(+) (limited to 'src') diff --git a/src/feature/dircommon/consdiff.c b/src/feature/dircommon/consdiff.c index 8e93953f73..f75ec848b5 100644 --- a/src/feature/dircommon/consdiff.c +++ b/src/feature/dircommon/consdiff.c @@ -530,10 +530,12 @@ typedef struct router_id_iterator_t { cdline_t hash; } router_id_iterator_t; +#ifndef COCCI /** * Initializer for a router_id_iterator_t. */ #define ROUTER_ID_ITERATOR_INIT { { NULL, 0 }, { NULL, 0 } } +#endif /** Given an index *idxp into the consensus at cons, advance * the index to the next router line ("r ...") in the consensus, or to -- cgit v1.2.3-54-g00ecf From 54c5366aa15d667484a93abf16d166db7981a0ea Mon Sep 17 00:00:00 2001 From: Nick Mathewson Date: Wed, 9 Oct 2019 12:36:47 -0400 Subject: feature/control: wrap some problem macros in COCCI --- src/feature/control/control_cmd.c | 2 ++ src/feature/control/control_events.c | 2 ++ 2 files changed, 4 insertions(+) (limited to 'src') diff --git a/src/feature/control/control_cmd.c b/src/feature/control/control_cmd.c index ad4a4ef0af..999095edb3 100644 --- a/src/feature/control/control_cmd.c +++ b/src/feature/control/control_cmd.c @@ -2245,6 +2245,7 @@ typedef struct control_cmd_def_t { */ #define CMD_FL_WIPE (1u<<0) +#ifndef COCCI /** Macro: declare a command with a one-line argument, a given set of flags, * and a syntax definition. **/ @@ -2277,6 +2278,7 @@ typedef struct control_cmd_def_t { 0, \ &obsolete_syntax, \ } +#endif /** * An array defining all the recognized controller commands. diff --git a/src/feature/control/control_events.c b/src/feature/control/control_events.c index 82ea943999..cc6b5019b3 100644 --- a/src/feature/control/control_events.c +++ b/src/feature/control/control_events.c @@ -1660,6 +1660,7 @@ control_event_status(int type, int severity, const char *format, va_list args) return 0; } +#ifndef COCCI #define CONTROL_EVENT_STATUS_BODY(event, sev) \ int r; \ do { \ @@ -1671,6 +1672,7 @@ control_event_status(int type, int severity, const char *format, va_list args) r = control_event_status((event), (sev), format, ap); \ va_end(ap); \ } while (0) +#endif /** Format and send an EVENT_STATUS_GENERAL event whose main text is obtained * by formatting the arguments using the printf-style format. */ -- cgit v1.2.3-54-g00ecf From 3e41459dff9e62cabe2636eac61d19b32dd0a4e1 Mon Sep 17 00:00:00 2001 From: Nick Mathewson Date: Wed, 9 Oct 2019 12:39:31 -0400 Subject: confmacros.h: fix coccinelle parsing. --- scripts/coccinelle/tor-coccinelle.h | 3 +++ src/lib/conf/confmacros.h | 2 ++ 2 files changed, 5 insertions(+) (limited to 'src') diff --git a/scripts/coccinelle/tor-coccinelle.h b/scripts/coccinelle/tor-coccinelle.h index c83dce3c5c..44d79325eb 100644 --- a/scripts/coccinelle/tor-coccinelle.h +++ b/scripts/coccinelle/tor-coccinelle.h @@ -57,4 +57,7 @@ #define NS_DECL(a, b, c) a b c #define NS(a) a +#define CONF_TEST_MEMBERS(a,b,c) +#define DUMMY_CONF_TEST_MEMBERS + #define EAT_SEMICOLON extern int dummy__; diff --git a/src/lib/conf/confmacros.h b/src/lib/conf/confmacros.h index 68121891f1..6449458a10 100644 --- a/src/lib/conf/confmacros.h +++ b/src/lib/conf/confmacros.h @@ -15,11 +15,13 @@ #include "orconfig.h" #include "lib/conf/conftesting.h" +#ifndef COCCI /** * Used to indicate the end of an array of configuration variables. **/ #define END_OF_CONFIG_VARS \ { .member = { .name = NULL } DUMMY_CONF_TEST_MEMBERS } +#endif /** * Declare a config_var_t as a member named membername of the structure -- cgit v1.2.3-54-g00ecf From 04a74d4aa7d990b03ea07182e86263ed1651db43 Mon Sep 17 00:00:00 2001 From: Nick Mathewson Date: Wed, 9 Oct 2019 12:42:09 -0400 Subject: conftesting.h: when COCCI is defined, disable unhandled macros --- src/lib/conf/conftesting.h | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/lib/conf/conftesting.h b/src/lib/conf/conftesting.h index a40c9bc97c..8f82b5bf18 100644 --- a/src/lib/conf/conftesting.h +++ b/src/lib/conf/conftesting.h @@ -12,7 +12,9 @@ #ifndef TOR_LIB_CONF_CONFTESTING_H #define TOR_LIB_CONF_CONFTESTING_H +#ifndef COCCI #ifdef TOR_UNIT_TESTS +#define USE_CONF_TESTING /** * Union used when building in test mode typechecking the members of a type * used with confparse.c. See CONF_CHECK_VAR_TYPE for a description of how @@ -41,12 +43,10 @@ typedef union { // XXXX this doesn't belong at this level of abstraction. struct routerset_t **ROUTERSET; } confparse_dummy_values_t; -#endif /* defined(TOR_UNIT_TESTS) */ /* Macros to define extra members inside config_var_t fields, and at the * end of a list of them. */ -#ifdef TOR_UNIT_TESTS /* This is a somewhat magic type-checking macro for users of confparse.c. * It initializes a union member "confparse_dummy_values_t.conftype" with * the address of a static member "tp_dummy.member". This @@ -72,9 +72,10 @@ typedef union { #define DUMMY_CONF_TEST_MEMBERS , .var_ptr_dummy={ .INT=NULL } #define DUMMY_TYPECHECK_INSTANCE(tp) \ static tp tp ## _dummy +#endif +#endif -#else /* !(defined(TOR_UNIT_TESTS)) */ - +#ifndef USE_CONF_TESTING #define CONF_TEST_MEMBERS(tp, conftype, member) /* Repeatedly declarable incomplete struct to absorb redundant semicolons */ #define DUMMY_TYPECHECK_INSTANCE(tp) \ -- cgit v1.2.3-54-g00ecf From 9453746b5e2276e26c4aaadba99aec2530889ea0 Mon Sep 17 00:00:00 2001 From: Nick Mathewson Date: Wed, 9 Oct 2019 12:47:21 -0400 Subject: dispatch_naming.c: when COCCI is defined, disable unparseable macros. --- src/lib/dispatch/dispatch_naming.c | 2 ++ 1 file changed, 2 insertions(+) (limited to 'src') diff --git a/src/lib/dispatch/dispatch_naming.c b/src/lib/dispatch/dispatch_naming.c index 83d9a2d604..79411cb3a1 100644 --- a/src/lib/dispatch/dispatch_naming.c +++ b/src/lib/dispatch/dispatch_naming.c @@ -33,6 +33,7 @@ dispatch_naming_init(void) { } +#ifndef COCCI /* Helper macro: declare functions to map IDs to and from names for a given * type in a namemap_t. */ @@ -56,6 +57,7 @@ dispatch_naming_init(void) return namemap_get_size(&type##_id_map); \ } \ EAT_SEMICOLON +#endif DECLARE_ID_MAP_FNS(message); DECLARE_ID_MAP_FNS(channel); -- cgit v1.2.3-54-g00ecf From 0abe89519b5f9d4710b06c6ec77b69879c76e18b Mon Sep 17 00:00:00 2001 From: Nick Mathewson Date: Wed, 9 Oct 2019 12:48:56 -0400 Subject: timers.c: define TIMEOUT_PUBLIC to no tokens when using COCCI. --- src/lib/evloop/timers.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/lib/evloop/timers.c b/src/lib/evloop/timers.c index 4b2a96ef7d..23562971ca 100644 --- a/src/lib/evloop/timers.c +++ b/src/lib/evloop/timers.c @@ -56,7 +56,9 @@ struct timeout_cb { /* * These definitions are for timeouts.c and timeouts.h. */ -#ifdef __GNUC__ +#ifdef COCCI +#define TIMEOUT_PUBLIC +#elif defined(__GNUC__) /* We're not exposing any of the functions outside this file. */ #define TIMEOUT_PUBLIC __attribute__((__unused__)) static #else -- cgit v1.2.3-54-g00ecf From 9f50a92a7e858591f65bb9c6f0a2b164032bccc6 Mon Sep 17 00:00:00 2001 From: Nick Mathewson Date: Wed, 9 Oct 2019 12:50:08 -0400 Subject: Fix a macro in address.c so coccinelle can understand it --- src/lib/net/address.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src') diff --git a/src/lib/net/address.c b/src/lib/net/address.c index 0a2c84caf2..dd6a83974a 100644 --- a/src/lib/net/address.c +++ b/src/lib/net/address.c @@ -1392,7 +1392,7 @@ get_interface_addresses_win32(int severity, sa_family_t family) /* This is defined on Mac OS X */ #ifndef _SIZEOF_ADDR_IFREQ -#define _SIZEOF_ADDR_IFREQ sizeof +#define _SIZEOF_ADDR_IFREQ(x) sizeof(x) #endif /* Free ifc->ifc_buf safely. */ -- cgit v1.2.3-54-g00ecf From 2695f7e68c23612804c9f74f33701eed4c949d70 Mon Sep 17 00:00:00 2001 From: Nick Mathewson Date: Wed, 9 Oct 2019 12:51:56 -0400 Subject: timeval.h: Coccinelle cannot understand timercmp. --- src/lib/wallclock/timeval.h | 2 ++ 1 file changed, 2 insertions(+) (limited to 'src') diff --git a/src/lib/wallclock/timeval.h b/src/lib/wallclock/timeval.h index e632d04a04..897a864416 100644 --- a/src/lib/wallclock/timeval.h +++ b/src/lib/wallclock/timeval.h @@ -69,6 +69,7 @@ } while (0) #endif /* !defined(timersub) */ +#ifndef COCCI #ifndef timercmp /** Replacement for timercmp on platforms that do not have it: returns true * iff the relational operator "op" makes the expression tv1 op tv2 true. @@ -82,5 +83,6 @@ ((tv1)->tv_usec op (tv2)->tv_usec) : \ ((tv1)->tv_sec op (tv2)->tv_sec)) #endif /* !defined(timercmp) */ +#endif #endif /* !defined(TOR_TIMEVAL_H) */ -- cgit v1.2.3-54-g00ecf From 514c61e4064dafa73895a8bf6b3733bd2e571c32 Mon Sep 17 00:00:00 2001 From: Nick Mathewson Date: Wed, 9 Oct 2019 12:54:23 -0400 Subject: namemap_st.h: Use COCCI to hide an initializer. --- src/lib/container/namemap_st.h | 2 ++ 1 file changed, 2 insertions(+) (limited to 'src') diff --git a/src/lib/container/namemap_st.h b/src/lib/container/namemap_st.h index 5008fd5855..2fa73fc173 100644 --- a/src/lib/container/namemap_st.h +++ b/src/lib/container/namemap_st.h @@ -28,7 +28,9 @@ struct namemap_t { struct smartlist_t *names; }; +#ifndef COCCI /** Macro to initialize a namemap. */ #define NAMEMAP_INIT() { HT_INITIALIZER(), NULL } +#endif #endif /* !defined(NAMEMAP_ST_H) */ -- cgit v1.2.3-54-g00ecf From 41f44d87604c8b780e9c3a1e60f006633e0a6d1b Mon Sep 17 00:00:00 2001 From: Nick Mathewson Date: Wed, 9 Oct 2019 12:55:37 -0400 Subject: smartlist.h: use COCCI to hide SMARTLIST_FOREACH_JOIN from Coccinelle --- src/lib/container/smartlist.h | 2 ++ 1 file changed, 2 insertions(+) (limited to 'src') diff --git a/src/lib/container/smartlist.h b/src/lib/container/smartlist.h index 25638e4b22..1dadf4ae6b 100644 --- a/src/lib/container/smartlist.h +++ b/src/lib/container/smartlist.h @@ -92,6 +92,7 @@ char *smartlist_join_strings2(smartlist_t *sl, const char *join, size_t join_len, int terminate, size_t *len_out) ATTR_MALLOC; +#ifndef COCCI /* Helper: Given two lists of items, possibly of different types, such that * both lists are sorted on some common field (as determined by a comparison * expression cmpexpr), and such that one list (sl1) has no @@ -165,5 +166,6 @@ char *smartlist_join_strings2(smartlist_t *sl, const char *join, #define SMARTLIST_FOREACH_JOIN_END(var1, var2) \ } \ STMT_END +#endif #endif /* !defined(TOR_SMARTLIST_H) */ -- cgit v1.2.3-54-g00ecf From d1cdb1a24e6289d5ce6f2c1433395abae7185e6e Mon Sep 17 00:00:00 2001 From: Nick Mathewson Date: Wed, 9 Oct 2019 12:57:37 -0400 Subject: Use STMT_BEGIN/END in parse_int.c so coccinelle can handle it. --- src/lib/string/parse_int.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/lib/string/parse_int.c b/src/lib/string/parse_int.c index fbdd554a47..fd4422ecd0 100644 --- a/src/lib/string/parse_int.c +++ b/src/lib/string/parse_int.c @@ -9,6 +9,7 @@ **/ #include "lib/string/parse_int.h" +#include "lib/cc/compat_compiler.h" #include #include @@ -17,6 +18,7 @@ /* Helper: common code to check whether the result of a strtol or strtoul or * strtoll is correct. */ #define CHECK_STRTOX_RESULT() \ + STMT_BEGIN \ /* Did an overflow occur? */ \ if (errno == ERANGE) \ goto err; \ @@ -38,7 +40,8 @@ err: \ if (ok) *ok = 0; \ if (next) *next = endptr; \ - return 0 + return 0; \ + STMT_END /** Extract a long from the start of s, in the given numeric * base. If base is 0, s is parsed as a decimal, -- cgit v1.2.3-54-g00ecf From fb4b6b64360659d7f9807fe9284cf3eab2e64ff3 Mon Sep 17 00:00:00 2001 From: Nick Mathewson Date: Wed, 9 Oct 2019 12:59:22 -0400 Subject: weakrng.h: use COCCI to hide a macro coccinelle cannot parse. --- src/lib/intmath/weakrng.h | 3 +++ 1 file changed, 3 insertions(+) (limited to 'src') diff --git a/src/lib/intmath/weakrng.h b/src/lib/intmath/weakrng.h index 40941e59b2..d583c8f79b 100644 --- a/src/lib/intmath/weakrng.h +++ b/src/lib/intmath/weakrng.h @@ -19,8 +19,11 @@ typedef struct tor_weak_rng_t { uint32_t state; } tor_weak_rng_t; +#ifndef COCCI #define TOR_WEAK_RNG_INIT {383745623} +#endif #define TOR_WEAK_RANDOM_MAX (INT_MAX) + void tor_init_weak_random(tor_weak_rng_t *weak_rng, unsigned seed); int32_t tor_weak_random(tor_weak_rng_t *weak_rng); int32_t tor_weak_random_range(tor_weak_rng_t *rng, int32_t top); -- cgit v1.2.3-54-g00ecf From c77f57d37bbea4e7281c2de95a9f19b885290111 Mon Sep 17 00:00:00 2001 From: Nick Mathewson Date: Wed, 9 Oct 2019 13:07:15 -0400 Subject: util_bug.h: Coccinelle does not understand IF_BUG_ONCE or #nodef. --- src/lib/log/util_bug.h | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/lib/log/util_bug.h b/src/lib/log/util_bug.h index 546ae1e3ef..8c233da735 100644 --- a/src/lib/log/util_bug.h +++ b/src/lib/log/util_bug.h @@ -131,7 +131,9 @@ #undef BUG // Coverity defines this in global headers; let's override it. This is a // magic coverity-only preprocessor thing. +#ifndef COCCI #nodef BUG(x) (x) +#endif #endif /* defined(__COVERITY__) */ #if defined(__COVERITY__) || defined(__clang_analyzer__) @@ -200,6 +202,7 @@ : 0) #endif /* defined(ALL_BUGS_ARE_FATAL) || ... */ +#ifndef COCCI #ifdef __GNUC__ #define IF_BUG_ONCE__(cond,var) \ if (( { \ @@ -208,7 +211,7 @@ if (bool_result && !var) { \ var = 1; \ tor_bug_occurred_(SHORT_FILE__, __LINE__, __func__, \ - "!("#cond")", 1, NULL); \ + ("!("#cond")"), 1, NULL); \ } \ bool_result; } )) #else /* !(defined(__GNUC__)) */ @@ -218,10 +221,12 @@ (var ? 1 : \ (var=1, \ tor_bug_occurred_(SHORT_FILE__, __LINE__, __func__, \ - "!("#cond")", 1, NULL), \ + ("!("#cond")"), 1, NULL), \ 1)) \ : 0) #endif /* defined(__GNUC__) */ +#endif + #define IF_BUG_ONCE_VARNAME_(a) \ warning_logged_on_ ## a ## __ #define IF_BUG_ONCE_VARNAME__(a) \ -- cgit v1.2.3-54-g00ecf From 189375fb5dfb6757f1aa0ed36532d933fc382e1e Mon Sep 17 00:00:00 2001 From: Nick Mathewson Date: Wed, 9 Oct 2019 13:09:44 -0400 Subject: ratelim.h: use COCCI to hide an initializer. --- src/lib/log/ratelim.h | 2 ++ 1 file changed, 2 insertions(+) (limited to 'src') diff --git a/src/lib/log/ratelim.h b/src/lib/log/ratelim.h index 1db54ba726..64f52df666 100644 --- a/src/lib/log/ratelim.h +++ b/src/lib/log/ratelim.h @@ -45,7 +45,9 @@ typedef struct ratelim_t { int n_calls_since_last_time; } ratelim_t; +#ifndef COCCI #define RATELIM_INIT(r) { (r), 0, 0 } +#endif #define RATELIM_TOOMANY (16*1000*1000) char *rate_limit_log(ratelim_t *lim, time_t now); -- cgit v1.2.3-54-g00ecf From 4346e5569ef9957688aa5b50eab58e7bbe145bb1 Mon Sep 17 00:00:00 2001 From: Nick Mathewson Date: Wed, 9 Oct 2019 13:12:28 -0400 Subject: ctassert.h: fix CTASSERT_DECL so coccinelle can parse it. --- src/lib/cc/ctassert.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src') diff --git a/src/lib/cc/ctassert.h b/src/lib/cc/ctassert.h index bedf0b83a6..d9d3aa40b0 100644 --- a/src/lib/cc/ctassert.h +++ b/src/lib/cc/ctassert.h @@ -46,7 +46,7 @@ #define CTASSERT_EXPN(x, a, b) CTASSERT_DECL(x, a, b) #define CTASSERT_DECL(x, a, b) \ - typedef char tor_ctassert_##a##_##b[(x) ? 1 : -1] ATTR_UNUSED + typedef char tor_ctassert_##a##_##b[(x) ? 1 : -1] ATTR_UNUSED; EAT_SEMICOLON #endif /* __STDC_VERSION__ >= 201112L */ -- cgit v1.2.3-54-g00ecf From 0b862a7616cfac4db2c85288abf59916b662f03b Mon Sep 17 00:00:00 2001 From: Nick Mathewson Date: Wed, 9 Oct 2019 13:13:54 -0400 Subject: threads.h: coccinelle cannot understand a macro. --- src/lib/thread/threads.h | 2 ++ 1 file changed, 2 insertions(+) (limited to 'src') diff --git a/src/lib/thread/threads.h b/src/lib/thread/threads.h index ecf60641b5..fcce651936 100644 --- a/src/lib/thread/threads.h +++ b/src/lib/thread/threads.h @@ -106,7 +106,9 @@ void tor_threadlocal_set(tor_threadlocal_t *threadlocal, void *value); typedef struct atomic_counter_t { atomic_size_t val; } atomic_counter_t; +#ifndef COCCI #define ATOMIC_LINKAGE static +#endif #else /* !(defined(HAVE_WORKING_STDATOMIC)) */ typedef struct atomic_counter_t { tor_mutex_t mutex; -- cgit v1.2.3-54-g00ecf From 0da349aa5ebc6d33c92a4f979002c2b0282afc41 Mon Sep 17 00:00:00 2001 From: Nick Mathewson Date: Wed, 9 Oct 2019 13:22:34 -0400 Subject: test.h: Use COCCI to suppress macros Coccinelle does not understand. --- src/test/test.h | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'src') diff --git a/src/test/test.h b/src/test/test.h index d6a1d19ea1..59c4bc7978 100644 --- a/src/test/test.h +++ b/src/test/test.h @@ -37,6 +37,7 @@ #define test_memeq_hex(expr1, hex) test_mem_op_hex(expr1, OP_EQ, hex) +#ifndef COCCI #define tt_double_op(a,op,b) \ tt_assert_test_type(a,b,#a" "#op" "#b,double,(val1_ op val2_),"%g", \ TT_EXIT_TEST_FUNCTION) @@ -64,6 +65,7 @@ tt_assert_test_fmt_type(a,b,#a" "#op" "#b,int64_t,(val1_ op val2_), \ int64_t, "%"PRId64, \ {print_ = (int64_t) value_;}, {}, TT_EXIT_TEST_FUNCTION) +#endif /** * Declare that the test is done, even though no tt___op() calls were made. @@ -145,6 +147,7 @@ void free_pregenerated_keys(void); #define NAME_TEST_(name) #name #define NAME_TEST(name) NAME_TEST_(name) #define ASPECT(test_module, test_name) US2_CONCAT_2__(test_module, test_name) +#ifndef COCCI #define TEST_CASE(function) \ { \ NAME_TEST(function), \ @@ -161,15 +164,18 @@ void free_pregenerated_keys(void); NULL, \ NULL, \ } +#endif #define NS(name) US_CONCAT_3_(NS_MODULE, NS_SUBMODULE, name) #define NS_FULL(module, submodule, name) US_CONCAT_3_(module, submodule, name) #define CALLED(mock_name) US_CONCAT_2_(NS(mock_name), called) +#ifndef COCCI #define NS_DECL(retval, mock_fn, args) \ extern int CALLED(mock_fn); \ static retval NS(mock_fn) args; int CALLED(mock_fn) = 0 #define NS_MOCK(name) MOCK(name, NS(name)) +#endif #define NS_UNMOCK(name) UNMOCK(name) extern const struct testcase_setup_t passthrough_setup; -- cgit v1.2.3-54-g00ecf From 7e7a4874b8fa333d1840cc5f2c0b118d6a0e7c47 Mon Sep 17 00:00:00 2001 From: Nick Mathewson Date: Wed, 9 Oct 2019 13:24:16 -0400 Subject: test_addr.c: use COCCI to suppress macros coccinelle cannot parse. --- src/test/test_addr.c | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'src') diff --git a/src/test/test_addr.c b/src/test/test_addr.c index 50543293c4..09faa540f4 100644 --- a/src/test/test_addr.c +++ b/src/test/test_addr.c @@ -51,6 +51,7 @@ test_addr_basic(void *arg) ; } +#ifndef COCCI #define test_op_ip6_(a,op,b,e1,e2) \ STMT_BEGIN \ tt_assert_test_fmt_type(a,b,e1" "#op" "e2,struct in6_addr*, \ @@ -68,6 +69,7 @@ test_addr_basic(void *arg) TT_EXIT_TEST_FUNCTION \ ); \ STMT_END +#endif /** Helper: Assert that two strings both decode as IPv6 addresses with * tor_inet_pton(), and both decode to the same address. */ @@ -110,6 +112,7 @@ test_addr_basic(void *arg) TT_DIE(("%s was not internal", a)); \ STMT_END +#ifndef COCCI /** Helper: Assert that a and b, when parsed by * tor_inet_pton(), give addresses that compare in the order defined by * op with tor_addr_compare(). */ @@ -134,6 +137,7 @@ test_addr_basic(void *arg) TT_DIE(("Failed: tor_addr_compare_masked(%s,%s,%d) %s 0", \ a, b, m, #op)); \ STMT_END +#endif /** Helper: assert that xx is parseable as a masked IPv6 address with * ports by tor_parse_mask_addr_ports(), with family f, IP address -- cgit v1.2.3-54-g00ecf