dovecot: Use N_ELEMENTS() macro instead of doing sizeof()/sizeof...
dovecot at dovecot.org
dovecot at dovecot.org
Mon Sep 24 20:27:26 EEST 2007
details: http://hg.dovecot.org/dovecot/rev/59490181469e
changeset: 6494:59490181469e
user: Timo Sirainen <tss at iki.fi>
date: Mon Sep 24 20:27:16 2007 +0300
description:
Use N_ELEMENTS() macro instead of doing sizeof()/sizeof([0]) ourself.
diffstat:
14 files changed, 22 insertions(+), 38 deletions(-)
src/deliver/mail-send.c | 5 ++---
src/imap/commands.c | 6 ++----
src/imap/imap-fetch.c | 3 +--
src/lib-index/mail-index-transaction.c | 3 +--
src/lib-otp/otp-hash.c | 10 ++++------
src/lib-storage/index/mbox/mbox-md5.c | 4 +---
src/lib-storage/index/mbox/mbox-storage.c | 6 ++----
src/lib-storage/index/mbox/mbox-sync-parse.c | 5 ++---
src/lib/backtrace-string.c | 2 +-
src/lib/ioloop-notify-kqueue.c | 3 +--
src/lib/primes.c | 2 +-
src/master/capabilities-posix.c | 4 ++--
src/master/ssl-init-openssl.c | 4 +---
src/plugins/quota/quota.c | 3 +--
diffs (275 lines):
diff -r 2821a472806f -r 59490181469e src/deliver/mail-send.c
--- a/src/deliver/mail-send.c Mon Sep 24 20:17:59 2007 +0300
+++ b/src/deliver/mail-send.c Mon Sep 24 20:27:16 2007 +0300
@@ -131,7 +131,7 @@ int mail_send_rejection(struct mail *mai
input = i_stream_create_header_filter(input,
HEADER_FILTER_EXCLUDE | HEADER_FILTER_NO_CR |
HEADER_FILTER_HIDE_BODY, exclude_headers,
- sizeof(exclude_headers) / sizeof(exclude_headers[0]),
+ N_ELEMENTS(exclude_headers),
null_header_filter_callback, NULL);
while ((ret = i_stream_read_data(input, &data, &size, 0)) > 0) {
@@ -170,8 +170,7 @@ int mail_send_forward(struct mail *mail,
input = i_stream_create_header_filter(input, HEADER_FILTER_EXCLUDE |
HEADER_FILTER_NO_CR, hide_headers,
- sizeof(hide_headers) /
- sizeof(hide_headers[0]),
+ N_ELEMENTS(hide_headers),
null_header_filter_callback, NULL);
while ((ret = i_stream_read_data(input, &data, &size, 0)) > 0) {
diff -r 2821a472806f -r 59490181469e src/imap/commands.c
--- a/src/imap/commands.c Mon Sep 24 20:17:59 2007 +0300
+++ b/src/imap/commands.c Mon Sep 24 20:27:16 2007 +0300
@@ -38,8 +38,7 @@ const struct command imap4rev1_commands[
{ "UID SEARCH", cmd_search, COMMAND_FLAG_BREAKS_SEQS },
{ "UID STORE", cmd_store, COMMAND_FLAG_BREAKS_SEQS }
};
-#define IMAP4REV1_COMMANDS_COUNT \
- (sizeof(imap4rev1_commands) / sizeof(imap4rev1_commands[0]))
+#define IMAP4REV1_COMMANDS_COUNT N_ELEMENTS(imap4rev1_commands)
const struct command imap_ext_commands[] = {
{ "IDLE", cmd_idle, COMMAND_FLAG_BREAKS_SEQS },
@@ -52,8 +51,7 @@ const struct command imap_ext_commands[]
{ "UNSELECT", cmd_unselect, COMMAND_FLAG_BREAKS_MAILBOX },
{ "X-CANCEL", cmd_x_cancel, 0 }
};
-#define IMAP_EXT_COMMANDS_COUNT \
- (sizeof(imap_ext_commands) / sizeof(imap_ext_commands[0]))
+#define IMAP_EXT_COMMANDS_COUNT N_ELEMENTS(imap_ext_commands)
static ARRAY_DEFINE(commands, struct command);
static bool commands_unsorted;
diff -r 2821a472806f -r 59490181469e src/imap/imap-fetch.c
--- a/src/imap/imap-fetch.c Mon Sep 24 20:17:59 2007 +0300
+++ b/src/imap/imap-fetch.c Mon Sep 24 20:27:16 2007 +0300
@@ -86,8 +86,7 @@ struct imap_fetch_context *imap_fetch_in
if (fetch_handlers == NULL) {
imap_fetch_handlers_register(default_handlers,
- sizeof(default_handlers) /
- sizeof(default_handlers[0]));
+ N_ELEMENTS(default_handlers));
}
ctx = p_new(cmd->pool, struct imap_fetch_context, 1);
diff -r 2821a472806f -r 59490181469e src/lib-index/mail-index-transaction.c
--- a/src/lib-index/mail-index-transaction.c Mon Sep 24 20:17:59 2007 +0300
+++ b/src/lib-index/mail-index-transaction.c Mon Sep 24 20:27:16 2007 +0300
@@ -299,8 +299,7 @@ mail_index_update_day_headers(struct mai
{
struct mail_index_header hdr;
const struct mail_index_record *rec;
- const int max_days =
- sizeof(hdr.day_first_uid) / sizeof(hdr.day_first_uid[0]);
+ const int max_days = N_ELEMENTS(hdr.day_first_uid);
struct tm tm;
time_t stamp;
int i, days;
diff -r 2821a472806f -r 59490181469e src/lib-otp/otp-hash.c
--- a/src/lib-otp/otp-hash.c Mon Sep 24 20:17:59 2007 +0300
+++ b/src/lib-otp/otp-hash.c Mon Sep 24 20:27:16 2007 +0300
@@ -87,22 +87,20 @@ static const struct digest digests[] = {
{ "sha1", F(sha1_init), F(sha1_loop), F(sha1_result), F(sha1_fold) },
};
-#define N_DIGESTS (int)(sizeof(digests) / sizeof(digests[0]))
-
#undef F
const char *digest_name(unsigned int algo)
{
- i_assert(algo < N_DIGESTS);
+ i_assert(algo < N_ELEMENTS(digests));
return digests[algo].name;
}
int digest_find(const char *name)
{
- int i;
+ unsigned int i;
- for (i = 0; i < N_DIGESTS; i++)
+ for (i = 0; i < N_ELEMENTS(digests); i++)
if (strcmp(name, digests[i].name) == 0)
return i;
@@ -111,7 +109,7 @@ int digest_find(const char *name)
int digest_init(struct digest_context *ctx, const unsigned int algo)
{
- i_assert(algo < N_DIGESTS);
+ i_assert(algo < N_ELEMENTS(digests));
ctx->digest = digests + algo;
ctx->digest->init((void *) &ctx->ctx);
diff -r 2821a472806f -r 59490181469e src/lib-storage/index/mbox/mbox-md5.c
--- a/src/lib-storage/index/mbox/mbox-md5.c Mon Sep 24 20:17:59 2007 +0300
+++ b/src/lib-storage/index/mbox/mbox-md5.c Mon Sep 24 20:27:16 2007 +0300
@@ -76,8 +76,6 @@ static struct mbox_md5_header_func md5_h
{ "Received", parse_received },
{ "X-Delivery-ID", parse_x_delivery_id }
};
-#define MD5_HEADER_FUNCS_COUNT \
- (sizeof(md5_header_funcs) / sizeof(*md5_header_funcs))
static int bsearch_header_func_cmp(const void *p1, const void *p2)
{
@@ -102,7 +100,7 @@ void mbox_md5_continue(struct mbox_md5_c
struct mbox_md5_header_func *func;
func = bsearch(hdr->name, md5_header_funcs,
- MD5_HEADER_FUNCS_COUNT, sizeof(*md5_header_funcs),
+ N_ELEMENTS(md5_header_funcs), sizeof(*md5_header_funcs),
bsearch_header_func_cmp);
if (func != NULL)
(void)func->func(ctx, hdr);
diff -r 2821a472806f -r 59490181469e src/lib-storage/index/mbox/mbox-storage.c
--- a/src/lib-storage/index/mbox/mbox-storage.c Mon Sep 24 20:17:59 2007 +0300
+++ b/src/lib-storage/index/mbox/mbox-storage.c Mon Sep 24 20:27:16 2007 +0300
@@ -47,8 +47,7 @@ const char *mbox_hide_headers[] = {
"X-Status",
"X-UID"
};
-unsigned int mbox_hide_headers_count =
- sizeof(mbox_hide_headers) / sizeof(mbox_hide_headers[0]);
+unsigned int mbox_hide_headers_count = N_ELEMENTS(mbox_hide_headers);
/* A bit ugly duplification of the above list. It's safe to modify this list
without bad side effects, just keep the list sorted. */
@@ -62,8 +61,7 @@ const char *mbox_save_drop_headers[] = {
"X-Status",
"X-UID"
};
-unsigned int mbox_save_drop_headers_count =
- sizeof(mbox_save_drop_headers) / sizeof(mbox_save_drop_headers[0]);
+unsigned int mbox_save_drop_headers_count = N_ELEMENTS(mbox_save_drop_headers);
extern struct mail_storage mbox_storage;
extern struct mailbox mbox_mailbox;
diff -r 2821a472806f -r 59490181469e src/lib-storage/index/mbox/mbox-sync-parse.c
--- a/src/lib-storage/index/mbox/mbox-sync-parse.c Mon Sep 24 20:17:59 2007 +0300
+++ b/src/lib-storage/index/mbox/mbox-sync-parse.c Mon Sep 24 20:27:16 2007 +0300
@@ -427,7 +427,6 @@ static struct mbox_sync_header_func head
{ "X-Status", parse_x_status },
{ "X-UID", parse_x_uid }
};
-#define HEADER_FUNCS_COUNT (sizeof(header_funcs) / sizeof(*header_funcs))
static int mbox_sync_bsearch_header_func_cmp(const void *p1, const void *p2)
{
@@ -477,7 +476,7 @@ void mbox_sync_parse_next_mail(struct is
}
func = bsearch(hdr->name, header_funcs,
- HEADER_FUNCS_COUNT, sizeof(*header_funcs),
+ N_ELEMENTS(header_funcs), sizeof(*header_funcs),
mbox_sync_bsearch_header_func_cmp);
if (func != NULL) {
@@ -559,7 +558,7 @@ bool mbox_sync_parse_match_mail(struct m
break;
func = bsearch(hdr->name, header_funcs,
- HEADER_FUNCS_COUNT, sizeof(*header_funcs),
+ N_ELEMENTS(header_funcs), sizeof(*header_funcs),
mbox_sync_bsearch_header_func_cmp);
if (func != NULL) {
if (strcasecmp(hdr->name, "X-UID") == 0) {
diff -r 2821a472806f -r 59490181469e src/lib/backtrace-string.c
--- a/src/lib/backtrace-string.c Mon Sep 24 20:17:59 2007 +0300
+++ b/src/lib/backtrace-string.c Mon Sep 24 20:27:16 2007 +0300
@@ -18,7 +18,7 @@ int backtrace_append(string_t *str)
char **strings;
int ret, i;
- ret = backtrace(stack, sizeof(stack)/sizeof(stack[0]));
+ ret = backtrace(stack, N_ELEMENTS(stack));
if (ret <= STACK_SKIP_COUNT)
return -1;
diff -r 2821a472806f -r 59490181469e src/lib/ioloop-notify-kqueue.c
--- a/src/lib/ioloop-notify-kqueue.c Mon Sep 24 20:17:59 2007 +0300
+++ b/src/lib/ioloop-notify-kqueue.c Mon Sep 24 20:27:16 2007 +0300
@@ -49,8 +49,7 @@ static void event_callback(struct ioloop
ts.tv_sec = 0;
ts.tv_nsec = 0;
- ret = kevent(ctx->kq, NULL, 0, events,
- sizeof(events)/sizeof(events[0]), &ts);
+ ret = kevent(ctx->kq, NULL, 0, events, N_ELEMENTS(events), &ts);
if (ret <= 0) {
if (ret == 0 || errno == EINTR)
return;
diff -r 2821a472806f -r 59490181469e src/lib/primes.c
--- a/src/lib/primes.c Mon Sep 24 20:17:59 2007 +0300
+++ b/src/lib/primes.c Mon Sep 24 20:27:16 2007 +0300
@@ -38,7 +38,7 @@ static const unsigned int primes[] = {
13845163
};
-static const unsigned int primes_count = sizeof(primes) / sizeof(primes[0]);
+static const unsigned int primes_count = N_ELEMENTS(primes);
unsigned int primes_closest(unsigned int num)
{
diff -r 2821a472806f -r 59490181469e src/master/capabilities-posix.c
--- a/src/master/capabilities-posix.c Mon Sep 24 20:17:59 2007 +0300
+++ b/src/master/capabilities-posix.c Mon Sep 24 20:27:16 2007 +0300
@@ -22,9 +22,9 @@ void drop_capabilities(void)
caps = cap_init();
cap_clear(caps);
cap_set_flag(caps, CAP_PERMITTED,
- sizeof(suidcaps) / sizeof(cap_value_t), suidcaps, CAP_SET);
+ N_ELEMENTS(suidcaps), suidcaps, CAP_SET);
cap_set_flag(caps, CAP_EFFECTIVE,
- sizeof(suidcaps) / sizeof(cap_value_t), suidcaps, CAP_SET);
+ N_ELEMENTS(suidcaps), suidcaps, CAP_SET);
cap_set_proc(caps);
cap_free(caps);
}
diff -r 2821a472806f -r 59490181469e src/master/ssl-init-openssl.c
--- a/src/master/ssl-init-openssl.c Mon Sep 24 20:17:59 2007 +0300
+++ b/src/master/ssl-init-openssl.c Mon Sep 24 20:27:16 2007 +0300
@@ -14,8 +14,6 @@
#define DH_GENERATOR 2
static int dh_param_bitsizes[] = { 512, 1024 };
-#define DH_PARAM_BITSIZE_COUNT \
- (sizeof(dh_param_bitsizes)/sizeof(dh_param_bitsizes[0]))
static const char *ssl_last_error(void)
{
@@ -63,7 +61,7 @@ void ssl_generate_parameters(int fd, con
unsigned int i;
int bits;
- for (i = 0; i < DH_PARAM_BITSIZE_COUNT; i++)
+ for (i = 0; i < N_ELEMENTS(dh_param_bitsizes); i++)
generate_dh_parameters(dh_param_bitsizes[i], fd, fname);
bits = 0;
if (write_full(fd, &bits, sizeof(bits)) < 0)
diff -r 2821a472806f -r 59490181469e src/plugins/quota/quota.c
--- a/src/plugins/quota/quota.c Mon Sep 24 20:17:59 2007 +0300
+++ b/src/plugins/quota/quota.c Mon Sep 24 20:27:16 2007 +0300
@@ -35,7 +35,6 @@ static const struct quota_backend *quota
"a_backend_dirsize,
"a_backend_maildir
};
-#define QUOTA_CLASS_COUNT (sizeof(quota_backends)/sizeof(quota_backends[0]))
static int quota_default_test_alloc(struct quota_transaction_context *ctx,
uoff_t size, bool *too_large_r);
@@ -74,7 +73,7 @@ static const struct quota_backend *quota
{
unsigned int i;
- for (i = 0; i < QUOTA_CLASS_COUNT; i++) {
+ for (i = 0; i < N_ELEMENTS(quota_backends); i++) {
if (strcmp(quota_backends[i]->name, name) == 0)
return quota_backends[i];
}
More information about the dovecot-cvs
mailing list