dovecot-2.2: Replaced all -1U and (unsigned int)-1 with UINT_MAX.

dovecot at dovecot.org dovecot at dovecot.org
Sun Feb 24 09:16:39 EET 2013


details:   http://hg.dovecot.org/dovecot-2.2/rev/d3cf06639864
changeset: 15904:d3cf06639864
user:      Timo Sirainen <tss at iki.fi>
date:      Sun Feb 24 09:16:31 2013 +0200
description:
Replaced all -1U and (unsigned int)-1 with UINT_MAX.
It's somewhat clearer this way. Also clang's -fsanitize=integer gives
runtime errors about -1U (but not about explicit casts, so no need to change
(type)-1 casts).

diffstat:

 configure.ac                                     |   2 +-
 src/anvil/anvil-settings.c                       |   2 +-
 src/auth/db-ldap.c                               |   4 ++--
 src/config/doveconf.c                            |  20 ++++++++++----------
 src/director/director-settings.c                 |   2 +-
 src/director/doveadm-connection.c                |   6 +++---
 src/doveadm/doveadm-director.c                   |   4 ++--
 src/doveadm/doveadm-mail-fetch.c                 |   4 ++--
 src/doveadm/doveadm-stats.c                      |   4 ++--
 src/lib-auth/auth-master.c                       |   8 ++++----
 src/lib-dict/dict-sql.c                          |   4 ++--
 src/lib-dict/dict.c                              |   4 ++--
 src/lib-http/http-client-peer.c                  |   2 +-
 src/lib-imap/imap-envelope.c                     |   2 +-
 src/lib-index/mail-cache-compress.c              |   2 +-
 src/lib-index/mail-cache-fields.c                |   4 ++--
 src/lib-index/mail-cache-lookup.c                |   2 +-
 src/lib-index/mail-cache-transaction.c           |   6 +++---
 src/lib-index/mail-cache.h                       |   2 +-
 src/lib-index/mail-index-map.c                   |   4 ++--
 src/lib-index/mail-index-sync-keywords.c         |   2 +-
 src/lib-index/mail-index-sync.c                  |   4 ++--
 src/lib-index/mail-index.c                       |   4 ++--
 src/lib-index/mail-index.h                       |   3 ++-
 src/lib-index/mail-transaction-log-file.c        |  12 ++++++------
 src/lib-mail/test-message-address.c              |   6 +++---
 src/lib-master/master-service.c                  |   4 ++--
 src/lib-settings/settings-parser.c               |   4 ++--
 src/lib-sql/driver-sqlpool.c                     |  12 ++++++------
 src/lib-storage/index/dbox-multi/mdbox-map.c     |   2 +-
 src/lib-storage/index/imapc/imapc-storage.c      |   2 +-
 src/lib-storage/index/index-mail-headers.c       |   4 ++--
 src/lib-storage/index/index-mail.c               |   4 ++--
 src/lib-storage/index/index-rebuild.c            |   3 ++-
 src/lib-storage/index/index-search.c             |   4 ++--
 src/lib-storage/index/index-storage.c            |   6 +++---
 src/lib-storage/index/maildir/maildir-uidlist.c  |  18 +++++++++---------
 src/lib-storage/list/mailbox-list-index.c        |   2 +-
 src/lib-storage/list/mailbox-list-iter.c         |   2 +-
 src/lib-storage/mail-storage-hooks.c             |   8 ++++----
 src/lib-storage/mail-storage.c                   |   2 +-
 src/lib/istream-concat.c                         |   6 +++---
 src/lib/priorityq.c                              |   4 ++--
 src/lib/strnum.c                                 |   2 +-
 src/lib/test-aqueue.c                            |   2 +-
 src/lib/test-base64.c                            |   8 ++++----
 src/lib/test-bsearch-insert-pos.c                |  10 +++++-----
 src/lib/test-seq-range-array.c                   |  22 +++++++++++-----------
 src/lmtp/commands.c                              |   4 ++--
 src/log/log-settings.c                           |   2 +-
 src/master/service-monitor.c                     |   2 +-
 src/plugins/fts/fts-build-mail.c                 |   2 +-
 src/plugins/quota/quota.c                        |   2 +-
 src/replication/replicator/replicator-settings.c |   2 +-
 src/stats/stats-settings.c                       |   2 +-
 55 files changed, 134 insertions(+), 132 deletions(-)

diffs (truncated from 1204 to 300 lines):

diff -r f1e8f8a73196 -r d3cf06639864 configure.ac
--- a/configure.ac	Sun Feb 24 08:58:03 2013 +0200
+++ b/configure.ac	Sun Feb 24 09:16:31 2013 +0200
@@ -346,7 +346,7 @@
 if test "$have_clang" = "yes"; then
   # clang specific options
   if test "$want_devel_checks" = "yes"; then
