]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
global: Check for enum/array size mismatches with static_assert_array_size()
authorTimo Sirainen <timo.sirainen@open-xchange.com>
Fri, 2 Dec 2022 13:54:07 +0000 (15:54 +0200)
committerTimo Sirainen <timo.sirainen@open-xchange.com>
Mon, 12 Dec 2022 09:49:39 +0000 (11:49 +0200)
18 files changed:
src/auth/auth-request-var-expand.c
src/auth/mech-digest-md5.c
src/doveadm/doveadm-mail-mailbox.c
src/doveadm/dsync/dsync-brain-mails.c
src/doveadm/dsync/dsync-brain.c
src/doveadm/dsync/dsync-ibc-stream.c
src/imap-login/imap-proxy.c
src/imap/imap-client.c
src/lib-fs/fs-randomfail.c
src/lib-index/test-mail-cache.c
src/lib-sql/driver-cassandra.c
src/lib-storage/index/index-mail.c
src/lib/event-filter.c
src/lib/failures.c
src/lib/var-expand-if.c
src/plugins/acl/acl-mailbox-list.c
src/pop3-login/pop3-proxy.c
src/submission-login/submission-proxy.c

index aad851a2546358f86663b592223994148dccea5e..b4859778087132ff551e17f0f229cbc2a8c97946 100644 (file)
@@ -11,7 +11,7 @@ struct auth_request_var_expand_ctx {
 };
 
 const struct var_expand_table
-auth_request_var_expand_static_tab[AUTH_REQUEST_VAR_TAB_COUNT+1] = {
+auth_request_var_expand_static_tab[] = {
        { 'u', NULL, "user" },
        { 'n', NULL, "username" },
        { 'd', NULL, "domain" },
@@ -65,6 +65,8 @@ auth_request_var_expand_static_tab[AUTH_REQUEST_VAR_TAB_COUNT+1] = {
        /* be sure to update AUTH_REQUEST_VAR_TAB_COUNT */
        { '\0', NULL, NULL }
 };
+static_assert_array_size(auth_request_var_expand_static_tab,
+                        AUTH_REQUEST_VAR_TAB_COUNT+1);
 
 static const char *
 escape_none(const char *string,
index c64559a3b1fa1aa36c2bbe763ecc9b8427c83ada..a4abd134ec7b2eefc941b6168440682366ed5679 100644 (file)
@@ -19,6 +19,7 @@
 #define IS_LWS(c) ((c) == ' ' || (c) == '\t')
 
 static const char *qop_names[] = { "auth", "auth-int", "auth-conf" };
+static_assert_array_size(qop_names, QOP_COUNT);
 
 static string_t *get_digest_challenge(struct digest_auth_request *request)
 {
index 8a85737905866cc4a1251a8076fe6c4e06ed7212..a86fb28810530166921e6765925f97d90494f08b 100644 (file)
@@ -65,6 +65,7 @@ static const char *mailbox_list_path_type_names[] = {
        "dir", "alt-dir", "mailbox", "alt-mailbox",
        "control", "index", "index-private", "index-cache", "list-index",
 };
+static_assert_array_size(mailbox_list_path_type_names, MAILBOX_LIST_PATH_TYPE_COUNT);
 
 static void doveadm_mailbox_arg_check(const char *arg)
 {
index 7865148062930079be97307debea582857f9853c..1ee8659357397ee64dc9fe0ee01cf9cea3fc35cf 100644 (file)
@@ -8,7 +8,7 @@
 #include "dsync-mailbox-export.h"
 #include "dsync-brain-private.h"
 
-const char *dsync_box_state_names[DSYNC_BOX_STATE_DONE+1] = {
+const char *dsync_box_state_names[] = {
        "mailbox",
        "changes",
        "attributes",
@@ -17,6 +17,7 @@ const char *dsync_box_state_names[DSYNC_BOX_STATE_DONE+1] = {
        "recv_last_common",
        "done"
 };
+static_assert_array_size(dsync_box_state_names, DSYNC_BOX_STATE_DONE+1);
 
 static bool dsync_brain_master_sync_recv_mailbox(struct dsync_brain *brain)
 {
index a47e85c36b283406c5b60e49fe3a837284b5e1e4..c5adabb929c89c57cb92f6d286f132af150dfb05 100644 (file)
@@ -39,6 +39,7 @@ static const char *dsync_state_names[] = {
        "finish",
        "done"
 };
+static_assert_array_size(dsync_state_names, DSYNC_STATE_DONE+1);
 
 #define BRAIN_MASTER TRUE
 #define BRAIN_SLAVE  FALSE
index 17115b0833fcc2ce27abe259c28cb98d578bd8df..585e74117fbcc42cface2096c2adfb929bd1fe68 100644 (file)
@@ -64,7 +64,7 @@ static const struct {
        const char *required_keys;
        const char *optional_keys;
        unsigned int min_minor_version;
-} items[ITEM_END_OF_LIST+1] = {
+} items[] = {
        { NULL, '\0', NULL, NULL, 0 },
        { .name = "done",
          .chr = 'X',
@@ -139,6 +139,7 @@ static const struct {
 
        { "end_of_list", '\0', NULL, NULL, 0 }
 };
+static_assert_array_size(items, ITEM_END_OF_LIST+1);
 
 struct dsync_ibc_stream {
        struct dsync_ibc ibc;
index a615aca4f1066d9e77b3a0443a0278586d8eca03..fd7916bac10ae138510e59b13bf48348f294f53b 100644 (file)
 #include "imap-quote.h"
 #include "imap-proxy.h"
 
-static const char *imap_proxy_sent_state_names[IMAP_PROXY_SENT_STATE_COUNT] = {
+static const char *imap_proxy_sent_state_names[] = {
        "id", "starttls", "capability",
        "authenticate", "auth-continue", "login"
 };
-static const char *imap_proxy_rcvd_state_names[IMAP_PROXY_RCVD_STATE_COUNT] = {
+static_assert_array_size(imap_proxy_sent_state_names,
+                        IMAP_PROXY_SENT_STATE_COUNT);
+
+static const char *imap_proxy_rcvd_state_names[] = {
        "none", "banner", "id", "starttls", "capability",
        "auth-continue", "login"
 };
+static_assert_array_size(imap_proxy_rcvd_state_names,
+                        IMAP_PROXY_RCVD_STATE_COUNT);
 
 static void proxy_write_id(struct imap_client *client, string_t *str)
 {
@@ -575,6 +580,7 @@ const char *imap_proxy_get_state(struct client *client)
                }
        }
        str_append_c(str, '/');
+
        str_append(str, imap_proxy_rcvd_state_names[imap_client->proxy_rcvd_state]);
        return str_c(str);
 }
index 2b0fcb07dbd0457d557c88b594b3866d58faa762..05fe135975524f5763a86e2591262a3c5525a69e 100644 (file)
@@ -44,7 +44,7 @@ unsigned int imap_client_count = 0;
 unsigned int imap_feature_condstore = UINT_MAX;
 unsigned int imap_feature_qresync = UINT_MAX;
 
-static const char *client_command_state_names[CLIENT_COMMAND_STATE_DONE+1] = {
+static const char *client_command_state_names[] = {
        "wait-input",
        "wait-output",
        "wait-external",
@@ -52,6 +52,8 @@ static const char *client_command_state_names[CLIENT_COMMAND_STATE_DONE+1] = {
        "wait-sync",
        "done"
 };
+static_assert_array_size(client_command_state_names,
+                        CLIENT_COMMAND_STATE_DONE+1);
 
 static void client_idle_timeout(struct client *client)
 {
index e945bb33ed1253c0a8abf1753625cedc9d9ef51c..95962d23848ee5ead2c584fbd5e52c25b629b3c2 100644 (file)
 
 #define RANDOMFAIL_ERROR "Random failure injection"
 
-static const char *fs_op_names[FS_OP_COUNT] = {
+static const char *fs_op_names[] = {
        "wait", "metadata", "prefetch", "read", "write", "lock", "exists",
        "stat", "copy", "rename", "delete", "iter"
 };
+static_assert_array_size(fs_op_names, FS_OP_COUNT);
 
 struct randomfail_fs {
        struct fs fs;
index 1b5ad24971ce4f807a2bc05ec9b2834d7af13624..9938e737c980a6f15e83204a64315ced54b7450c 100644 (file)
@@ -21,7 +21,7 @@ enum {
        TEST_FIELD_YES_FORCED,
        TEST_FIELD_COUNT,
 };
-static const struct mail_cache_field decision_cache_fields[TEST_FIELD_COUNT] = {
+static const struct mail_cache_field decision_cache_fields[] = {
        {
                .name = "no",
                .type = MAIL_CACHE_FIELD_STRING,
@@ -53,6 +53,7 @@ static const struct mail_cache_field decision_cache_fields[TEST_FIELD_COUNT] = {
                .decision = MAIL_CACHE_DECISION_YES | MAIL_CACHE_DECISION_FORCED,
        },
 };
+static_assert_array_size(decision_cache_fields, TEST_FIELD_COUNT);
 
 static void test_mail_cache_fields(void)
 {
index 40409202edbe16eb9daf2f7b8be3bcaa8c29d200..948c792ab622345d82a3ee3e430d3b6a96fb2be2 100644 (file)
@@ -47,7 +47,7 @@ enum cassandra_counter_type {
 
        CASSANDRA_COUNTER_COUNT
 };
-static const char *counter_names[CASSANDRA_COUNTER_COUNT] = {
+static const char *counter_names[] = {
        "sent",
        "recv_ok",
        "recv_err_no_hosts",
@@ -58,6 +58,7 @@ static const char *counter_names[CASSANDRA_COUNTER_COUNT] = {
        "recv_err_other",
        "slow",
 };
+static_assert_array_size(counter_names, CASSANDRA_COUNTER_COUNT);
 
 enum cassandra_query_type {
        CASSANDRA_QUERY_TYPE_READ,
@@ -68,9 +69,11 @@ enum cassandra_query_type {
        CASSANDRA_QUERY_TYPE_COUNT
 };
 
-static const char *cassandra_query_type_names[CASSANDRA_QUERY_TYPE_COUNT] = {
+static const char *cassandra_query_type_names[] = {
        "read", "read-more", "write", "delete"
 };
+static_assert_array_size(cassandra_query_type_names,
+                        CASSANDRA_QUERY_TYPE_COUNT);
 
 struct cassandra_callback {
        unsigned int id;
index 49c73acf6b96645b3a812bd557e05052daec30de..12079a1751d91e11279c2ddb5475e3f4712125dc 100644 (file)
@@ -26,7 +26,7 @@
 #define BODY_SNIPPET_ALGO_V1 "1"
 #define BODY_SNIPPET_MAX_CHARS 200
 
-static struct mail_cache_field global_cache_fields[MAIL_INDEX_CACHE_FIELD_COUNT] = {
+static struct mail_cache_field global_cache_fields[] = {
        { .name = "flags",
          .type = MAIL_CACHE_FIELD_BITMASK,
          .field_size = sizeof(uint32_t) },
@@ -68,6 +68,7 @@ static struct mail_cache_field global_cache_fields[MAIL_INDEX_CACHE_FIELD_COUNT]
           index-status.c when adding more fields. those fields should probably
           just be moved here to the same struct. */
 };
+static_assert_array_size(global_cache_fields, MAIL_INDEX_CACHE_FIELD_COUNT);
 
 static void index_mail_init_data(struct index_mail *mail);
 static int index_mail_parse_body(struct index_mail *mail,
index e33dcb2b0608cdd5b0cdc78329c8383f865e3cb8..ac1d312675d32f1acbd613c7891048283fd9a150 100644 (file)
@@ -33,6 +33,7 @@ static const struct log_type_map {
        [LOG_TYPE_FATAL]   = { EVENT_FILTER_LOG_TYPE_FATAL, "fatal" },
        [LOG_TYPE_PANIC]   = { EVENT_FILTER_LOG_TYPE_PANIC, "panic" },
 };
+static_assert_array_size(event_filter_log_type_map, LOG_TYPE_COUNT);
 
 struct event_filter_query_internal {
        struct event_filter_node *expr;
index 4ea76750984ab108e49a4636ffe010d915638454..5990a750f59ed92cb144f77732562b57bd939e07 100644 (file)
@@ -22,7 +22,7 @@
 #define LOG_TYPE_FLAG_PREFIX_LEN 0x40
 #define LOG_TYPE_FLAG_DISABLE_LOG_PREFIX 0x80
 
-const char *failure_log_type_prefixes[LOG_TYPE_COUNT] = {
+const char *failure_log_type_prefixes[] = {
        "Debug: ",
        "Info: ",
        "Warning: ",
@@ -30,6 +30,7 @@ const char *failure_log_type_prefixes[LOG_TYPE_COUNT] = {
        "Fatal: ",
        "Panic: "
 };
+static_assert_array_size(failure_log_type_prefixes, LOG_TYPE_COUNT);
 
 const char *failure_log_type_names[LOG_TYPE_COUNT] = {
        "debug", "info", "warning", "error", "fatal", "panic"
index aa0a9b3e9d0f871daff7084561f3ba9f6daec2d4..0387840a4a40066a8dc7f69cc63e1debfb796ffd 100644 (file)
@@ -34,7 +34,7 @@ enum var_expand_if_op {
 
 static enum var_expand_if_op var_expand_if_str_to_comp(const char *op)
 {
-       const char *ops[OP_COUNT] = {
+       const char *ops[] = {
                NULL,
                "==",
                "<",
@@ -53,6 +53,7 @@ static enum var_expand_if_op var_expand_if_str_to_comp(const char *op)
                "~",
                "!~",
        };
+       static_assert_array_size(ops, OP_COUNT);
        for(enum var_expand_if_op i = 1; i < OP_COUNT; i++) {
                i_assert(ops[i] != NULL);
                if (strcmp(op, ops[i]) == 0)
index 4d3eb761c6629a91ee511f408da2ee985218c5b8..596bcbb07acc87cee029830581b3063f3ed3a655 100644 (file)
@@ -25,7 +25,7 @@ struct acl_mailbox_list_iterate_context {
        bool autocreate_acls_checked:1;
 };
 
-static const char *acl_storage_right_names[ACL_STORAGE_RIGHT_COUNT] = {
+static const char *acl_storage_right_names[] = {
        MAIL_ACL_LOOKUP,
        MAIL_ACL_READ,
        MAIL_ACL_WRITE,
@@ -38,6 +38,7 @@ static const char *acl_storage_right_names[ACL_STORAGE_RIGHT_COUNT] = {
        MAIL_ACL_DELETE,
        MAIL_ACL_ADMIN
 };
+static_assert_array_size(acl_storage_right_names, ACL_STORAGE_RIGHT_COUNT);
 
 #define ACL_LIST_ITERATE_CONTEXT(obj) \
        MODULE_CONTEXT_REQUIRE(obj, acl_mailbox_list_module)
index 33786971f2a4f41c849306981dc5320cb2d851eb..2641da8c288976e9ef66f3c45eb2bf230621cbb2 100644 (file)
 #include "client.h"
 #include "pop3-proxy.h"
 
-static const char *pop3_proxy_state_names[POP3_PROXY_STATE_COUNT] = {
+static const char *pop3_proxy_state_names[] = {
        "banner", "starttls", "xclient", "login1", "login2"
 };
+static_assert_array_size(pop3_proxy_state_names, POP3_PROXY_STATE_COUNT);
 
 static int proxy_send_login(struct pop3_client *client, struct ostream *output)
 {
index a98d0bd59d9fc1366a6fe0e0e8767141b4463a47..fac0b52ccc4efd2f6c41bb4b563a0bb6f4f76223 100644 (file)
 
 #include <ctype.h>
 
-static const char *submission_proxy_state_names[SUBMISSION_PROXY_STATE_COUNT] = {
+static const char *submission_proxy_state_names[] = {
        "banner", "ehlo", "starttls", "tls-ehlo", "xclient", "xclient-ehlo", "authenticate"
 };
+static_assert_array_size(submission_proxy_state_names,
+                        SUBMISSION_PROXY_STATE_COUNT);
 
 static void
 submission_proxy_success_reply_sent(