-    CFLAGS="$CFLAGS -fcatch-undefined-behavior -ftrapv"
+    CFLAGS="$CFLAGS -fsanitize=address,integer,undefined -ftrapv"
   fi
 fi
 
diff -r f1e8f8a73196 -r d3cf06639864 src/anvil/anvil-settings.c
--- a/src/anvil/anvil-settings.c	Sun Feb 24 08:58:03 2013 +0200
+++ b/src/anvil/anvil-settings.c	Sun Feb 24 09:16:31 2013 +0200
@@ -38,7 +38,7 @@
 	.process_limit = 1,
 	.client_limit = 0,
 	.service_count = 0,
-	.idle_kill = -1U,
+	.idle_kill = UINT_MAX,
 	.vsz_limit = (uoff_t)-1,
 
 	.unix_listeners = { { &anvil_unix_listeners_buf,
diff -r f1e8f8a73196 -r d3cf06639864 src/auth/db-ldap.c
--- a/src/auth/db-ldap.c	Sun Feb 24 08:58:03 2013 +0200
+++ b/src/auth/db-ldap.c	Sun Feb 24 09:16:31 2013 +0200
@@ -928,7 +928,7 @@
 
 static void db_ldap_disconnect_timeout(struct ldap_connection *conn)
 {
-	db_ldap_abort_requests(conn, -1U,
+	db_ldap_abort_requests(conn, UINT_MAX,
 		DB_LDAP_REQUEST_DISCONNECT_TIMEOUT_SECS, FALSE,
 		"Aborting (timeout), we're not connected to LDAP server");
 
@@ -1469,7 +1469,7 @@
 		}
 	}
 
-	db_ldap_abort_requests(conn, -1U, 0, FALSE, "Shutting down");
+	db_ldap_abort_requests(conn, UINT_MAX, 0, FALSE, "Shutting down");
 	i_assert(conn->pending_count == 0);
 	db_ldap_conn_close(conn);
 	i_assert(conn->to == NULL);
diff -r f1e8f8a73196 -r d3cf06639864 src/config/doveconf.c
--- a/src/config/doveconf.c	Sun Feb 24 08:58:03 2013 +0200
+++ b/src/config/doveconf.c	Sun Feb 24 09:16:31 2013 +0200
@@ -104,7 +104,7 @@
 	s = array_get(stack, &count);
 	i_assert(count > 0);
 	if (count == 1) {
-		sc.prefix_idx = -1U;
+		sc.prefix_idx = UINT_MAX;
 	} else {
 		sc.prefix_idx = s[count-2].prefix_idx;
 	}
@@ -118,7 +118,7 @@
 	struct prefix_stack *s;
 
 	array_foreach_modifiable(stack, s)
-		s->str_pos = -1U;
+		s->str_pos = UINT_MAX;
 }
 
 static struct config_dump_human_context *
@@ -178,7 +178,7 @@
 	const char *const *strings, *const *args, *p, *str, *const *prefixes;
 	const char *key, *key2, *value;
 	unsigned int i, j, count, len, prefix_count, skip_len;
-	unsigned int setting_name_filter_len, prefix_idx = -1U;
+	unsigned int setting_name_filter_len, prefix_idx = UINT_MAX;
 	bool unique_key;
 	int ret = 0;
 
@@ -238,12 +238,12 @@
 		j = 0;
 		/* if there are open sections and this key isn't in it,
 		   close the sections */
-		while (prefix_idx != -1U) {
+		while (prefix_idx != UINT_MAX) {
 			len = strlen(prefixes[prefix_idx]);
 			if (strncmp(prefixes[prefix_idx], key, len) != 0) {
 				prefix = prefix_stack_pop(&prefix_stack);
 				indent--;
-				if (prefix.str_pos != -1U)
+				if (prefix.str_pos != UINT_MAX)
 					str_truncate(ctx->list_prefix, prefix.str_pos);
 				else {
 					o_stream_nsend(output, indent_str, indent*2);
@@ -260,9 +260,9 @@
 		for (; j < prefix_count; j++) {
 			len = strlen(prefixes[j]);
 			if (strncmp(prefixes[j], key, len) == 0) {
-				key2 = key + (prefix_idx == -1U ? 0 :
+				key2 = key + (prefix_idx == UINT_MAX ? 0 :
 					      strlen(prefixes[prefix_idx]));
-				prefix.str_pos = !unique_key ? -1U :
+				prefix.str_pos = !unique_key ? UINT_MAX :
 					str_len(ctx->list_prefix);
 				prefix_idx = j;
 				prefix.prefix_idx = prefix_idx;
@@ -294,7 +294,7 @@
 		prefix_stack_reset_str(&prefix_stack);
 		ctx->list_prefix_sent = TRUE;
 
-		skip_len = prefix_idx == -1U ? 0 : strlen(prefixes[prefix_idx]);
+		skip_len = prefix_idx == UINT_MAX ? 0 : strlen(prefixes[prefix_idx]);
 		i_assert(skip_len == 0 ||
 			 strncmp(prefixes[prefix_idx], strings[i], skip_len) == 0);
 		o_stream_nsend(output, indent_str, indent*2);
@@ -314,9 +314,9 @@
 	end: ;
 	} T_END;
 
-	while (prefix_idx != -1U) {
+	while (prefix_idx != UINT_MAX) {
 		prefix = prefix_stack_pop(&prefix_stack);
-		if (prefix.str_pos != -1U)
+		if (prefix.str_pos != UINT_MAX)
 			break;
 		prefix_idx = prefix.prefix_idx;
 		indent--;
diff -r f1e8f8a73196 -r d3cf06639864 src/director/director-settings.c
--- a/src/director/director-settings.c	Sun Feb 24 08:58:03 2013 +0200
+++ b/src/director/director-settings.c	Sun Feb 24 09:16:31 2013 +0200
@@ -48,7 +48,7 @@
 	.process_limit = 1,
 	.client_limit = 0,
 	.service_count = 0,
-	.idle_kill = -1U,
+	.idle_kill = UINT_MAX,
 	.vsz_limit = (uoff_t)-1,
 
 	.unix_listeners = { { &director_unix_listeners_buf,
diff -r f1e8f8a73196 -r d3cf06639864 src/director/doveadm-connection.c
--- a/src/director/doveadm-connection.c	Sun Feb 24 08:58:03 2013 +0200
+++ b/src/director/doveadm-connection.c	Sun Feb 24 09:16:31 2013 +0200
@@ -189,7 +189,7 @@
 	const char *const *args;
 	struct mail_host *host;
 	struct ip_addr ip;
-	unsigned int vhost_count = -1U;
+	unsigned int vhost_count = UINT_MAX;
 
 	args = t_strsplit_tab(line);
 	if (args[0] == NULL ||
@@ -198,14 +198,14 @@
 		i_error("doveadm sent invalid HOST-SET parameters: %s", line);
 		return FALSE;
 	}
-	if (vhost_count > MAX_VALID_VHOST_COUNT && vhost_count != -1U) {
+	if (vhost_count > MAX_VALID_VHOST_COUNT && vhost_count != UINT_MAX) {
 		o_stream_nsend_str(conn->output, "vhost count too large\n");
 		return TRUE;
 	}
 	host = mail_host_lookup(dir->mail_hosts, &ip);
 	if (host == NULL)
 		host = mail_host_add_ip(dir->mail_hosts, &ip);
-	if (vhost_count != -1U)
+	if (vhost_count != UINT_MAX)
 		mail_host_set_vhost_count(dir->mail_hosts, host, vhost_count);
 	director_update_host(dir, dir->self_host, NULL, host);
 
diff -r f1e8f8a73196 -r d3cf06639864 src/doveadm/doveadm-director.c
--- a/src/doveadm/doveadm-director.c	Sun Feb 24 08:58:03 2013 +0200
+++ b/src/doveadm/doveadm-director.c	Sun Feb 24 09:16:31 2013 +0200
@@ -357,7 +357,7 @@
 {
 	struct director_context *ctx;
 	struct ip_addr *ips;
-	unsigned int i, ips_count, vhost_count = -1U;
+	unsigned int i, ips_count, vhost_count = UINT_MAX;
 	const char *host, *cmd, *line;
 
 	ctx = cmd_director_init(argc, argv, "a:", cmd_director_add);
@@ -373,7 +373,7 @@
 
 	director_get_host(host, &ips, &ips_count);
 	for (i = 0; i < ips_count; i++) {
-		cmd = vhost_count == -1U ?
+		cmd = vhost_count == UINT_MAX ?
 			t_strdup_printf("HOST-SET\t%s\n",
 					net_ip2addr(&ips[i])) :
 			t_strdup_printf("HOST-SET\t%s\t%u\n",
diff -r f1e8f8a73196 -r d3cf06639864 src/doveadm/doveadm-mail-fetch.c
--- a/src/doveadm/doveadm-mail-fetch.c	Sun Feb 24 08:58:03 2013 +0200
+++ b/src/doveadm/doveadm-mail-fetch.c	Sun Feb 24 09:16:31 2013 +0200
@@ -170,8 +170,8 @@
 		struct message_address *addr;
 
 		addr = message_address_parse(pool_datastack_create(),
-					     str_data(str), str_len(str), -1U,
-					     FALSE);
+					     str_data(str), str_len(str),
+					     UINT_MAX, FALSE);
 		str_truncate(str, 0);
 		add_lf = FALSE;
 		for (; addr != NULL; addr = addr->next) {
diff -r f1e8f8a73196 -r d3cf06639864 src/doveadm/doveadm-stats.c
--- a/src/doveadm/doveadm-stats.c	Sun Feb 24 08:58:03 2013 +0200
+++ b/src/doveadm/doveadm-stats.c	Sun Feb 24 09:16:31 2013 +0200
@@ -438,7 +438,7 @@
 
 	for (i = 0; i < N_ELEMENTS(names); i++) {
 		if (!stats_header_find(ctx, names[i], &indexes[i]))
-			indexes[i] = -1U;
+			indexes[i] = UINT_MAX;
 	}
 
 	if (ioctl(STDOUT_FILENO, TIOCGWINSZ, &ws) < 0)
@@ -448,7 +448,7 @@
 	lines = array_get(&ctx->lines, &count);
 	for (i = 0, row = 1; row < maxrow && i < count; i++, row++) {
 		for (j = 0; j < N_ELEMENTS(names); j++) {
-			if (indexes[j] == -1U)
+			if (indexes[j] == UINT_MAX)
 				doveadm_print("?");
 			else
 				stats_top_output_diff(ctx, lines[i], indexes[j]);
diff -r f1e8f8a73196 -r d3cf06639864 src/lib-auth/auth-master.c
--- a/src/lib-auth/auth-master.c	Sun Feb 24 08:58:03 2013 +0200
+++ b/src/lib-auth/auth-master.c	Sun Feb 24 09:16:31 2013 +0200
@@ -577,9 +577,9 @@
 	unsigned int *countp = context;
 
 	if (strcmp(cmd, "OK") != 0)
-		*countp = -1U;
+		*countp = UINT_MAX;
 	else if (args[0] == NULL || str_to_uint(args[0], countp) < 0)
-		*countp = -1U;
+		*countp = UINT_MAX;
 
 	io_loop_stop(current_ioloop);
 	return TRUE;
@@ -590,7 +590,7 @@
 {
 	string_t *str;
 
-	*count_r = -1U;
+	*count_r = UINT_MAX;
 
 	conn->reply_callback = auth_cache_flush_reply_callback;
 	conn->reply_context = count_r;
@@ -609,7 +609,7 @@
 	(void)auth_master_run_cmd(conn, str_c(str));
 	conn->prefix = DEFAULT_USERDB_LOOKUP_PREFIX;
 
-	return *count_r == -1U ? -1 : 0;
+	return *count_r == UINT_MAX ? -1 : 0;
 }
 
 static bool
diff -r f1e8f8a73196 -r d3cf06639864 src/lib-dict/dict-sql.c
--- a/src/lib-dict/dict-sql.c	Sun Feb 24 08:58:03 2013 +0200
+++ b/src/lib-dict/dict-sql.c	Sun Feb 24 09:16:31 2013 +0200
@@ -525,7 +525,7 @@
 			ret = -1;
 		} else {
 			while (ctx->inc_row != NULL) {
-				i_assert(ctx->inc_row->rows != -1U);
+				i_assert(ctx->inc_row->rows != UINT_MAX);
 				if (ctx->inc_row->rows == 0) {
 					ret = 0;
 					break;
@@ -759,7 +759,7 @@
 	}
 	row = p_new(ctx->inc_row_pool, struct sql_dict_inc_row, 1);
 	row->prev = ctx->inc_row;
-	row->rows = -1U;
+	row->rows = UINT_MAX;
 	ctx->inc_row = row;
 	return &row->rows;
 }
diff -r f1e8f8a73196 -r d3cf06639864 src/lib-dict/dict.c
--- a/src/lib-dict/dict.c	Sun Feb 24 08:58:03 2013 +0200
+++ b/src/lib-dict/dict.c	Sun Feb 24 09:16:31 2013 +0200
@@ -37,7 +37,7 @@
 void dict_driver_unregister(struct dict *driver)
 {
 	struct dict *const *dicts;
-	unsigned int idx = -1U;
+	unsigned int idx = UINT_MAX;
 
 	array_foreach(&dict_drivers, dicts) {
 		if (*dicts == driver) {
@@ -45,7 +45,7 @@
 			break;
 		}
 	}
-	i_assert(idx != -1U);
+	i_assert(idx != UINT_MAX);
 	array_delete(&dict_drivers, idx, 1);
 
 	if (array_count(&dict_drivers) == 0)
diff -r f1e8f8a73196 -r d3cf06639864 src/lib-http/http-client-peer.c
--- a/src/lib-http/http-client-peer.c	Sun Feb 24 08:58:03 2013 +0200
+++ b/src/lib-http/http-client-peer.c	Sun Feb 24 09:16:31 2013 +0200
@@ -122,7 +122,7 @@
 {


More information about the dovecot-cvs mailing list