changeset 14682:d0d7b810646b

Make sure we check all the functions' return values. Minor API changes to simplify this. Checked using a patched clang that adds attribute(warn_unused_result) to all functions. This commit fixes several error handling mistakes.
author Timo Sirainen <tss@iki.fi>
date Mon, 25 Jun 2012 01:14:03 +0300
parents ca37d1577291
children 9646f80ac3e9
files src/anvil/main.c src/auth/auth-request.c src/auth/mech-digest-md5.c src/auth/mech-scram-sha1.c src/auth/passdb-blocking.c src/auth/password-scheme-otp.c src/auth/userdb-blocking.c src/auth/userdb-sql.c src/config/doveconf.c src/config/main.c src/config/old-set-parser.c src/dict/dict-commands.c src/dict/main.c src/director/director-connection.c src/director/director-host.c src/director/director.c src/director/doveadm-connection.c src/director/mail-host.c src/director/main.c src/director/test-user-directory.c src/doveadm/doveadm-dump-dbox.c src/doveadm/doveadm-mail-server.c src/doveadm/doveadm-mailbox-list-iter.c src/doveadm/doveadm-mount.c src/doveadm/doveadm-penalty.c src/doveadm/doveadm-stats.c src/doveadm/dsync/doveadm-dsync.c src/doveadm/dsync/dsync-brain-mailbox-tree.c src/doveadm/dsync/dsync-brain-mailbox.c src/doveadm/dsync/dsync-brain-mails.c src/doveadm/dsync/dsync-mailbox-import.c src/doveadm/dsync/dsync-mailbox-tree.c src/doveadm/dsync/dsync-slave.c src/doveadm/dsync/dsync-slave.h src/doveadm/server-connection.c src/doveadm/server-connection.h src/imap-login/client.c src/imap/cmd-fetch.c src/imap/cmd-idle.c src/imap/cmd-list.c src/imap/imap-client.c src/imap/imap-client.h src/imap/imap-fetch-body.c src/imap/imap-sync.c src/imap/main.c src/indexer/master-connection.c src/lib-auth/auth-client.c src/lib-imap/imap-parser.c src/lib-imap/imap-quote.c src/lib-index/mail-cache-compress.c src/lib-index/mail-cache-transaction.c src/lib-index/mail-cache.c src/lib-index/mail-index-fsck.c src/lib-index/mail-index-map-hdr.c src/lib-index/mail-index-modseq.c src/lib-index/mail-index-private.h src/lib-index/mail-index-strmap.c src/lib-index/mail-index-sync-update.c src/lib-index/mail-index-transaction-private.h src/lib-index/mail-index-transaction-sort-appends.c src/lib-index/mail-index-transaction-update.c src/lib-index/mail-index-view-sync.c src/lib-index/mail-index-write.c src/lib-index/mail-index.c src/lib-index/mail-transaction-log-file.c src/lib-index/test-mail-index-transaction-update.c src/lib-index/test-mail-transaction-log-append.c src/lib-mail/message-header-decode.c src/lib-mail/message-part-serialize.c src/lib-mail/rfc822-parser.c src/lib-mail/test-istream-dot.c src/lib-ntlm/ntlm-des.c src/lib-ntlm/ntlm-des.h src/lib-ntlm/ntlm-encrypt.c src/lib-ntlm/ntlm-encrypt.h src/lib-otp/otp-hash.c src/lib-otp/otp-hash.h src/lib-storage/index/dbox-common/dbox-file-fix.c src/lib-storage/index/dbox-common/dbox-file.c src/lib-storage/index/dbox-common/dbox-sync-rebuild.c src/lib-storage/index/dbox-multi/mdbox-purge.c src/lib-storage/index/dbox-single/sdbox-copy.c src/lib-storage/index/imapc/imapc-mail.c src/lib-storage/index/imapc/imapc-storage.c src/lib-storage/index/index-mail.c src/lib-storage/index/index-search.c src/lib-storage/index/index-sort-string.c src/lib-storage/index/index-sort.c src/lib-storage/index/index-status.c src/lib-storage/index/index-storage.h src/lib-storage/index/index-sync-changes.c src/lib-storage/index/index-sync.c src/lib-storage/index/index-thread.c src/lib-storage/index/maildir/maildir-uidlist.c src/lib-storage/index/mbox/istream-raw-mbox.c src/lib-storage/index/mbox/mbox-mail.c src/lib-storage/index/mbox/mbox-save.c src/lib-storage/index/mbox/mbox-storage.c src/lib-storage/index/mbox/mbox-storage.h src/lib-storage/index/mbox/mbox-sync.c src/lib-storage/index/pop3c/pop3c-client.c src/lib-storage/index/raw/raw-mail.c src/lib-storage/mail-search-build.c src/lib-storage/mail-storage-private.h src/lib-storage/mail.c src/lib-storage/mailbox-get.c src/lib-storage/mailbox-uidvalidity.c src/lib/data-stack.c src/lib/hash.c src/lib/hostpid.c src/lib/iostream-rawlog.c src/lib/md4.c src/lib/md5.c src/lib/mountpoint.c src/lib/nfs-workarounds.c src/lib/nfs-workarounds.h src/lib/seq-range-array.c src/lib/seq-range-array.h src/lib/test-base64.c src/lib/test-network.c src/lib/test-ostream-file.c src/lib/test-seq-range-array.c src/log/log-connection.c src/log/log-connection.h src/login-common/client-common-auth.c src/login-common/login-proxy-state.c src/login-common/login-proxy.c src/login-common/ssl-proxy-openssl.c src/master/main.c src/master/service-anvil.c src/master/service-process.c src/master/service-process.h src/plugins/autocreate/autocreate-plugin.c src/plugins/expire/doveadm-expire.c src/plugins/expire/expire-plugin.c src/plugins/fts-lucene/fts-backend-lucene.c src/plugins/fts-squat/squat-trie.c src/plugins/fts-squat/squat-uidlist.c src/plugins/fts/fts-storage.c src/plugins/imap-acl/imap-acl-plugin.c src/plugins/imap-quota/imap-quota-plugin.c src/plugins/imap-zlib/imap-zlib-plugin.c src/plugins/quota/quota-maildir.c src/plugins/quota/quota.c src/plugins/stats/stats-connection.c src/plugins/virtual/virtual-mail.c src/plugins/virtual/virtual-sync.c src/plugins/zlib/doveadm-zlib.c src/plugins/zlib/ostream-zlib.c src/pop3/main.c src/pop3/pop3-client.c src/pop3/pop3-client.h src/pop3/pop3-commands.c src/replication/aggregator/notify-connection.c src/replication/replicator/notify-connection.c src/stats/main.c src/util/rawlog.c
diffstat 157 files changed, 623 insertions(+), 492 deletions(-) [+]
line wrap: on
line diff
--- a/src/anvil/main.c	Mon Jun 25 00:01:59 2012 +0300
+++ b/src/anvil/main.c	Mon Jun 25 01:14:03 2012 +0300
@@ -26,7 +26,7 @@
 	bool master = conn->listen_fd == MASTER_LISTEN_FD_FIRST;
 
 	master_service_client_connection_accept(conn);
-	anvil_connection_create(conn->fd, master, conn->fifo);
+	(void)anvil_connection_create(conn->fd, master, conn->fifo);
 }
 
 static void ATTR_NULL(1)
--- a/src/auth/auth-request.c	Mon Jun 25 00:01:59 2012 +0300
+++ b/src/auth/auth-request.c	Mon Jun 25 01:14:03 2012 +0300
@@ -237,9 +237,9 @@
 	if (strcmp(key, "service") == 0)
 		request->service = p_strdup(request->pool, value);
 	else if (strcmp(key, "lip") == 0)
-		net_addr2ip(value, &request->local_ip);
+		(void)net_addr2ip(value, &request->local_ip);
 	else if (strcmp(key, "rip") == 0)
-		net_addr2ip(value, &request->remote_ip);
+		(void)net_addr2ip(value, &request->remote_ip);
 	else if (strcmp(key, "lport") == 0)
 		request->local_port = atoi(value);
 	else if (strcmp(key, "rport") == 0)
--- a/src/auth/mech-digest-md5.c	Mon Jun 25 00:01:59 2012 +0300
+++ b/src/auth/mech-digest-md5.c	Mon Jun 25 01:14:03 2012 +0300
@@ -283,7 +283,7 @@
 {
 	unsigned int i;
 
-	str_lcase(key);
+	(void)str_lcase(key);
 
 	if (strcmp(key, "realm") == 0) {
 		if (request->auth_request.realm == NULL && *value != '\0')
--- a/src/auth/mech-scram-sha1.c	Mon Jun 25 00:01:59 2012 +0300
+++ b/src/auth/mech-scram-sha1.c	Mon Jun 25 01:14:03 2012 +0300
@@ -328,7 +328,7 @@
 		return FALSE;
 	}
 
-	str_array_remove(fields, fields[field_count-1]);
+	(void)str_array_remove(fields, fields[field_count-1]);
 	request->client_final_message_without_proof =
 		p_strdup(request->pool, t_strarray_join(fields, ","));
 
--- a/src/auth/passdb-blocking.c	Mon Jun 25 00:01:59 2012 +0300
+++ b/src/auth/passdb-blocking.c	Mon Jun 25 01:14:03 2012 +0300
@@ -88,7 +88,8 @@
 	auth_request_export(request, reply);
 
 	auth_request_ref(request);
-	auth_worker_call(request->pool, reply, verify_plain_callback, request);
+	(void)auth_worker_call(request->pool, reply,
+			       verify_plain_callback, request);
 }
 
 static bool lookup_credentials_callback(const char *reply, void *context)
@@ -130,8 +131,8 @@
 	auth_request_export(request, reply);
 
 	auth_request_ref(request);
-	auth_worker_call(request->pool, reply,
-			 lookup_credentials_callback, request);
+	(void)auth_worker_call(request->pool, reply,
+			       lookup_credentials_callback, request);
 }
 
 static bool
@@ -158,6 +159,6 @@
 	auth_request_export(request, reply);
 
 	auth_request_ref(request);
-	auth_worker_call(request->pool, reply,
-			 set_credentials_callback, request);
+	(void)auth_worker_call(request->pool, reply,
+			       set_credentials_callback, request);
 }
--- a/src/auth/password-scheme-otp.c	Mon Jun 25 00:01:59 2012 +0300
+++ b/src/auth/password-scheme-otp.c	Mon Jun 25 01:14:03 2012 +0300
@@ -23,10 +23,12 @@
 	} else {
 		/* Generate new OTP credentials from plaintext */
 		unsigned char random_data[OTP_MAX_SEED_LEN / 2];
+		const char *random_hex;
 
 		random_fill(random_data, sizeof(random_data));
-		i_strocpy(state.seed, binary_to_hex(random_data,
-			OTP_MAX_SEED_LEN / 2), sizeof(state.seed));
+		random_hex = binary_to_hex(random_data, sizeof(random_data));
+		if (i_strocpy(state.seed, random_hex, sizeof(state.seed)) < 0)
+			i_unreached();
 
 		state.seq = 1024;
 		state.algo = algo;
--- a/src/auth/userdb-blocking.c	Mon Jun 25 00:01:59 2012 +0300
+++ b/src/auth/userdb-blocking.c	Mon Jun 25 01:14:03 2012 +0300
@@ -58,7 +58,7 @@
 	auth_request_export(request, reply);
 
 	auth_request_ref(request);
-	auth_worker_call(request->pool, reply, user_callback, request);
+	(void)auth_worker_call(request->pool, reply, user_callback, request);
 }
 
 static bool iter_callback(const char *reply, void *context)
--- a/src/auth/userdb-sql.c	Mon Jun 25 00:01:59 2012 +0300
+++ b/src/auth/userdb-sql.c	Mon Jun 25 01:14:03 2012 +0300
@@ -136,7 +136,7 @@
 	sql_result_ref(sql_result);
 
 	if (ctx->freed)
-		userdb_sql_iterate_deinit(&ctx->ctx);
+		(void)userdb_sql_iterate_deinit(&ctx->ctx);
 	else if (ctx->call_iter)
 		userdb_sql_iterate_next(&ctx->ctx);
 }
--- a/src/config/doveconf.c	Mon Jun 25 00:01:59 2012 +0300
+++ b/src/config/doveconf.c	Mon Jun 25 01:14:03 2012 +0300
@@ -478,7 +478,7 @@
 	config_dump_human_deinit(ctx);
 
 	if (dump_section)
-		config_dump_human(filter, "", scope, setting_name_filter);
+		(void)config_dump_human(filter, "", scope, setting_name_filter);
 	return 0;
 }
 
--- a/src/config/main.c	Mon Jun 25 00:01:59 2012 +0300
+++ b/src/config/main.c	Mon Jun 25 01:14:03 2012 +0300
@@ -11,7 +11,7 @@
 static void client_connected(struct master_service_connection *conn)
 {
 	master_service_client_connection_accept(conn);
-	config_connection_create(conn->fd);
+	(void)config_connection_create(conn->fd);
 }
 
 int main(int argc, char *argv[])
--- a/src/config/old-set-parser.c	Mon Jun 25 00:01:59 2012 +0300
+++ b/src/config/old-set-parser.c	Mon Jun 25 01:14:03 2012 +0300
@@ -6,6 +6,8 @@
 #include "config-parser-private.h"
 #include "old-set-parser.h"
 
+#define config_apply_line (void)config_apply_line
+
 struct socket_set {
 	const char *path, *mode, *user, *group;
 	bool master;
--- a/src/dict/dict-commands.c	Mon Jun 25 00:01:59 2012 +0300
+++ b/src/dict/dict-commands.c	Mon Jun 25 01:14:03 2012 +0300
@@ -101,7 +101,7 @@
 	conn->iter_ctx = dict_iterate_init_multiple(conn->dict, args+1, flags);
 
 	o_stream_set_flush_callback(conn->output, cmd_iterate_flush, conn);
-	cmd_iterate_flush(conn);
+	(void)cmd_iterate_flush(conn);
 	return 0;
 }
 
--- a/src/dict/main.c	Mon Jun 25 00:01:59 2012 +0300
+++ b/src/dict/main.c	Mon Jun 25 01:14:03 2012 +0300
@@ -23,7 +23,7 @@
 static void client_connected(struct master_service_connection *conn)
 {
 	master_service_client_connection_accept(conn);
-	dict_connection_create(conn->fd);
+	(void)dict_connection_create(conn->fd);
 }
 
 static void main_preinit(void)
--- a/src/director/director-connection.c	Mon Jun 25 00:01:59 2012 +0300
+++ b/src/director/director-connection.c	Mon Jun 25 01:14:03 2012 +0300
@@ -538,7 +538,8 @@
 		return FALSE;
 	}
 
-	director_user_refresh(conn, username_hash, host, timestamp, weak, &user);
+	(void)director_user_refresh(conn, username_hash, host,
+				    timestamp, weak, &user);
 	return TRUE;
 }
 
@@ -1081,7 +1082,7 @@
 	}
 
 	if (host == NULL || !host->self)
-		director_resend_sync(dir);
+		(void)director_resend_sync(dir);
 	return TRUE;
 }
 
--- a/src/director/director-host.c	Mon Jun 25 00:01:59 2012 +0300
+++ b/src/director/director-host.c	Mon Jun 25 01:14:03 2012 +0300
@@ -158,7 +158,7 @@
 		i_fatal("Unknown director host: %s", host);
 
 	for (i = 0; i < ips_count; i++)
-		director_host_add(dir, &ips[i], port);
+		(void)director_host_add(dir, &ips[i], port);
 }
 
 void director_host_add_from_string(struct director *dir, const char *hosts)
@@ -175,7 +175,8 @@
 		/* standalone director */
 		struct ip_addr ip;
 
-		net_addr2ip("127.0.0.1", &ip);
+		if (net_addr2ip("127.0.0.1", &ip) < 0)
+			i_unreached();
 		dir->self_host = director_host_add(dir, &ip, 0);
 		dir->self_host->self = TRUE;
 	}
--- a/src/director/director.c	Mon Jun 25 00:01:59 2012 +0300
+++ b/src/director/director.c	Mon Jun 25 01:14:03 2012 +0300
@@ -121,7 +121,7 @@
 	   while we're still trying to connect to it */
 	host->last_network_failure = 0;
 
-	director_connection_init_out(dir, fd, host);
+	(void)director_connection_init_out(dir, fd, host);
 	return 0;
 }
 
--- a/src/director/doveadm-connection.c	Mon Jun 25 00:01:59 2012 +0300
+++ b/src/director/doveadm-connection.c	Mon Jun 25 01:14:03 2012 +0300
@@ -419,9 +419,9 @@
 		else if (strcmp(cmd, "DIRECTOR-LIST") == 0)
 			doveadm_cmd_director_list(conn);
 		else if (strcmp(cmd, "DIRECTOR-ADD") == 0)
-			doveadm_cmd_director_add(conn, args);
+			ret = doveadm_cmd_director_add(conn, args);
 		else if (strcmp(cmd, "DIRECTOR-REMOVE") == 0)
-			doveadm_cmd_director_remove(conn, args);
+			ret = doveadm_cmd_director_remove(conn, args);
 		else if (strcmp(cmd, "HOST-SET") == 0)
 			ret = doveadm_cmd_host_set(conn, args);
 		else if (strcmp(cmd, "HOST-REMOVE") == 0)
--- a/src/director/mail-host.c	Mon Jun 25 00:01:59 2012 +0300
+++ b/src/director/mail-host.c	Mon Jun 25 01:14:03 2012 +0300
@@ -59,7 +59,7 @@
 	}
 
 	for (i = 0; i < ips_count; i++)
-		mail_host_add_ip(list, &ips[i]);
+		(void)mail_host_add_ip(list, &ips[i]);
 	return 0;
 }
 
@@ -120,7 +120,7 @@
 	/* create hosts from the final bits */
 	do {
 		ip1_arr[i] = ntohl(i1);
-		mail_host_add_ip(list, &ip1);
+		(void)mail_host_add_ip(list, &ip1);
 		i1++;
 	} while (ip1_arr[i] != ip2_arr[i]);
 	return 0;
--- a/src/director/main.c	Mon Jun 25 00:01:59 2012 +0300
+++ b/src/director/main.c	Mon Jun 25 01:14:03 2012 +0300
@@ -37,7 +37,7 @@
 		return -1;
 	}
 
-	director_connection_init_in(director, fd, ip);
+	(void)director_connection_init_in(director, fd, ip);
 	return 0;
 }
 
@@ -90,7 +90,7 @@
 	auth = auth_connection_init(socket_path);
 	if (auth_connection_connect(auth) == 0) {
 		master_service_client_connection_accept(conn);
-		login_connection_init(director, conn->fd, auth, userdb);
+		(void)login_connection_init(director, conn->fd, auth, userdb);
 	} else {
 		auth_connection_deinit(&auth);
 	}
--- a/src/director/test-user-directory.c	Mon Jun 25 00:01:59 2012 +0300
+++ b/src/director/test-user-directory.c	Mon Jun 25 01:14:03 2012 +0300
@@ -44,10 +44,10 @@
 
 	test_begin("user directory ascending");
 	dir = user_directory_init(USER_DIR_TIMEOUT, "%u");
-	user_directory_add(dir, 1, host, ioloop_time + count+1);
+	(void)user_directory_add(dir, 1, host, ioloop_time + count+1);
 
 	for (i = 0; i < count; i++)
-		user_directory_add(dir, i+2, host, ioloop_time + i);
+		(void)user_directory_add(dir, i+2, host, ioloop_time + i);
 	verify_user_directory(dir, count+1);
 	user_directory_deinit(&dir);
 	test_end();
@@ -64,7 +64,7 @@
 	dir = user_directory_init(USER_DIR_TIMEOUT, "%u");
 
 	for (i = 0; i < count; i++)
-		user_directory_add(dir, i+1, host, ioloop_time - i);
+		(void)user_directory_add(dir, i+1, host, ioloop_time - i);
 	verify_user_directory(dir, count);
 	user_directory_deinit(&dir);
 	test_end();
@@ -84,7 +84,7 @@
 			timestamp = ioloop_time;
 		else
 			timestamp = ioloop_time-rand()%100;
-		user_directory_add(dir, i+1, host, timestamp);
+		(void)user_directory_add(dir, i+1, host, timestamp);
 	}
 	verify_user_directory(dir, count);
 	user_directory_deinit(&dir);
--- a/src/doveadm/doveadm-dump-dbox.c	Mon Jun 25 00:01:59 2012 +0300
+++ b/src/doveadm/doveadm-dump-dbox.c	Mon Jun 25 01:14:03 2012 +0300
@@ -152,10 +152,10 @@
 			dump_timestamp(input, "msg.received", line + 1);
 			break;
 		case DBOX_METADATA_PHYSICAL_SIZE:
-			dump_size(input, "msg.physical-size", line + 1);
+			(void)dump_size(input, "msg.physical-size", line + 1);
 			break;
 		case DBOX_METADATA_VIRTUAL_SIZE:
-			dump_size(input, "msg.virtual-size", line + 1);
+			(void)dump_size(input, "msg.virtual-size", line + 1);
 			break;
 		case DBOX_METADATA_EXT_REF:
 			printf("msg.ext-ref = %s\n", line + 1);
--- a/src/doveadm/doveadm-mail-server.c	Mon Jun 25 00:01:59 2012 +0300
+++ b/src/doveadm/doveadm-mail-server.c	Mon Jun 25 01:14:03 2012 +0300
@@ -241,8 +241,10 @@
 		doveadm_mail_server_handle(conn, input->username);
 	else if (array_count(&server->connections) <
 		 	I_MAX(ctx->set->doveadm_worker_count, 1)) {
-		conn = server_connection_create(server);
-		doveadm_mail_server_handle(conn, input->username);
+		if (server_connection_create(server, &conn) < 0)
+			internal_failure = TRUE;
+		else
+			doveadm_mail_server_handle(conn, input->username);
 	} else {
 		if (array_count(&server->queue) >= DOVEADM_SERVER_QUEUE_MAX)
 			doveadm_server_flush_one(server);
--- a/src/doveadm/doveadm-mailbox-list-iter.c	Mon Jun 25 00:01:59 2012 +0300
+++ b/src/doveadm/doveadm-mailbox-list-iter.c	Mon Jun 25 01:14:03 2012 +0300
@@ -24,7 +24,7 @@
 	bool only_selectable;
 };
 
-static int
+static bool
 search_args_get_mailbox_patterns(const struct mail_search_arg *args,
 				 ARRAY_TYPE(const_string) *patterns,
 				 bool *have_guid, bool *have_wildcards)
@@ -43,7 +43,7 @@
 				if (!search_args_get_mailbox_patterns(subargs,
 							patterns, have_guid,
 							have_wildcards))
-					return 0;
+					return FALSE;
 			}
 			break;
 		case SEARCH_MAILBOX_GLOB:
@@ -52,7 +52,7 @@
 		case SEARCH_MAILBOX:
 			if (args->match_not) {
 				array_clear(patterns);
-				return 0;
+				return FALSE;
 			}
 			array_append(patterns, &args->value.str, 1);
 			break;
@@ -63,7 +63,7 @@
 			break;
 		}
 	}
-	return 1;
+	return TRUE;
 }
 
 static struct doveadm_mailbox_list_iter *
@@ -82,8 +82,9 @@
 	iter->search_args = search_args;
 	iter->user = user;
 	i_array_init(&iter->patterns, 16);
-	search_args_get_mailbox_patterns(search_args->args, &iter->patterns,
-					 &have_guid, &have_wildcards);
+	(void)search_args_get_mailbox_patterns(search_args->args,
+					       &iter->patterns,
+					       &have_guid, &have_wildcards);
 
 	if (array_count(&iter->patterns) == 0) {
 		iter_flags |= MAILBOX_LIST_ITER_SKIP_ALIASES;
--- a/src/doveadm/doveadm-mount.c	Mon Jun 25 00:01:59 2012 +0300
+++ b/src/doveadm/doveadm-mount.c	Mon Jun 25 01:14:03 2012 +0300
@@ -71,13 +71,14 @@
 {
 	struct mountpoint_list *mountpoints;
 	struct mountpoint_list_rec rec;
+	int ret = 0;
 
 	if (argc > 3)
 		mount_cmd_help(cmd_mount_add);
 
 	mountpoints = mountpoint_list_get();
 	if (argv[1] == NULL) {
-		mountpoint_list_add_missing(mountpoints,
+		ret = mountpoint_list_add_missing(mountpoints,
 			MOUNTPOINT_STATE_DEFAULT,
 			mountpoint_list_default_ignore_prefixes,
 			mountpoint_list_default_ignore_types);
@@ -91,8 +92,11 @@
 			rec.wildcard = TRUE;
 		mountpoint_list_add(mountpoints, &rec);
 	}
-	(void)mountpoint_list_save(mountpoints);
+	if (mountpoint_list_save(mountpoints) < 0)
+		ret = -1;
 	mountpoint_list_deinit(&mountpoints);
+	if (ret < 0)
+		doveadm_exit_code = EX_TEMPFAIL;
 }
 
 static void cmd_mount_remove(int argc, char *argv[])
--- a/src/doveadm/doveadm-penalty.c	Mon Jun 25 00:01:59 2012 +0300
+++ b/src/doveadm/doveadm-penalty.c	Mon Jun 25 01:14:03 2012 +0300
@@ -35,7 +35,7 @@
 
 	memset(line_r, 0, sizeof(*line_r));
 
-	net_addr2ip(ident, &line_r->ip);
+	(void)net_addr2ip(ident, &line_r->ip);
 	line_r->penalty = strtoul(penalty_str, NULL, 10);
 	line_r->last_penalty = strtoul(last_penalty_str, NULL, 10);
 	line_r->last_update = strtoul(last_update_str, NULL, 10);
--- a/src/doveadm/doveadm-stats.c	Mon Jun 25 00:01:59 2012 +0300
+++ b/src/doveadm/doveadm-stats.c	Mon Jun 25 01:14:03 2012 +0300
@@ -388,17 +388,19 @@
 
 	if (str_to_uint64(line->prev_values[i], &prev_num) == 0 &&
 	    str_to_uint64(line->cur_values[i], &cur_num) == 0) {
-		i_snprintf(numstr, sizeof(numstr), "%llu",
-			   (unsigned long long)(cur_num - prev_num));
+		if (i_snprintf(numstr, sizeof(numstr), "%llu",
+			       (unsigned long long)(cur_num - prev_num)) < 0)
+			i_unreached();
 		doveadm_print(numstr);
 	} else if (get_double(line->prev_values[i], &prev_double) == 0 &&
 		   get_double(line->cur_values[i], &cur_double) == 0 &&
 		   get_double(line->prev_values[ctx->last_update_idx], &prev_time) == 0 &&
 		   get_double(line->cur_values[ctx->last_update_idx], &cur_time) == 0) {
 		/* %CPU */
-		i_snprintf(numstr, sizeof(numstr), "%d",
-			   (int)((cur_double - prev_double) *
-				 (cur_time - prev_time) * 100));
+		if (i_snprintf(numstr, sizeof(numstr), "%d",
+			       (int)((cur_double - prev_double) *
+				     (cur_time - prev_time) * 100)) < 0)
+			i_unreached();
 		doveadm_print(numstr);
 	} else {
 		doveadm_print(line->cur_values[i]);
--- a/src/doveadm/dsync/doveadm-dsync.c	Mon Jun 25 00:01:59 2012 +0300
+++ b/src/doveadm/dsync/doveadm-dsync.c	Mon Jun 25 01:14:03 2012 +0300
@@ -226,7 +226,7 @@
 	return TRUE;
 }
 
-static struct dsync_slave *
+static int
 cmd_dsync_run_local(struct dsync_cmd_context *ctx, struct mail_user *user,
 		    struct dsync_brain *brain, struct dsync_slave *slave2)
 {
@@ -281,8 +281,7 @@
 		brain2_running = dsync_brain_run(brain2, &changed2);
 	}
 	mail_user_unref(&user2);
-	dsync_brain_deinit(&brain2);
-	return slave2;
+	return dsync_brain_deinit(&brain2);
 }
 
 static void
@@ -349,10 +348,12 @@
 					DSYNC_BRAIN_FLAG_SEND_REQUESTS,
 					"");
 
-	if (!ctx->remote)
-		cmd_dsync_run_local(ctx, user, brain, slave2);
-	else
+	if (!ctx->remote) {
+		if (cmd_dsync_run_local(ctx, user, brain, slave2) < 0)
+			_ctx->exit_code = EX_TEMPFAIL;
+	} else {
 		cmd_dsync_run_remote(user);
+	}
 
 	if (dsync_brain_deinit(&brain) < 0)
 		_ctx->exit_code = EX_TEMPFAIL;
--- a/src/doveadm/dsync/dsync-brain-mailbox-tree.c	Mon Jun 25 00:01:59 2012 +0300
+++ b/src/doveadm/dsync/dsync-brain-mailbox-tree.c	Mon Jun 25 01:14:03 2012 +0300
@@ -122,8 +122,8 @@
 
 	deletes = dsync_mailbox_tree_get_deletes(brain->local_mailbox_tree,
 						 &count);
-	dsync_slave_send_mailbox_deletes(brain->slave, deletes, count,
-					 brain->hierarchy_sep);
+	(void)dsync_slave_send_mailbox_deletes(brain->slave, deletes, count,
+					       brain->hierarchy_sep);
 
 	brain->state = DSYNC_STATE_RECV_MAILBOX_TREE;
 }
--- a/src/doveadm/dsync/dsync-brain-mailbox.c	Mon Jun 25 00:01:59 2012 +0300
+++ b/src/doveadm/dsync/dsync-brain-mailbox.c	Mon Jun 25 01:14:03 2012 +0300
@@ -372,9 +372,9 @@
 	}
 
 	/* start exporting this mailbox (wait for remote to start importing) */
-	dsync_slave_send_mailbox(brain->slave, &dsync_box);
-	dsync_brain_sync_mailbox_init(brain, box, &dsync_box,
-				      DSYNC_BOX_STATE_MAILBOX);
+	(void)dsync_slave_send_mailbox(brain->slave, &dsync_box);
+	(void)dsync_brain_sync_mailbox_init(brain, box, &dsync_box,
+					    DSYNC_BOX_STATE_MAILBOX);
 	brain->state = DSYNC_STATE_SYNC_MAILS;
 }
 
@@ -560,13 +560,13 @@
 		memcpy(delete_box.mailbox_guid, dsync_box->mailbox_guid,
 		       sizeof(delete_box.mailbox_guid));
 		delete_box.mailbox_lost = TRUE;
-		dsync_slave_send_mailbox(brain->slave, &delete_box);
+		(void)dsync_slave_send_mailbox(brain->slave, &delete_box);
 		return TRUE;
 	}
 	i_assert(local_dsync_box.uid_validity != 0);
 	i_assert(memcmp(dsync_box->mailbox_guid, local_dsync_box.mailbox_guid,
 			sizeof(dsync_box->mailbox_guid)) == 0);
-	dsync_slave_send_mailbox(brain->slave, &local_dsync_box);
+	(void)dsync_slave_send_mailbox(brain->slave, &local_dsync_box);
 
 	dsync_brain_mailbox_update_pre(brain, box, &local_dsync_box, dsync_box);
 
--- a/src/doveadm/dsync/dsync-brain-mails.c	Mon Jun 25 00:01:59 2012 +0300
+++ b/src/doveadm/dsync/dsync-brain-mails.c	Mon Jun 25 01:14:03 2012 +0300
@@ -155,7 +155,7 @@
 		if (changes_during_sync)
 			brain->changes_during_sync = TRUE;
 	}
-	dsync_slave_send_mailbox_state(brain->slave, &state);
+	(void)dsync_slave_send_mailbox_state(brain->slave, &state);
 }
 
 static bool dsync_brain_recv_mail(struct dsync_brain *brain)
--- a/src/doveadm/dsync/dsync-mailbox-import.c	Mon Jun 25 00:01:59 2012 +0300
+++ b/src/doveadm/dsync/dsync-mailbox-import.c	Mon Jun 25 01:14:03 2012 +0300
@@ -170,19 +170,18 @@
 	return importer;
 }
 
-static int dsync_mail_error(struct dsync_mailbox_importer *importer,
-			    struct mail *mail, const char *field)
+static void dsync_mail_error(struct dsync_mailbox_importer *importer,
+			     struct mail *mail, const char *field)
 {
 	const char *errstr;
 	enum mail_error error;
 
 	errstr = mailbox_get_last_error(importer->box, &error);
 	if (error == MAIL_ERROR_EXPUNGED)
-		return 0;
+		return;
 
 	i_error("Can't lookup %s for UID=%u: %s", field, mail->uid, errstr);
 	importer->failed = TRUE;
-	return -1;
 }
 
 static bool
@@ -768,7 +767,7 @@
 	importer->cur_guid = NULL;
 	importer->next_local_seq = 0;
 
-	mailbox_search_deinit(&importer->search_ctx);
+	(void)mailbox_search_deinit(&importer->search_ctx);
 	dsync_mailbox_import_search_init(importer);
 }
 
@@ -1026,10 +1025,10 @@
 		dsync_mailbox_common_uid_found(importer);
 	}
 	/* skip common local mails */
-	importer_next_mail(importer, importer->last_common_uid+1);
+	(void)importer_next_mail(importer, importer->last_common_uid+1);
 	/* if there are any local mails left, add them to newmails list */
 	while (importer->cur_mail != NULL)
-		dsync_mailbox_try_save(importer, NULL);
+		(void)dsync_mailbox_try_save(importer, NULL);
 
 	dsync_mailbox_import_assign_new_uids(importer);
 }
@@ -1431,8 +1430,10 @@
 			mailbox_get_vname(importer->box), msgs_left);
 	}
 
-	if (importer->search_ctx != NULL)
-		mailbox_search_deinit(&importer->search_ctx);
+	if (importer->search_ctx != NULL) {
+		if (mailbox_search_deinit(&importer->search_ctx) < 0)
+			importer->failed = TRUE;
+	}
 	mail_free(&importer->mail);
 	mail_free(&importer->ext_mail);
 
--- a/src/doveadm/dsync/dsync-mailbox-tree.c	Mon Jun 25 00:01:59 2012 +0300
+++ b/src/doveadm/dsync/dsync-mailbox-tree.c	Mon Jun 25 01:14:03 2012 +0300
@@ -300,7 +300,7 @@
 					    guid_128_hash, guid_128_cmp);
 	iter = dsync_mailbox_tree_iter_init(tree);
 	while (dsync_mailbox_tree_iter_next(iter, &name, &node))
-		dsync_mailbox_tree_guid_hash_add(tree, node);
+		(void)dsync_mailbox_tree_guid_hash_add(tree, node);
 	dsync_mailbox_tree_iter_deinit(&iter);
 	return ret;
 }
--- a/src/doveadm/dsync/dsync-slave.c	Mon Jun 25 00:01:59 2012 +0300
+++ b/src/doveadm/dsync/dsync-slave.c	Mon Jun 25 01:14:03 2012 +0300
@@ -40,11 +40,9 @@
 		DSYNC_SLAVE_SEND_RET_OK;
 }
 
-enum dsync_slave_send_ret
-dsync_slave_send_end_of_list(struct dsync_slave *slave)
+void dsync_slave_send_end_of_list(struct dsync_slave *slave)
 {
 	slave->v.send_end_of_list(slave);
-	return dsync_slave_send_ret(slave);
 }
 
 enum dsync_slave_send_ret
--- a/src/doveadm/dsync/dsync-slave.h	Mon Jun 25 00:01:59 2012 +0300
+++ b/src/doveadm/dsync/dsync-slave.h	Mon Jun 25 01:14:03 2012 +0300
@@ -54,8 +54,7 @@
 dsync_slave_recv_handshake(struct dsync_slave *slave,
 			   const struct dsync_slave_settings **set_r);
 
-enum dsync_slave_send_ret
-dsync_slave_send_end_of_list(struct dsync_slave *slave);
+void dsync_slave_send_end_of_list(struct dsync_slave *slave);
 
 enum dsync_slave_send_ret
 dsync_slave_send_mailbox_state(struct dsync_slave *slave,
--- a/src/doveadm/server-connection.c	Mon Jun 25 00:01:59 2012 +0300
+++ b/src/doveadm/server-connection.c	Mon Jun 25 01:14:03 2012 +0300
@@ -303,8 +303,8 @@
 	return 0;
 }
 
-struct server_connection *
-server_connection_create(struct doveadm_server *server)
+int server_connection_create(struct doveadm_server *server,
+			     struct server_connection **conn_r)
 {
 #define DOVEADM_SERVER_HANDSHAKE "VERSION\tdoveadm-server\t1\t0\n"
 	struct server_connection *conn;
@@ -324,8 +324,12 @@
 	o_stream_nsend_str(conn->output, DOVEADM_SERVER_HANDSHAKE);
 
 	array_append(&conn->server->connections, &conn, 1);
-	server_connection_read_settings(conn);
-	return conn;
+	if (server_connection_read_settings(conn) < 0) {
+		server_connection_destroy(&conn);
+		return -1;
+	}
+	*conn_r = conn;
+	return 0;
 }
 
 void server_connection_destroy(struct server_connection **_conn)
--- a/src/doveadm/server-connection.h	Mon Jun 25 00:01:59 2012 +0300
+++ b/src/doveadm/server-connection.h	Mon Jun 25 01:14:03 2012 +0300
@@ -9,11 +9,12 @@
 };
 
 struct doveadm_server;
+struct server_connection;
 
 typedef void server_cmd_callback_t(enum server_cmd_reply reply, void *context);
 
-struct server_connection *
-server_connection_create(struct doveadm_server *server);
+int server_connection_create(struct doveadm_server *server,
+			     struct server_connection **conn_r);
 void server_connection_destroy(struct server_connection **conn);
 
 /* Return the server given to create() */
--- a/src/imap-login/client.c	Mon Jun 25 00:01:59 2012 +0300
+++ b/src/imap-login/client.c	Mon Jun 25 01:14:03 2012 +0300
@@ -371,7 +371,7 @@
 		}
 	}
 	o_stream_uncork(imap_client->common.output);
-	client_unref(&client);
+	(void)client_unref(&client);
 }
 
 static struct client *imap_client_alloc(pool_t pool)
--- a/src/imap/cmd-fetch.c	Mon Jun 25 00:01:59 2012 +0300
+++ b/src/imap/cmd-fetch.c	Mon Jun 25 01:14:03 2012 +0300
@@ -224,7 +224,7 @@
 	if (!fetch_parse_args(ctx, cmd, &args[1], &next_arg) ||
 	    (imap_arg_get_list(next_arg, &list_arg) &&
 	     !fetch_parse_modifiers(ctx, cmd, list_arg))) {
-		imap_fetch_deinit(ctx);
+		(void)imap_fetch_deinit(ctx);
 		return TRUE;
 	}
 
--- a/src/imap/cmd-idle.c	Mon Jun 25 00:01:59 2012 +0300
+++ b/src/imap/cmd-idle.c	Mon Jun 25 01:14:03 2012 +0300
@@ -143,7 +143,7 @@
 
 	ctx->sync_pending = FALSE;
 	ctx->sync_ctx = imap_sync_init(ctx->client, box, 0, 0);
-	cmd_idle_continue(ctx->cmd);
+	(void)cmd_idle_continue(ctx->cmd);
 }
 
 static void idle_callback(struct mailbox *box, struct cmd_idle_context *ctx)
--- a/src/imap/cmd-list.c	Mon Jun 25 00:01:59 2012 +0300
+++ b/src/imap/cmd-list.c	Mon Jun 25 01:14:03 2012 +0300
@@ -479,7 +479,7 @@
 		imap_quote_append_string(str, str_c(mutf7_name), FALSE);
 		mailbox_childinfo2str(ctx, str, flags);
 
-		ret = client_send_line(ctx->cmd->client, str_c(str));
+		ret = client_send_line_next(ctx->cmd->client, str_c(str));
 		if (ctx->used_status) T_BEGIN {
 			list_send_status(ctx, name, flags);
 		} T_END;
--- a/src/imap/imap-client.c	Mon Jun 25 00:01:59 2012 +0300
+++ b/src/imap/imap-client.c	Mon Jun 25 01:14:03 2012 +0300
@@ -285,7 +285,12 @@
 	client_disconnect(client, msg);
 }
 
-int client_send_line(struct client *client, const char *data)
+void client_send_line(struct client *client, const char *data)
+{
+	(void)client_send_line_next(client, data);
+}
+
+int client_send_line_next(struct client *client, const char *data)
 {
 	struct const_iovec iov[2];
 
@@ -807,7 +812,7 @@
 		return FALSE;
 
 	if (client->input_lock == NULL)
-		cmd_sync_delayed(client);
+		(void)cmd_sync_delayed(client);
 	return TRUE;
 }
 
--- a/src/imap/imap-client.h	Mon Jun 25 00:01:59 2012 +0300
+++ b/src/imap/imap-client.h	Mon Jun 25 01:14:03 2012 +0300
@@ -176,9 +176,12 @@
 void client_disconnect(struct client *client, const char *reason);
 void client_disconnect_with_error(struct client *client, const char *msg);
 
+/* Send a line of data to client. */
+void client_send_line(struct client *client, const char *data);
 /* Send a line of data to client. Returns 1 if ok, 0 if buffer is getting full,
-   -1 if error */
-int client_send_line(struct client *client, const char *data);
+   -1 if error. This should be used when you're (potentially) sending a lot of
+   lines to client. */
+int client_send_line_next(struct client *client, const char *data);
 /* Send line of data to client, prefixed with client->tag. You need to prefix
    the data with "OK ", "NO " or "BAD ". */
 void client_send_tagline(struct client_command_context *cmd, const char *data);
--- a/src/imap/imap-fetch-body.c	Mon Jun 25 00:01:59 2012 +0300
+++ b/src/imap/imap-fetch-body.c	Mon Jun 25 01:14:03 2012 +0300
@@ -333,7 +333,8 @@
 	const char *str;
 
 	msgpart = imap_msgpart_full();
-	fetch_and_free_msgpart(ctx, mail, &msgpart);
+	if (fetch_and_free_msgpart(ctx, mail, &msgpart) < 0)
+		return -1;
 
 	str = t_strdup_printf(" RFC822 {%"PRIuUOFF_T"}\r\n", ctx->cur_size);
 	if (ctx->first) {
@@ -353,7 +354,8 @@
 	const char *str;
 
 	msgpart = imap_msgpart_header();
-	fetch_and_free_msgpart(ctx, mail, &msgpart);
+	if (fetch_and_free_msgpart(ctx, mail, &msgpart) < 0)
+		return -1;
 
 	str = t_strdup_printf(" RFC822.HEADER {%"PRIuUOFF_T"}\r\n",
 			      ctx->cur_size);
@@ -374,7 +376,8 @@
 	const char *str;
 
 	msgpart = imap_msgpart_body();
-	fetch_and_free_msgpart(ctx, mail, &msgpart);
+	if (fetch_and_free_msgpart(ctx, mail, &msgpart) < 0)
+		return -1;
 
 	str = t_strdup_printf(" RFC822.TEXT {%"PRIuUOFF_T"}\r\n",
 			      ctx->cur_size);
--- a/src/imap/imap-sync.c	Mon Jun 25 00:01:59 2012 +0300
+++ b/src/imap/imap-sync.c	Mon Jun 25 01:14:03 2012 +0300
@@ -306,7 +306,7 @@
 	str_append(str, "FLAGS (");
 	imap_write_flags(str, flags, keywords);
 	str_append(str, "))");
-	return client_send_line(ctx->client, str_c(str));
+	return client_send_line_next(ctx->client, str_c(str));
 }
 
 static int imap_sync_send_modseq(struct imap_sync_context *ctx, string_t *str)
@@ -319,7 +319,7 @@
 		str_printfa(str, "UID %u ", ctx->mail->uid);
 	imap_sync_add_modseq(ctx, str);
 	str_append_c(str, ')');
-	return client_send_line(ctx->client, str_c(str));
+	return client_send_line_next(ctx->client, str_c(str));
 }
 
 static void imap_sync_vanished(struct imap_sync_context *ctx)
@@ -437,7 +437,7 @@
 
 				str_truncate(str, 0);
 				str_printfa(str, "* %u EXPUNGE", ctx->seq);
-				ret = client_send_line(ctx->client, str_c(str));
+				ret = client_send_line_next(ctx->client, str_c(str));
 			}
 			if (ctx->seq < ctx->sync_rec.seq1) {
 				/* update only after we're finished, so that
--- a/src/imap/main.c	Mon Jun 25 00:01:59 2012 +0300
+++ b/src/imap/main.c	Mon Jun 25 01:14:03 2012 +0300
@@ -235,9 +235,9 @@
 	if (input.username == NULL)
 		i_fatal("USER environment missing");
 	if ((value = getenv("IP")) != NULL)
-		net_addr2ip(value, &input.remote_ip);
+		(void)net_addr2ip(value, &input.remote_ip);
 	if ((value = getenv("LOCAL_IP")) != NULL)
-		net_addr2ip(value, &input.local_ip);
+		(void)net_addr2ip(value, &input.local_ip);
 
 	input_base64 = getenv("CLIENT_INPUT");
 	input_buf = input_base64 == NULL ? NULL :
--- a/src/indexer/master-connection.c	Mon Jun 25 00:01:59 2012 +0300
+++ b/src/indexer/master-connection.c	Mon Jun 25 01:14:03 2012 +0300
@@ -89,9 +89,10 @@
 			percentage = counter*100 / max;
 			if (percentage != percentage_sent && percentage < 100) {
 				percentage_sent = percentage;
-				i_snprintf(percentage_str,
-					   sizeof(percentage_str), "%u\n",
-					   percentage);
+				if (i_snprintf(percentage_str,
+					       sizeof(percentage_str), "%u\n",
+					       percentage) < 0)
+					i_unreached();
 				(void)write_full(conn->fd, percentage_str,
 						 strlen(percentage_str));
 			}
@@ -169,7 +170,8 @@
 		}
 		ret = -1;
 	} else if (strchr(what, 'i') != NULL) {
-		index_mailbox_precache(conn, box);
+		if (index_mailbox_precache(conn, box) < 0)
+			ret = -1;
 	}
 	mailbox_free(&box);
 	return ret;
--- a/src/lib-auth/auth-client.c	Mon Jun 25 00:01:59 2012 +0300
+++ b/src/lib-auth/auth-client.c	Mon Jun 25 01:14:03 2012 +0300
@@ -34,7 +34,7 @@
 void auth_client_connect(struct auth_client *client)
 {
 	if (client->conn->fd == -1)
-		auth_server_connection_connect(client->conn);
+		(void)auth_server_connection_connect(client->conn);
 }
 
 void auth_client_disconnect(struct auth_client *client, const char *reason)
--- a/src/lib-imap/imap-parser.c	Mon Jun 25 00:01:59 2012 +0300
+++ b/src/lib-imap/imap-parser.c	Mon Jun 25 01:14:03 2012 +0300
@@ -238,7 +238,7 @@
 		if (parser->str_first_escape >= 0 &&
 		    (parser->flags & IMAP_PARSE_FLAG_NO_UNESCAPE) == 0) {
 			/* -1 because we skipped the '"' prefix */
-			str_unescape(str + parser->str_first_escape-1);
+			(void)str_unescape(str + parser->str_first_escape-1);
 		}
 		arg->_data.str = str;
 		arg->str_len = strlen(str);
--- a/src/lib-imap/imap-quote.c	Mon Jun 25 00:01:59 2012 +0300
+++ b/src/lib-imap/imap-quote.c	Mon Jun 25 01:14:03 2012 +0300
@@ -95,24 +95,31 @@
 		str_append_c(str, '"');
 }
 
+static const char *
+imap_quote_internal(pool_t pool, const unsigned char *value,
+		    size_t value_len, bool fix_text)
+{
+	string_t *str;
+
+	str = t_str_new(value_len + MAX_INT_STRLEN + 5);
+	imap_quote_append(str, value, value_len, fix_text);
+	return pool->datastack_pool ? str_c(str) :
+		p_strndup(pool, str_data(str), str_len(str));
+}
+
 const char *imap_quote(pool_t pool, const unsigned char *value,
 		       size_t value_len, bool fix_text)
 {
-	string_t *str;
-	char *ret;
+	const char *ret;
 
 	if (value == NULL)
 		return "NIL";
 
 	if (!pool->datastack_pool)
-		t_push();
-
-	str = t_str_new(value_len + MAX_INT_STRLEN + 5);
-	imap_quote_append(str, value, value_len, fix_text);
-	ret = p_strndup(pool, str_data(str), str_len(str));
-
-	if (!pool->datastack_pool)
-		t_pop();
+		ret = imap_quote_internal(pool, value, value_len, fix_text);
+	else T_BEGIN {
+		ret = imap_quote_internal(pool, value, value_len, fix_text);
+	} T_END;
 	return ret;
 }
 
--- a/src/lib-index/mail-cache-compress.c	Mon Jun 25 00:01:59 2012 +0300
+++ b/src/lib-index/mail-cache-compress.c	Mon Jun 25 01:14:03 2012 +0300
@@ -277,7 +277,7 @@
 	buffer_free(&ctx.buffer);
 	buffer_free(&ctx.field_seen);
 
-	o_stream_seek(output, 0);
+	(void)o_stream_seek(output, 0);
 	o_stream_nsend(output, &hdr, sizeof(hdr));
 
 	mail_cache_view_close(&cache_view);
--- a/src/lib-index/mail-cache-transaction.c	Mon Jun 25 00:01:59 2012 +0300
+++ b/src/lib-index/mail-cache-transaction.c	Mon Jun 25 01:14:03 2012 +0300
@@ -73,7 +73,9 @@
 	struct mail_cache_transaction_ctx *ctx = CACHE_TRANS_CONTEXT(t);
 	struct mail_index_transaction_vfuncs super = ctx->super;
 
-	mail_cache_transaction_commit(&ctx);
+	/* a failed cache commit isn't important enough to fail the entire
+	   index transaction, so we'll just ignore it */
+	(void)mail_cache_transaction_commit(&ctx);
 	return super.commit(t, result_r);
 }
 
--- a/src/lib-index/mail-cache.c	Mon Jun 25 00:01:59 2012 +0300
+++ b/src/lib-index/mail-cache.c	Mon Jun 25 01:14:03 2012 +0300
@@ -85,7 +85,7 @@
 	file_cache_set_fd(cache->file_cache, cache->fd);
 
 	if (fstat(cache->fd, &st) == 0)
-		file_cache_set_size(cache->file_cache, st.st_size);
+		(void)file_cache_set_size(cache->file_cache, st.st_size);
 	else if (!ESTALE_FSTAT(errno))
 		mail_cache_set_syscall_error(cache, "fstat()");
 
--- a/src/lib-index/mail-index-fsck.c	Mon Jun 25 00:01:59 2012 +0300
+++ b/src/lib-index/mail-index-fsck.c	Mon Jun 25 01:14:03 2012 +0300
@@ -210,7 +210,7 @@
 	/* add keyword records so we can start appending names directly */
 	rec_pos = dest->used;
 	memset(&new_kw_rec, 0, sizeof(new_kw_rec));
-	buffer_append_space_unsafe(dest, keywords_count * sizeof(*kw_rec));
+	(void)buffer_append_space_unsafe(dest, keywords_count * sizeof(*kw_rec));
 
 	/* write the actual records and names */
 	name_base_pos = dest->used;
--- a/src/lib-index/mail-index-map-hdr.c	Mon Jun 25 00:01:59 2012 +0300
+++ b/src/lib-index/mail-index-map-hdr.c	Mon Jun 25 01:14:03 2012 +0300
@@ -52,7 +52,7 @@
 			return -1;
 		}
 
-		mail_index_map_register_ext(map, name, ext_offset, ext_hdr);
+		(void)mail_index_map_register_ext(map, name, ext_offset, ext_hdr);
 	}
 	return 0;
 }
--- a/src/lib-index/mail-index-modseq.c	Mon Jun 25 00:01:59 2012 +0300
+++ b/src/lib-index/mail-index-modseq.c	Mon Jun 25 01:14:03 2012 +0300
@@ -344,8 +344,7 @@
 		for (i = 0; i < count; i++) {
 			if (mail_index_lookup_seq(ctx->view,
 						  appends[i].uid, &seq1)) {
-				mail_index_modseq_update_to_highest(ctx, seq1,
-								    seq1);
+				(void)mail_index_modseq_update_to_highest(ctx, seq1, seq1);
 			}
 		}
 		return;
@@ -385,7 +384,7 @@
 		rec = array_idx(&uids, i);
 		if (mail_index_lookup_seq_range(ctx->view, rec->seq1, rec->seq2,
 						&seq1, &seq2))
-			mail_index_modseq_update_to_highest(ctx, seq1, seq2);
+			(void)mail_index_modseq_update_to_highest(ctx, seq1, seq2);
 	}
 }
 
@@ -547,7 +546,7 @@
 
 void mail_index_modseq_append(struct mail_index_modseq_sync *ctx, uint32_t seq)
 {
-	mail_index_modseq_update_to_highest(ctx, seq, seq);
+	(void)mail_index_modseq_update_to_highest(ctx, seq, seq);
 }
 
 void mail_index_modseq_expunge(struct mail_index_modseq_sync *ctx,
--- a/src/lib-index/mail-index-private.h	Mon Jun 25 00:01:59 2012 +0300
+++ b/src/lib-index/mail-index-private.h	Mon Jun 25 01:14:03 2012 +0300
@@ -343,14 +343,14 @@
 
 void mail_index_fsck_locked(struct mail_index *index);
 
-int mail_index_set_error(struct mail_index *index, const char *fmt, ...)
+void mail_index_set_error(struct mail_index *index, const char *fmt, ...)
 	ATTR_FORMAT(2, 3);
 /* "%s failed with index file %s: %m" */
-int mail_index_set_syscall_error(struct mail_index *index,
-				 const char *function);
+void mail_index_set_syscall_error(struct mail_index *index,
+				  const char *function);
 /* "%s failed with file %s: %m" */
-int mail_index_file_set_syscall_error(struct mail_index *index,
-				      const char *filepath,
-				      const char *function);
+void mail_index_file_set_syscall_error(struct mail_index *index,
+				       const char *filepath,
+				       const char *function);
 
 #endif
--- a/src/lib-index/mail-index-strmap.c	Mon Jun 25 00:01:59 2012 +0300
+++ b/src/lib-index/mail-index-strmap.c	Mon Jun 25 01:14:03 2012 +0300
@@ -953,9 +953,9 @@
 	i_assert(block_size != 0);
 
 	end_offset = output->offset;
-	o_stream_seek(output, block_offset);
+	(void)o_stream_seek(output, block_offset);
 	o_stream_nsend(output, &block_size, sizeof(block_size));
-	o_stream_seek(output, end_offset);
+	(void)o_stream_seek(output, end_offset);
 
 	if (output->last_failed_errno != 0)
 		return;
@@ -1167,7 +1167,7 @@
 
 	/* write the new records */
 	output = o_stream_create_fd(view->strmap->fd, 0, FALSE);
-	o_stream_seek(output, view->last_read_block_offset);
+	(void)o_stream_seek(output, view->last_read_block_offset);
 	o_stream_cork(output);
 	mail_index_strmap_write_block(view, output, i,
 				      view->last_read_uid + 1);
--- a/src/lib-index/mail-index-sync-update.c	Mon Jun 25 00:01:59 2012 +0300
+++ b/src/lib-index/mail-index-sync-update.c	Mon Jun 25 01:14:03 2012 +0300
@@ -92,7 +92,7 @@
 struct mail_index_map *
 mail_index_sync_get_atomic_map(struct mail_index_sync_map_ctx *ctx)
 {
-	mail_index_sync_move_to_private_memory(ctx);
+	(void)mail_index_sync_move_to_private_memory(ctx);
 	mail_index_record_map_move_to_private(ctx->view->map);
 	mail_index_modseq_sync_map_replaced(ctx->modseq_ctx);
 	return ctx->view->map;
--- a/src/lib-index/mail-index-transaction-private.h	Mon Jun 25 00:01:59 2012 +0300
+++ b/src/lib-index/mail-index-transaction-private.h	Mon Jun 25 01:14:03 2012 +0300
@@ -147,7 +147,7 @@
 					   unsigned int right_idx,
 					   uint32_t seq);
 
-bool mail_index_ext_using_reset_id(struct mail_index_transaction *t,
+void mail_index_ext_using_reset_id(struct mail_index_transaction *t,
 				   uint32_t ext_id, uint32_t reset_id);
 
 #endif
--- a/src/lib-index/mail-index-transaction-sort-appends.c	Mon Jun 25 00:01:59 2012 +0300
+++ b/src/lib-index/mail-index-transaction-sort-appends.c	Mon Jun 25 01:14:03 2012 +0300
@@ -51,9 +51,9 @@
 
 			seq = *ext_rec < first_new_seq ? *ext_rec :
 				old_to_newseq_map[*ext_rec - first_new_seq];
-			mail_index_seq_array_add(&new_array, seq, ext_rec+1,
-						 old_array->arr.element_size -
-						 sizeof(*ext_rec), NULL);
+			(void)mail_index_seq_array_add(&new_array, seq, ext_rec+1,
+						       old_array->arr.element_size -
+						       sizeof(*ext_rec), NULL);
 		}
 		array_free(old_array);
 		ext_rec_arrays[j] = new_array;
--- a/src/lib-index/mail-index-transaction-update.c	Mon Jun 25 00:01:59 2012 +0300
+++ b/src/lib-index/mail-index-transaction-update.c	Mon Jun 25 01:14:03 2012 +0300
@@ -833,7 +833,7 @@
 	t->log_ext_updates = mail_index_transaction_has_ext_changes(t);
 }
 
-bool mail_index_ext_using_reset_id(struct mail_index_transaction *t,
+void mail_index_ext_using_reset_id(struct mail_index_transaction *t,
 				   uint32_t ext_id, uint32_t reset_id)
 {
 	uint32_t *reset_id_p;
@@ -848,7 +848,6 @@
 		/* reset_id changed, clear existing changes */
 		mail_index_ext_reset_changes(t, ext_id);
 	}
-	return changed;
 }
 
 void mail_index_ext_set_reset_id(struct mail_index_transaction *t,
@@ -953,8 +952,8 @@
 				     &old_diff32)) {
 		/* already incremented this sequence in this transaction */
 		diff32 += old_diff32;
-		mail_index_seq_array_add(array, seq, &diff32, sizeof(diff32),
-					 NULL);
+		(void)mail_index_seq_array_add(array, seq, &diff32,
+					       sizeof(diff32), NULL);
 	}
 	return diff32;
 }
--- a/src/lib-index/mail-index-view-sync.c	Mon Jun 25 00:01:59 2012 +0300
+++ b/src/lib-index/mail-index-view-sync.c	Mon Jun 25 01:14:03 2012 +0300
@@ -370,7 +370,8 @@
 					   &kw_reset) < 0)
 			return -1;
 
-		view_sync_update_keywords(ctx, new_rec->uid);
+		if (view_sync_update_keywords(ctx, new_rec->uid) < 0)
+			return -1;
 		changed = TRUE;
 	}
 
@@ -463,7 +464,8 @@
 			return -1;
 		mail_index_map_lookup_keywords(new_map, j + 1,
 					       &ctx->lost_new_kw);
-		view_sync_update_keywords(ctx, new_rec->uid);
+		if (view_sync_update_keywords(ctx, new_rec->uid) < 0)
+			return -1;
 	}
 	*expunge_count_r = view_sync_expunges2seqs(ctx);
 
--- a/src/lib-index/mail-index-write.c	Mon Jun 25 00:01:59 2012 +0300
+++ b/src/lib-index/mail-index-write.c	Mon Jun 25 01:14:03 2012 +0300
@@ -102,7 +102,7 @@
 	}
 
 	if ((index->flags & MAIL_INDEX_OPEN_FLAG_KEEP_BACKUPS) != 0)
-		mail_index_create_backup(index);
+		(void)mail_index_create_backup(index);
 
 	if (ret == 0 && rename(path, index->filepath) < 0) {
 		mail_index_set_error(index, "rename(%s, %s) failed: %m",
@@ -134,7 +134,7 @@
 
 	if (!MAIL_INDEX_IS_IN_MEMORY(index)) {
 		if (mail_index_recreate(index) < 0) {
-			mail_index_move_to_memory(index);
+			(void)mail_index_move_to_memory(index);
 			return;
 		}
 	}
--- a/src/lib-index/mail-index.c	Mon Jun 25 00:01:59 2012 +0300
+++ b/src/lib-index/mail-index.c	Mon Jun 25 01:14:03 2012 +0300
@@ -403,8 +403,10 @@
 	}
 
 	if (index->fd == -1) {
-		if (errno != ENOENT)
-			return mail_index_set_syscall_error(index, "open()");
+		if (errno != ENOENT) {
+			mail_index_set_syscall_error(index, "open()");
+			return -1;
+		}
 
 		/* have to create it */
 		return 0;
@@ -705,12 +707,15 @@
 	if (nfs_safe_stat(index->filepath, &st2) < 0) {
 		if (errno == ENOENT)
 			return 0;
-		return mail_index_set_syscall_error(index, "stat()");
+		mail_index_set_syscall_error(index, "stat()");
+		return -1;
 	}
 
 	if (fstat(index->fd, &st1) < 0) {
-		if (!ESTALE_FSTAT(errno))
-			return mail_index_set_syscall_error(index, "fstat()");
+		if (!ESTALE_FSTAT(errno)) {
+			mail_index_set_syscall_error(index, "fstat()");
+			return -1;
+		}
 		/* deleted/recreated, reopen */
 	} else if (st1.st_ino == st2.st_ino &&
 		   CMP_DEV_T(st1.st_dev, st2.st_dev)) {
@@ -738,7 +743,7 @@
 	return index->cache;
 }
 
-int mail_index_set_error(struct mail_index *index, const char *fmt, ...)
+void mail_index_set_error(struct mail_index *index, const char *fmt, ...)
 {
 	va_list va;
 
@@ -753,8 +758,6 @@
 
 		i_error("%s", index->error);
 	}
-
-	return -1;
 }
 
 bool mail_index_is_in_memory(struct mail_index *index)
@@ -875,16 +878,15 @@
 		mail_index_file_set_syscall_error(index, path, "fchmod()");
 }
 
-int mail_index_set_syscall_error(struct mail_index *index,
-				 const char *function)
+void mail_index_set_syscall_error(struct mail_index *index,
+				  const char *function)
 {
-	return mail_index_file_set_syscall_error(index, index->filepath,
-						 function);
+	mail_index_file_set_syscall_error(index, index->filepath, function);
 }
 
-int mail_index_file_set_syscall_error(struct mail_index *index,
-				      const char *filepath,
-				      const char *function)
+void mail_index_file_set_syscall_error(struct mail_index *index,
+				       const char *filepath,
+				       const char *function)
 {
 	const char *errstr;
 
@@ -894,7 +896,7 @@
 	if (ENOSPACE(errno)) {
 		index->nodiskspace = TRUE;
 		if ((index->flags & MAIL_INDEX_OPEN_FLAG_NEVER_IN_MEMORY) == 0)
-			return -1;
+			return;
 	}
 
 	if (errno == EACCES) {
@@ -904,12 +906,12 @@
 			errstr = eacces_error_get_creating(function, filepath);
 		else
 			errstr = eacces_error_get(function, filepath);
-		return mail_index_set_error(index, "%s", errstr);
+		mail_index_set_error(index, "%s", errstr);
 	} else {
 		const char *suffix = errno != EFBIG ? "" :
 			" (process was started with ulimit -f limit)";
-		return mail_index_set_error(index, "%s failed with file %s: "
-					    "%m%s", function, filepath, suffix);
+		mail_index_set_error(index, "%s failed with file %s: "
+				     "%m%s", function, filepath, suffix);
 	}
 }
 
--- a/src/lib-index/mail-transaction-log-file.c	Mon Jun 25 00:01:59 2012 +0300
+++ b/src/lib-index/mail-transaction-log-file.c	Mon Jun 25 01:14:03 2012 +0300
@@ -19,12 +19,12 @@
 static int
 mail_transaction_log_file_sync(struct mail_transaction_log_file *file);
 
-static int
+static void
 log_file_set_syscall_error(struct mail_transaction_log_file *file,
 			   const char *function)
 {
-	return mail_index_file_set_syscall_error(file->log->index,
-						 file->filepath, function);
+	mail_index_file_set_syscall_error(file->log->index,
+					  file->filepath, function);
 }
 
 static void
@@ -392,7 +392,7 @@
 	}
 
 	if (file->log->index->lock_method == FILE_LOCK_METHOD_DOTLOCK) {
-		mail_transaction_log_file_undotlock(file);
+		(void)mail_transaction_log_file_undotlock(file);
 		return;
 	}
 
@@ -654,8 +654,10 @@
 	if (reset)
 		rename_existing = FALSE;
 	else if (nfs_safe_stat(file->filepath, &st) < 0) {
-		if (errno != ENOENT)
-			return log_file_set_syscall_error(file, "stat()");
+		if (errno != ENOENT) {
+			log_file_set_syscall_error(file, "stat()");
+			return -1;
+		}
 		rename_existing = FALSE;
 	} else if (st.st_ino == file->st_ino &&
 		   CMP_DEV_T(st.st_dev, file->st_dev) &&
@@ -712,14 +714,18 @@
 
 	if (index->ext_hdr_init_data != NULL && reset)
 		log_write_ext_hdr_init_data(index, writebuf);
-	if (write_full(new_fd, writebuf->data, writebuf->used) < 0)
-		return log_file_set_syscall_error(file, "write_full()");
+	if (write_full(new_fd, writebuf->data, writebuf->used) < 0) {
+		log_file_set_syscall_error(file, "write_full()");
+		return -1;
+	}
 
 	if (file->log->index->fsync_mode == FSYNC_MODE_ALWAYS) {
 		/* the header isn't important, so don't bother calling
 		   fdatasync() unless it's required */
-		if (fdatasync(new_fd) < 0)
-			return log_file_set_syscall_error(file, "fdatasync()");
+		if (fdatasync(new_fd) < 0) {
+			log_file_set_syscall_error(file, "fdatasync()");
+			return -1;
+		}
 	}
 
 	file->fd = new_fd;
@@ -795,8 +801,10 @@
 	fd = file_dotlock_open(&new_dotlock_set, file->filepath, 0, &dotlock);
 	umask(old_mask);
 
-	if (fd == -1)
-		return log_file_set_syscall_error(file, "file_dotlock_open()");
+	if (fd == -1) {
+		log_file_set_syscall_error(file, "file_dotlock_open()");
+		return -1;
+	}
 	mail_index_fchown(index, fd, file_dotlock_get_lock_path(dotlock));
 
         /* either fd gets used or the dotlock gets deleted and returned fd
@@ -828,7 +836,8 @@
 			if (errno == ENOENT)
 				return 0;
 
-			return log_file_set_syscall_error(file, "open()");
+			log_file_set_syscall_error(file, "open()");
+			return -1;
                 }
 
 		ignore_estale = i < MAIL_INDEX_ESTALE_RETRY_COUNT;
@@ -1326,8 +1335,10 @@
 		   Without this check we might see partial transactions,
 		   sometimes causing "Extension record updated without intro
 		   prefix" errors. */
-		if (fstat(file->fd, &st) < 0)
-			return log_file_set_syscall_error(file, "fstat()");
+		if (fstat(file->fd, &st) < 0) {
+			log_file_set_syscall_error(file, "fstat()");
+			return -1;
+		}
 		if ((uoff_t)st.st_size != file->last_size) {
 			file->last_size = st.st_size;
 			return 0;
@@ -1399,7 +1410,8 @@
 		/* log file was deleted in NFS server, fail silently */
 		return 0;
 	} else {
-		return log_file_set_syscall_error(file, "pread()");
+		log_file_set_syscall_error(file, "pread()");
+		return -1;
 	}
 }
 
@@ -1430,7 +1442,8 @@
 			/* log file was deleted in NFS server, fail silently */
 			return 0;
 		}
-		return log_file_set_syscall_error(file, "pread()");
+		log_file_set_syscall_error(file, "pread()");
+		return -1;
 	}
 	return 1;
 }
@@ -1472,10 +1485,8 @@
 	if (file->log->nfs_flush && nfs_flush) {
 		if (!file->locked)
 			nfs_flush_attr_cache_unlocked(file->filepath);
-		else {
-			nfs_flush_attr_cache_fd_locked(file->filepath,
-						       file->fd);
-		}
+		else
+			nfs_flush_attr_cache_fd_locked(file->filepath, file->fd);
 	}
 
 	if (file->buffer != NULL && file->buffer_offset > start_offset) {
@@ -1543,7 +1554,8 @@
 	if (file->mmap_base == MAP_FAILED) {
 		file->mmap_base = NULL;
 		file->mmap_size = 0;
-		return log_file_set_syscall_error(file, "mmap()");
+		log_file_set_syscall_error(file, "mmap()");
+		return -1;
 	}
 
 	if (file->mmap_size > mmap_get_page_size()) {
@@ -1584,8 +1596,10 @@
 	i_assert(file->buffer_offset == 0 || file->mmap_base == NULL);
 	i_assert(file->mmap_size == 0 || file->mmap_base != NULL);
 
-	if (fstat(file->fd, &st) < 0)
-		return log_file_set_syscall_error(file, "fstat()");
+	if (fstat(file->fd, &st) < 0) {
+		log_file_set_syscall_error(file, "fstat()");
+		return -1;
+	}
 	file->last_size = st.st_size;
 
 	if ((uoff_t)st.st_size < file->sync_offset) {
--- a/src/lib-index/test-mail-index-transaction-update.c	Mon Jun 25 00:01:59 2012 +0300
+++ b/src/lib-index/test-mail-index-transaction-update.c	Mon Jun 25 01:14:03 2012 +0300
@@ -277,7 +277,7 @@
 	test_end();
 }
 
-static bool
+static void
 flags_array_check(struct mail_index_transaction *t,
 		  const enum mail_flags *flags, unsigned int msg_count)
 {
@@ -304,7 +304,6 @@
 	}
 	for (; seq <= msg_count; seq++)
 		test_assert(flags[seq] == 0);
-	return TRUE;
 }
 
 static void test_mail_index_flag_update_random(void)
@@ -367,15 +366,15 @@
 	updates = array_get(&t->updates, &count);
 	test_assert(count == 1);
 	test_assert(updates[0].uid1 == 5 && updates[0].uid2 == 7);
-	mail_index_cancel_flag_updates(t, 5);
+	test_assert(mail_index_cancel_flag_updates(t, 5));
 	test_assert(updates[0].uid1 == 6 && updates[0].uid2 == 7);
-	mail_index_cancel_flag_updates(t, 7);
+	test_assert(mail_index_cancel_flag_updates(t, 7));
 	test_assert(updates[0].uid1 == 6 && updates[0].uid2 == 6);
-	mail_index_cancel_flag_updates(t, 6);
+	test_assert(mail_index_cancel_flag_updates(t, 6));
 	test_assert(!array_is_created(&t->updates));
 
 	mail_index_update_flags_range(t, 5, 7, MODIFY_REPLACE, 0);
-	mail_index_cancel_flag_updates(t, 6);
+	test_assert(mail_index_cancel_flag_updates(t, 6));
 	updates = array_get(&t->updates, &count);
 	test_assert(count == 2);
 	test_assert(updates[0].uid1 == 5 && updates[0].uid2 == 5);
--- a/src/lib-index/test-mail-transaction-log-append.c	Mon Jun 25 00:01:59 2012 +0300
+++ b/src/lib-index/test-mail-transaction-log-append.c	Mon Jun 25 01:14:03 2012 +0300
@@ -11,11 +11,10 @@
 
 static bool log_lock_failure = FALSE;
 
-int mail_index_file_set_syscall_error(struct mail_index *index ATTR_UNUSED,
-				      const char *filepath ATTR_UNUSED,
-				      const char *function ATTR_UNUSED)
+void mail_index_file_set_syscall_error(struct mail_index *index ATTR_UNUSED,
+				       const char *filepath ATTR_UNUSED,
+				       const char *function ATTR_UNUSED)
 {
-	return -1;
 }
 
 int mail_transaction_log_lock_head(struct mail_transaction_log *log ATTR_UNUSED)
--- a/src/lib-mail/message-header-decode.c	Mon Jun 25 00:01:59 2012 +0300
+++ b/src/lib-mail/message-header-decode.c	Mon Jun 25 01:14:03 2012 +0300
@@ -178,7 +178,6 @@
 				buffer_t *dest, bool dtcase)
 {
 	struct decode_utf8_context ctx;
-	size_t used = dest->used;
 
 	memset(&ctx, 0, sizeof(ctx));
 	ctx.dest = dest;
--- a/src/lib-mail/message-part-serialize.c	Mon Jun 25 00:01:59 2012 +0300
+++ b/src/lib-mail/message-part-serialize.c	Mon Jun 25 01:14:03 2012 +0300
@@ -39,8 +39,8 @@
 	const char *error;
 };
 
-static unsigned int
-part_serialize(struct message_part *part, buffer_t *dest)
+static void part_serialize(struct message_part *part, buffer_t *dest,
+			   unsigned int *children_count_r)
 {
 	unsigned int count, children_count;
 	size_t children_offset;
@@ -79,8 +79,8 @@
 				      sizeof(children_count));
 
 			if (part->children != NULL) {
-				children_count =
-					part_serialize(part->children, dest);
+				part_serialize(part->children, dest,
+					       &children_count);
 
 				buffer_write(dest, children_offset,
 					     &children_count,
@@ -94,12 +94,14 @@
 		part = part->next;
 	}
 
-	return count;
+	*children_count_r = count;
 }
 
 void message_part_serialize(struct message_part *part, buffer_t *dest)
 {
-	part_serialize(part, dest);
+	unsigned int children_count;
+
+	part_serialize(part, dest, &children_count);
 }
 
 static bool read_next(struct deserialize_context *ctx,
--- a/src/lib-mail/rfc822-parser.c	Mon Jun 25 00:01:59 2012 +0300
+++ b/src/lib-mail/rfc822-parser.c	Mon Jun 25 01:14:03 2012 +0300
@@ -407,7 +407,7 @@
 		/* broken / no value */
 	} else if (*ctx->data == '"') {
 		ret = rfc822_parse_quoted_string(ctx, tmp);
-		str_unescape(str_c_modifiable(tmp) + value_pos);
+		(void)str_unescape(str_c_modifiable(tmp) + value_pos);
 	} else if (ctx->data != ctx->end && *ctx->data == '=') {
 		/* workaround for broken input:
 		   name==?utf-8?b?...?= */
--- a/src/lib-mail/test-istream-dot.c	Mon Jun 25 00:01:59 2012 +0300
+++ b/src/lib-mail/test-istream-dot.c	Mon Jun 25 01:14:03 2012 +0300
@@ -71,7 +71,7 @@
 			}
 		}
 		test_istream_set_size(test_input, input_len);
-		i_stream_read(test_input);
+		(void)i_stream_read(test_input);
 	} else {
 		test_istream_set_size(test_input, input_len);
 		size = 0;
--- a/src/lib-ntlm/ntlm-des.c	Mon Jun 25 00:01:59 2012 +0300
+++ b/src/lib-ntlm/ntlm-des.c	Mon Jun 25 01:14:03 2012 +0300
@@ -589,9 +589,8 @@
 	PUT_32BIT_MSB_FIRST(dest + 4, out[1]);
 }
 
-unsigned char *
-deshash(unsigned char *dst, const unsigned char *key,
-	const unsigned char *src)
+void deshash(unsigned char *dst, const unsigned char *key,
+	     const unsigned char *src)
 {
 	struct des_context ctx;
 
@@ -599,6 +598,4 @@
 		      GET_32BIT_MSB_FIRST(key + 3), &ctx);
 
 	des_cbc_encrypt(dst, src, &ctx);
-
-	return dst;
 }
--- a/src/lib-ntlm/ntlm-des.h	Mon Jun 25 00:01:59 2012 +0300
+++ b/src/lib-ntlm/ntlm-des.h	Mon Jun 25 01:14:03 2012 +0300
@@ -1,7 +1,7 @@
 #ifndef NTLM_DES_H
 #define NTLM_DES_H
 
-unsigned char * deshash(unsigned char *dst, const unsigned char *key,
-			const unsigned char *src);
+void deshash(unsigned char *dst, const unsigned char *key,
+	     const unsigned char *src);
 
 #endif
--- a/src/lib-ntlm/ntlm-encrypt.c	Mon Jun 25 00:01:59 2012 +0300
+++ b/src/lib-ntlm/ntlm-encrypt.c	Mon Jun 25 01:14:03 2012 +0300
@@ -32,8 +32,7 @@
 	return buffer_free_without_data(&wstr);
 }
 
-const unsigned char *
-lm_hash(const char *passwd, unsigned char hash[LM_HASH_SIZE])
+void lm_hash(const char *passwd, unsigned char hash[LM_HASH_SIZE])
 {
 	static const unsigned char lm_magic[8] = "KGS!@#$%";
 	unsigned char buffer[14];
@@ -48,12 +47,9 @@
 	deshash(hash + 8, buffer + 7, lm_magic);
 
 	safe_memset(buffer, 0, sizeof(buffer));
-
-	return hash;
 }
 
-const unsigned char *
-ntlm_v1_hash(const char *passwd, unsigned char hash[NTLMSSP_HASH_SIZE])
+void ntlm_v1_hash(const char *passwd, unsigned char hash[NTLMSSP_HASH_SIZE])
 {
 	size_t len;
 	void *wpwd = t_unicode_str(passwd, 0, &len);
@@ -61,8 +57,6 @@
 	md4_get_digest(wpwd, len, hash);
 
 	safe_memset(wpwd, 0, len);
-
-	return hash;
 }
 
 static void
--- a/src/lib-ntlm/ntlm-encrypt.h	Mon Jun 25 00:01:59 2012 +0300
+++ b/src/lib-ntlm/ntlm-encrypt.h	Mon Jun 25 01:14:03 2012 +0300
@@ -1,11 +1,8 @@
 #ifndef NTLM_ENCRYPT_H
 #define NTLM_ENCRYPT_H
 
-const unsigned char *
-lm_hash(const char *passwd, unsigned char hash[LM_HASH_SIZE]);
-
-const unsigned char *
-ntlm_v1_hash(const char *passwd, unsigned char hash[NTLMSSP_HASH_SIZE]);
+void lm_hash(const char *passwd, unsigned char hash[LM_HASH_SIZE]);
+void ntlm_v1_hash(const char *passwd, unsigned char hash[NTLMSSP_HASH_SIZE]);
 
 void ntlmssp_v1_response(const unsigned char *hash,
 			 const unsigned char *challenge,
--- a/src/lib-otp/otp-hash.c	Mon Jun 25 00:01:59 2012 +0300
+++ b/src/lib-otp/otp-hash.c	Mon Jun 25 01:14:03 2012 +0300
@@ -107,14 +107,12 @@
 	return -1;
 }
 
-int digest_init(struct digest_context *ctx, const unsigned int algo)
+void digest_init(struct digest_context *ctx, const unsigned int algo)
 {
 	i_assert(algo < N_ELEMENTS(digests));
 
 	ctx->digest = digests + algo;
 	ctx->digest->init(&ctx->ctx);
-
-	return 0;
 }
 
 void digest_update(struct digest_context *ctx, const void *data,
--- a/src/lib-otp/otp-hash.h	Mon Jun 25 00:01:59 2012 +0300
+++ b/src/lib-otp/otp-hash.h	Mon Jun 25 01:14:03 2012 +0300
@@ -10,7 +10,7 @@
 };
 
 int digest_find(const char *name);
-int digest_init(struct digest_context *ctx, const unsigned int algo);
+void digest_init(struct digest_context *ctx, const unsigned int algo);
 void digest_update(struct digest_context *ctx, const void *data,
 		   const size_t size);
 void digest_final(struct digest_context *ctx, unsigned char *result);
--- a/src/lib-storage/index/dbox-common/dbox-file-fix.c	Mon Jun 25 00:01:59 2012 +0300
+++ b/src/lib-storage/index/dbox-common/dbox-file-fix.c	Mon Jun 25 01:14:03 2012 +0300
@@ -30,7 +30,7 @@
 	/* \n isn't part of the DBOX_MAGIC_PRE, but it always preceds it.
 	   assume that at this point we've already just read the \n. when
 	   scanning for it later we'll need to find the \n though. */
-	str_find_more(pre_ctx, (const unsigned char *)"\n", 1);
+	(void)str_find_more(pre_ctx, (const unsigned char *)"\n", 1);
 
 	orig_offset = input->v_offset;
 	while ((ret = i_stream_read_data(input, &data, &size, 0)) > 0) {
--- a/src/lib-storage/index/dbox-common/dbox-file.c	Mon Jun 25 00:01:59 2012 +0300
+++ b/src/lib-storage/index/dbox-common/dbox-file.c	Mon Jun 25 01:14:03 2012 +0300
@@ -601,7 +601,10 @@
 				"dbox file size too small");
 			return 0;
 		}
-		o_stream_seek(ctx->output, st.st_size);
+		if (o_stream_seek(ctx->output, st.st_size) < 0) {
+			dbox_file_set_syscall_error(file, "lseek()");
+			return -1;
+		}
 	}
 	*output_r = ctx->output;
 	return 1;
--- a/src/lib-storage/index/dbox-common/dbox-sync-rebuild.c	Mon Jun 25 00:01:59 2012 +0300
+++ b/src/lib-storage/index/dbox-common/dbox-sync-rebuild.c	Mon Jun 25 01:14:03 2012 +0300
@@ -158,7 +158,7 @@
 	ctx->trans = trans;
 	mail_index_reset(ctx->trans);
 	index_mailbox_reset_uidvalidity(box);
-	mail_index_ext_lookup(box->index, "cache", &ctx->cache_ext_id);
+	(void)mail_index_ext_lookup(box->index, "cache", &ctx->cache_ext_id);
 
 	/* open cache and read the caching decisions. we'll reset the cache in
 	   case it contains any invalid data, but we want to preserve the
--- a/src/lib-storage/index/dbox-multi/mdbox-purge.c	Mon Jun 25 00:01:59 2012 +0300
+++ b/src/lib-storage/index/dbox-multi/mdbox-purge.c	Mon Jun 25 01:14:03 2012 +0300
@@ -423,7 +423,8 @@
 	   temporarily vanished */
 	if (ret > 0) {
 		(void)dbox_file_unlink(file);
-		mdbox_map_remove_file_id(ctx->storage->map, file_id);
+		if (mdbox_map_remove_file_id(ctx->storage->map, file_id) < 0)
+			ret = -1;
 	} else {
 		dbox_file_unlock(file);
 	}
@@ -670,7 +671,8 @@
 			if (mdbox_file_purge(ctx, file, file_id) < 0)
 				ret = -1;
 		} else {
-			mdbox_map_remove_file_id(storage->map, file_id);
+			if (mdbox_map_remove_file_id(storage->map, file_id) < 0)
+				ret = -1;
 		}
 		dbox_file_unref(&file);
 	} T_END;
--- a/src/lib-storage/index/dbox-single/sdbox-copy.c	Mon Jun 25 00:01:59 2012 +0300
+++ b/src/lib-storage/index/dbox-single/sdbox-copy.c	Mon Jun 25 01:14:03 2012 +0300
@@ -123,7 +123,7 @@
 	ret = sdbox_file_copy_attachments((struct sdbox_file *)src_file,
 					  (struct sdbox_file *)dest_file);
 	if (ret <= 0) {
-		sdbox_file_unlink_aborted_save((struct sdbox_file *)dest_file);
+		(void)sdbox_file_unlink_aborted_save((struct sdbox_file *)dest_file);
 		dbox_file_unref(&src_file);
 		dbox_file_unref(&dest_file);
 		return ret;
--- a/src/lib-storage/index/imapc/imapc-mail.c	Mon Jun 25 00:01:59 2012 +0300
+++ b/src/lib-storage/index/imapc/imapc-mail.c	Mon Jun 25 01:14:03 2012 +0300
@@ -176,7 +176,8 @@
 	if (data->stream == NULL) {
 		if (!data->initialized) {
 			/* coming here from mail_set_seq() */
-			return mail_set_aborted(_mail);
+			mail_set_aborted(_mail);
+			return -1;
 		}
 		fetch_field = get_body ||
 			(data->access_part & READ_BODY) != 0 ?
--- a/src/lib-storage/index/imapc/imapc-storage.c	Mon Jun 25 00:01:59 2012 +0300
+++ b/src/lib-storage/index/imapc/imapc-storage.c	Mon Jun 25 01:14:03 2012 +0300
@@ -603,7 +603,7 @@
 					      enum mailbox_status_items items,
 					      struct mailbox_status *status_r)
 {
-	index_storage_get_status(&mbox->box, items, status_r);
+	index_storage_get_open_status(&mbox->box, items, status_r);
 	if ((items & STATUS_PERMANENT_FLAGS) != 0)
 		status_r->permanent_flags = mbox->permanent_flags;
 }
--- a/src/lib-storage/index/index-mail.c	Mon Jun 25 00:01:59 2012 +0300
+++ b/src/lib-storage/index/index-mail.c	Mon Jun 25 01:14:03 2012 +0300
@@ -353,7 +353,7 @@
 	struct index_mail_data *data = &mail->data;
 
 	if (data->parts == NULL)
-		get_cached_parts(mail);
+		(void)get_cached_parts(mail);
 
 	if (data->parts != NULL) {
 		data->hdr_size_set = TRUE;
@@ -903,9 +903,14 @@
 				if (index_mail_parse_headers(mail, NULL) < 0)
 					return -1;
 			} else {
-				message_get_header_size(data->stream,
-							&data->hdr_size,
-							&has_nuls);
+				if (message_get_header_size(data->stream,
+							    &data->hdr_size,
+							    &has_nuls) < 0) {
+					mail_storage_set_critical(_mail->box->storage,
+						"read(%s) failed: %m",
+						i_stream_get_name(data->stream));
+					return -1;
+				}
 				data->hdr_size_set = TRUE;
 			}
 		}
@@ -924,9 +929,14 @@
 				if (index_mail_parse_body(mail, 0) < 0)
 					return -1;
 			} else {
-				message_get_body_size(data->stream,
-						      &data->body_size,
-						      &has_nuls);
+				if (message_get_body_size(data->stream,
+							  &data->body_size,
+							  &has_nuls) < 0) {
+					mail_storage_set_critical(_mail->box->storage,
+						"read(%s) failed: %m",
+						i_stream_get_name(data->stream));
+					return -1;
+				}
 				data->body_size_set = TRUE;
 			}
 		}
--- a/src/lib-storage/index/index-search.c	Mon Jun 25 00:01:59 2012 +0300
+++ b/src/lib-storage/index/index-search.c	Mon Jun 25 01:14:03 2012 +0300
@@ -548,7 +548,8 @@
 {
 	if (hdr == NULL) {
 		/* end of headers, mark all unknown SEARCH_HEADERs unmatched */
-		mail_search_args_foreach(ctx->args, search_header_unmatch, ctx);
+		(void)mail_search_args_foreach(ctx->args, search_header_unmatch,
+					       ctx);
 		return;
 	}
 
@@ -562,7 +563,7 @@
 		ctx->hdr = hdr;
 
 		ctx->custom_header = FALSE;
-		mail_search_args_foreach(ctx->args, search_header_arg, ctx);
+		(void)mail_search_args_foreach(ctx->args, search_header_arg, ctx);
 	}
 }
 
@@ -859,8 +860,8 @@
 	if (uid_lowwater == 0)
 		return;
 
-	mail_index_lookup_seq_range(ctx->view, uid_lowwater, (uint32_t)-1,
-				    &seq1, &seq2);
+	(void)mail_index_lookup_seq_range(ctx->view, uid_lowwater, (uint32_t)-1,
+					  &seq1, &seq2);
 	if (*first_seq < seq1)
 		*first_seq = seq1;
 }
--- a/src/lib-storage/index/index-sort-string.c	Mon Jun 25 00:01:59 2012 +0300
+++ b/src/lib-storage/index/index-sort-string.c	Mon Jun 25 01:14:03 2012 +0300
@@ -275,8 +275,8 @@
 		i_assert(nodes[i].seq <= ctx->last_seq);
 
 		T_BEGIN {
-			index_sort_header_get(mail, nodes[i].seq,
-					      sort_type, str);
+			(void)index_sort_header_get(mail, nodes[i].seq,
+						    sort_type, str);
 			ctx->sort_strings[nodes[i].seq] =
 				str_len(str) == 0 ? "" :
 				p_strdup(pool, str_c(str));
--- a/src/lib-storage/index/index-sort.c	Mon Jun 25 00:01:59 2012 +0300
+++ b/src/lib-storage/index/index-sort.c	Mon Jun 25 01:14:03 2012 +0300
@@ -470,8 +470,8 @@
 
 			str1 = t_str_new(256);
 			str2 = t_str_new(256);
-			index_sort_header_get(mail, seq1, sort_type, str1);
-			index_sort_header_get(mail, seq2, sort_type, str2);
+			(void)index_sort_header_get(mail, seq1, sort_type, str1);
+			(void)index_sort_header_get(mail, seq2, sort_type, str2);
 
 			ret = strcmp(str_c(str1), str_c(str2));
 		} T_END;
--- a/src/lib-storage/index/index-status.c	Mon Jun 25 00:01:59 2012 +0300
+++ b/src/lib-storage/index/index-status.c	Mon Jun 25 01:14:03 2012 +0300
@@ -33,16 +33,23 @@
 			     enum mailbox_status_items items,
 			     struct mailbox_status *status_r)
 {
-	const struct mail_index_header *hdr, *hdr_pvt;
-
-	memset(status_r, 0, sizeof(struct mailbox_status));
-
 	if (!box->opened) {
 		if (mailbox_open(box) < 0)
 			return -1;
 		if (mailbox_sync(box, 0) < 0)
 			return -1;
 	}
+	index_storage_get_open_status(box, items, status_r);
+	return 0;
+}
+
+void index_storage_get_open_status(struct mailbox *box,
+				   enum mailbox_status_items items,
+				   struct mailbox_status *status_r)
+{
+	const struct mail_index_header *hdr, *hdr_pvt;
+
+	memset(status_r, 0, sizeof(struct mailbox_status));
 
 	/* we can get most of the status items without any trouble */
 	hdr = mail_index_get_header(box->view);
@@ -96,7 +103,6 @@
 				!box->disallow_new_keywords;
 		}
 	}
-	return 0;
 }
 
 static void
--- a/src/lib-storage/index/index-storage.h	Mon Jun 25 00:01:59 2012 +0300
+++ b/src/lib-storage/index/index-storage.h	Mon Jun 25 01:14:03 2012 +0300
@@ -109,6 +109,9 @@
 int index_storage_get_status(struct mailbox *box,
 			     enum mailbox_status_items items,
 			     struct mailbox_status *status_r);
+void index_storage_get_open_status(struct mailbox *box,
+				   enum mailbox_status_items items,
+				   struct mailbox_status *status_r);
 int index_mailbox_get_metadata(struct mailbox *box,
 			       enum mailbox_metadata_items items,
 			       struct mailbox_metadata *metadata_r);
--- a/src/lib-storage/index/index-sync-changes.c	Mon Jun 25 00:01:59 2012 +0300
+++ b/src/lib-storage/index/index-sync-changes.c	Mon Jun 25 01:14:03 2012 +0300
@@ -131,10 +131,10 @@
 				break;
 
 			/* mark the changes as dirty */
-			mail_index_lookup_seq_range(ctx->sync_view,
-						    sync_rec->uid1,
-						    sync_rec->uid2,
-						    &seq1, &seq2);
+			(void)mail_index_lookup_seq_range(ctx->sync_view,
+							  sync_rec->uid1,
+							  sync_rec->uid2,
+							  &seq1, &seq2);
 			memset(sync_rec, 0, sizeof(*sync_rec));
 
 			if (seq1 == 0)
--- a/src/lib-storage/index/index-sync.c	Mon Jun 25 00:01:59 2012 +0300
+++ b/src/lib-storage/index/index-sync.c	Mon Jun 25 01:14:03 2012 +0300
@@ -305,15 +305,15 @@
 			continue;
 
 		ibox->recent_flags_count -=
-			seq_range_array_remove_range(&ibox->recent_flags,
-						     start_uid + 1, uid - 1);
+			seq_range_array_remove_range_count(&ibox->recent_flags,
+							   start_uid + 1, uid - 1);
 	}
 
 	if (uid + 1 < hdr->next_uid) {
 		ibox->recent_flags_count -=
-			seq_range_array_remove_range(&ibox->recent_flags,
-						     uid + 1,
-						     hdr->next_uid - 1);
+			seq_range_array_remove_range_count(&ibox->recent_flags,
+							   uid + 1,
+							   hdr->next_uid - 1);
 	}
 #ifdef DEBUG
 	if (!mail_index_view_is_inconsistent(view)) {
@@ -325,7 +325,7 @@
 			for (uid = range[i].seq1; uid <= range[i].seq2; uid++) {
 				if (uid >= hdr->next_uid)
 					break;
-				mail_index_lookup_seq(view, uid, &seq);
+				(void)mail_index_lookup_seq(view, uid, &seq);
 				i_assert(seq != 0);
 			}
 		}
@@ -341,11 +341,10 @@
 
 	hdr = mail_index_get_header(box->view);
 	if (hdr->first_recent_uid > ibox->recent_flags_prev_uid) {
-		mail_index_lookup_seq_range(box->view,
-					    hdr->first_recent_uid,
-					    hdr->next_uid,
-					    &seq1, &seq2);
-		if (seq1 != 0) {
+		if (mail_index_lookup_seq_range(box->view,
+						hdr->first_recent_uid,
+						hdr->next_uid,
+						&seq1, &seq2)) {
 			index_mailbox_set_recent_seq(box, box->view,
 						     seq1, seq2);
 		}
--- a/src/lib-storage/index/index-thread.c	Mon Jun 25 00:01:59 2012 +0300
+++ b/src/lib-storage/index/index-thread.c	Mon Jun 25 01:14:03 2012 +0300
@@ -387,8 +387,9 @@
 	uids = array_get(&removed_uids, &uid_count);
 	for (i = j = 0; i < uid_count; i++) {
 		/* find and remove from the map */
-		bsearch_insert_pos(&uids[i].seq1, &msgid_map[j], map_count - j,
-				   sizeof(*msgid_map), msgid_map_cmp, &idx);
+		(void)bsearch_insert_pos(&uids[i].seq1, &msgid_map[j],
+					 map_count - j, sizeof(*msgid_map),
+					 msgid_map_cmp, &idx);
 		j += idx;
 		if (j == map_count) {
 			/* all removals after this are about messages we never
--- a/src/lib-storage/index/maildir/maildir-uidlist.c	Mon Jun 25 00:01:59 2012 +0300
+++ b/src/lib-storage/index/maildir/maildir-uidlist.c	Mon Jun 25 01:14:03 2012 +0300
@@ -328,7 +328,7 @@
 	i_assert(!UIDLIST_IS_LOCKED(uidlist));
 
 	*_uidlist = NULL;
-	maildir_uidlist_update(uidlist);
+	(void)maildir_uidlist_update(uidlist);
 	maildir_uidlist_close(uidlist);
 
 	hash_table_destroy(&uidlist->files);
@@ -553,7 +553,7 @@
 		if (uidlist->retry_rewind)
 			return FALSE;
 		/* Delete the old UID */
-		maildir_uidlist_records_array_delete(uidlist, old_rec);
+		(void)maildir_uidlist_records_array_delete(uidlist, old_rec);
 		/* Replace the old record with this new one */
 		*old_rec = *rec;
 		rec = old_rec;
@@ -1336,7 +1336,7 @@
 	if (!uidlist->box->opened)
 		return;
 
-	mail_index_refresh(uidlist->box->index);
+	(void)mail_index_refresh(uidlist->box->index);
 	view = mail_index_view_open(uidlist->box->index);
 	count = array_count(&uidlist->records);
 	hdr = mail_index_get_header(view);
--- a/src/lib-storage/index/mbox/istream-raw-mbox.c	Mon Jun 25 00:01:59 2012 +0300
+++ b/src/lib-storage/index/mbox/istream-raw-mbox.c	Mon Jun 25 01:14:03 2012 +0300
@@ -537,7 +537,7 @@
 	offset = stream->v_offset;
 	i_stream_seek(stream, rstream->hdr_offset);
 	while (rstream->body_offset == (uoff_t)-1) {
-		i_stream_get_data(stream, &pos);
+		(void)i_stream_get_data(stream, &pos);
 		i_stream_skip(stream, pos);
 
 		if (i_stream_raw_mbox_read(&rstream->istream) < 0) {
--- a/src/lib-storage/index/mbox/mbox-mail.c	Mon Jun 25 00:01:59 2012 +0300
+++ b/src/lib-storage/index/mbox/mbox-mail.c	Mon Jun 25 01:14:03 2012 +0300
@@ -43,8 +43,10 @@
 	if (_mail->expunged || mbox->syncing)
 		return -1;
 
-	if (_mail->lookup_abort != MAIL_LOOKUP_ABORT_NEVER)
-		return mail_set_aborted(_mail);
+	if (_mail->lookup_abort != MAIL_LOOKUP_ABORT_NEVER) {
+		mail_set_aborted(_mail);
+		return -1;
+	}
 
 	if (mbox->mbox_stream != NULL &&
 	    istream_raw_mbox_is_corrupted(mbox->mbox_stream)) {
--- a/src/lib-storage/index/mbox/mbox-save.c	Mon Jun 25 00:01:59 2012 +0300
+++ b/src/lib-storage/index/mbox/mbox-save.c	Mon Jun 25 01:14:03 2012 +0300
@@ -58,11 +58,10 @@
 	unsigned int finished:1;
 };
 
-static int write_error(struct mbox_save_context *ctx)
+static void write_error(struct mbox_save_context *ctx)
 {
 	mbox_set_syscall_error(ctx->mbox, "write()");
 	ctx->failed = TRUE;
-	return -1;
 }
 
 static int mbox_seek_to_end(struct mbox_save_context *ctx, uoff_t *offset)
@@ -77,8 +76,10 @@
 	}
 
 	fd = ctx->mbox->mbox_fd;
-	if (fstat(fd, &st) < 0)
-                return mbox_set_syscall_error(ctx->mbox, "fstat()");
+	if (fstat(fd, &st) < 0) {
+		mbox_set_syscall_error(ctx->mbox, "fstat()");
+		return -1;
+	}
 
 	ctx->orig_atime = st.st_atime;
 
@@ -86,15 +87,21 @@
 	if (st.st_size == 0)
 		return 0;
 
-	if (lseek(fd, st.st_size-1, SEEK_SET) < 0)
-                return mbox_set_syscall_error(ctx->mbox, "lseek()");
+	if (lseek(fd, st.st_size-1, SEEK_SET) < 0) {
+                mbox_set_syscall_error(ctx->mbox, "lseek()");
+		return -1;
+	}
 
-	if (read(fd, &ch, 1) != 1)
-		return mbox_set_syscall_error(ctx->mbox, "read()");
+	if (read(fd, &ch, 1) != 1) {
+		mbox_set_syscall_error(ctx->mbox, "read()");
+		return -1;
+	}
 
 	if (ch != '\n') {
-		if (write_full(fd, "\n", 1) < 0)
-			return write_error(ctx);
+		if (write_full(fd, "\n", 1) < 0) {
+			write_error(ctx);
+			return -1;
+		}
 		*offset += 1;
 	}
 
@@ -103,8 +110,10 @@
 
 static int mbox_append_lf(struct mbox_save_context *ctx)
 {
-	if (o_stream_send(ctx->output, "\n", 1) < 0)
-		return write_error(ctx);
+	if (o_stream_send(ctx->output, "\n", 1) < 0) {
+		write_error(ctx);
+		return -1;
+	}
 
 	return 0;
 }
@@ -162,18 +171,26 @@
 
 	/* flush manually here so that we don't confuse seek() errors with
 	   buffer flushing errors */
-	if (o_stream_flush(ctx->output) < 0)
-		return write_error(ctx);
+	if (o_stream_flush(ctx->output) < 0) {
+		write_error(ctx);
+		return -1;
+	}
 	if (o_stream_seek(ctx->output, ctx->extra_hdr_offset +
-			  ctx->space_end_idx - len) < 0)
-		return mbox_set_syscall_error(ctx->mbox, "o_stream_seek()");
+			  ctx->space_end_idx - len) < 0) {
+		mbox_set_syscall_error(ctx->mbox, "lseek()");
+		return -1;
+	}
 
 	if (o_stream_send(ctx->output, str, len) < 0 ||
-	    o_stream_flush(ctx->output) < 0)
-		return write_error(ctx);
+	    o_stream_flush(ctx->output) < 0) {
+		write_error(ctx);
+		return -1;
+	}
 
-	if (o_stream_seek(ctx->output, end_offset) < 0)
-		return mbox_set_syscall_error(ctx->mbox, "o_stream_seek()");
+	if (o_stream_seek(ctx->output, end_offset) < 0) {
+		mbox_set_syscall_error(ctx->mbox, "lseek()");
+		return -1;
+	}
 	return 0;
 }
 
@@ -528,8 +545,10 @@
 
 	data = i_stream_get_data(ctx->input, &size);
 	if (size > 0) {
-		if (o_stream_send(ctx->output, data, size) < 0)
-			return write_error(ctx);
+		if (o_stream_send(ctx->output, data, size) < 0) {
+			write_error(ctx);
+			return -1;
+		}
 		ctx->last_char = data[size-1];
 		i_stream_skip(ctx->input, size);
 	}
@@ -564,8 +583,10 @@
 	/* append our own headers and ending empty line */
 	ctx->extra_hdr_offset = ctx->output->offset;
 	if (o_stream_send(ctx->output, str_data(ctx->headers),
-			  str_len(ctx->headers)) < 0)
-		return write_error(ctx);
+			  str_len(ctx->headers)) < 0) {
+		write_error(ctx);
+		return -1;
+	}
 	ctx->eoh_offset = ctx->output->offset;
 	return 0;
 }
@@ -602,15 +623,19 @@
 		if (i != size) {
 			/* found end of headers. write the rest of them
 			   (not including the finishing empty line) */
-			if (o_stream_send(ctx->output, data, i) < 0)
-				return write_error(ctx);
+			if (o_stream_send(ctx->output, data, i) < 0) {
+				write_error(ctx);
+				return -1;
+			}
 			ctx->last_char = '\n';
 			i_stream_skip(ctx->input, i + 1);
 			break;
 		}
 
-		if (o_stream_send(ctx->output, data, size) < 0)
-			return write_error(ctx);
+		if (o_stream_send(ctx->output, data, size) < 0) {
+			write_error(ctx);
+			return -1;
+		}
 		ctx->last_char = data[size-1];
 		i_stream_skip(ctx->input, size);
 	}
@@ -687,7 +712,7 @@
 		(void)o_stream_nfinish(ctx->output);
 		if (ftruncate(ctx->mbox->mbox_fd, (off_t)ctx->mail_offset) < 0)
 			mbox_set_syscall_error(ctx->mbox, "ftruncate()");
-		o_stream_seek(ctx->output, ctx->mail_offset);
+		(void)o_stream_seek(ctx->output, ctx->mail_offset);
 		ctx->mail_offset = (uoff_t)-1;
 	}
 
--- a/src/lib-storage/index/mbox/mbox-storage.c	Mon Jun 25 00:01:59 2012 +0300
+++ b/src/lib-storage/index/mbox/mbox-storage.c	Mon Jun 25 01:14:03 2012 +0300
@@ -68,7 +68,7 @@
 static MODULE_CONTEXT_DEFINE_INIT(mbox_mailbox_list_module,
 				  &mailbox_list_module_register);
 
-int mbox_set_syscall_error(struct mbox_mailbox *mbox, const char *function)
+void mbox_set_syscall_error(struct mbox_mailbox *mbox, const char *function)
 {
 	i_assert(function != NULL);
 
@@ -82,7 +82,6 @@
 			"%s failed with mbox file %s: %m%s", function,
 			mailbox_get_path(&mbox->box), toobig_error);
 	}
-	return -1;
 }
 
 static const char *
--- a/src/lib-storage/index/mbox/mbox-storage.h	Mon Jun 25 00:01:59 2012 +0300
+++ b/src/lib-storage/index/mbox/mbox-storage.h	Mon Jun 25 01:14:03 2012 +0300
@@ -76,7 +76,7 @@
 extern const char *mbox_hide_headers[], *mbox_save_drop_headers[];
 extern unsigned int mbox_hide_headers_count, mbox_save_drop_headers_count;
 
-int mbox_set_syscall_error(struct mbox_mailbox *mbox, const char *function);
+void mbox_set_syscall_error(struct mbox_mailbox *mbox, const char *function);
 
 struct mailbox_sync_context *
 mbox_storage_sync_init(struct mailbox *box, enum mailbox_sync_flags flags);
--- a/src/lib-storage/index/mbox/mbox-sync.c	Mon Jun 25 00:01:59 2012 +0300
+++ b/src/lib-storage/index/mbox/mbox-sync.c	Mon Jun 25 01:14:03 2012 +0300
@@ -1687,9 +1687,8 @@
 		mbox_sync_index_update_ext_header(mbox, trans);
 		ret = mail_index_transaction_commit(&trans);
 	}
-	mbox_unlock(mbox, lock_id);
+	(void)mbox_unlock(mbox, lock_id);
 	return ret;
-
 }
 
 int mbox_sync_has_changed(struct mbox_mailbox *mbox, bool leave_dirty)
--- a/src/lib-storage/index/pop3c/pop3c-client.c	Mon Jun 25 00:01:59 2012 +0300
+++ b/src/lib-storage/index/pop3c/pop3c-client.c	Mon Jun 25 01:14:03 2012 +0300
@@ -170,7 +170,7 @@
 static void pop3c_client_ioloop_changed(struct pop3c_client *client)
 {
 	if (client->to != NULL)
-		io_loop_move_timeout(&client->to);
+		client->to = io_loop_move_timeout(&client->to);
 	if (client->io != NULL)
 		client->io = io_loop_move_io(&client->io);
 	if (client->output != NULL)
--- a/src/lib-storage/index/raw/raw-mail.c	Mon Jun 25 00:01:59 2012 +0300
+++ b/src/lib-storage/index/raw/raw-mail.c	Mon Jun 25 01:14:03 2012 +0300
@@ -14,8 +14,10 @@
 	struct raw_mailbox *mbox = (struct raw_mailbox *)mail->box;
 	const struct stat *st;
 
-	if (mail->lookup_abort == MAIL_LOOKUP_ABORT_NOT_IN_CACHE)
-		return mail_set_aborted(mail);
+	if (mail->lookup_abort == MAIL_LOOKUP_ABORT_NOT_IN_CACHE) {
+		mail_set_aborted(mail);
+		return -1;
+	}
 
 	mail->transaction->stats.fstat_lookup_count++;
 	st = i_stream_stat(mail->box->input, TRUE);
--- a/src/lib-storage/mail-search-build.c	Mon Jun 25 00:01:59 2012 +0300
+++ b/src/lib-storage/mail-search-build.c	Mon Jun 25 01:14:03 2012 +0300
@@ -207,7 +207,7 @@
 
 void mail_search_build_add_all(struct mail_search_args *args)
 {
-	mail_search_build_add(args, SEARCH_ALL);
+	(void)mail_search_build_add(args, SEARCH_ALL);
 }
 
 void mail_search_build_add_seqset(struct mail_search_args *args,
--- a/src/lib-storage/mail-storage-private.h	Mon Jun 25 00:01:59 2012 +0300
+++ b/src/lib-storage/mail-storage-private.h	Mon Jun 25 01:14:03 2012 +0300
@@ -526,7 +526,7 @@
 
 /* Returns TRUE if everything should already be in memory after this call. */
 bool mail_prefetch(struct mail *mail);
-int mail_set_aborted(struct mail *mail);
+void mail_set_aborted(struct mail *mail);
 void mail_set_expunged(struct mail *mail);
 void mail_set_seq_saving(struct mail *mail, uint32_t seq);
 void mailbox_set_deleted(struct mailbox *box);
--- a/src/lib-storage/mail.c	Mon Jun 25 00:01:59 2012 +0300
+++ b/src/lib-storage/mail.c	Mon Jun 25 01:14:03 2012 +0300
@@ -183,11 +183,10 @@
 	return p->v.get_header_stream(mail, headers, stream_r);
 }
 
-int mail_set_aborted(struct mail *mail)
+void mail_set_aborted(struct mail *mail)
 {
 	mail_storage_set_error(mail->box->storage, MAIL_ERROR_NOTPOSSIBLE,
 			       "Mail field not cached");
-	return -1;
 }
 
 int mail_get_stream(struct mail *mail, struct message_size *hdr_size,
@@ -195,8 +194,10 @@
 {
 	struct mail_private *p = (struct mail_private *)mail;
 
-	if (mail->lookup_abort != MAIL_LOOKUP_ABORT_NEVER)
-		return mail_set_aborted(mail);
+	if (mail->lookup_abort != MAIL_LOOKUP_ABORT_NEVER) {
+		mail_set_aborted(mail);
+		return -1;
+	}
 	return p->v.get_stream(mail, TRUE, hdr_size, body_size, stream_r);
 }
 
@@ -205,8 +206,10 @@
 {
 	struct mail_private *p = (struct mail_private *)mail;
 
-	if (mail->lookup_abort != MAIL_LOOKUP_ABORT_NEVER)
-		return mail_set_aborted(mail);
+	if (mail->lookup_abort != MAIL_LOOKUP_ABORT_NEVER) {
+		mail_set_aborted(mail);
+		return -1;
+	}
 	return p->v.get_stream(mail, FALSE, hdr_size, NULL, stream_r);
 }
 
--- a/src/lib-storage/mailbox-get.c	Mon Jun 25 00:01:59 2012 +0300
+++ b/src/lib-storage/mailbox-get.c	Mon Jun 25 01:14:03 2012 +0300
@@ -8,7 +8,7 @@
 void mailbox_get_seq_range(struct mailbox *box, uint32_t uid1, uint32_t uid2,
 			   uint32_t *seq1_r, uint32_t *seq2_r)
 {
-	mail_index_lookup_seq_range(box->view, uid1, uid2, seq1_r, seq2_r);
+	(void)mail_index_lookup_seq_range(box->view, uid1, uid2, seq1_r, seq2_r);
 }
 
 void mailbox_get_uid_range(struct mailbox *box,
--- a/src/lib-storage/mailbox-uidvalidity.c	Mon Jun 25 00:01:59 2012 +0300
+++ b/src/lib-storage/mailbox-uidvalidity.c	Mon Jun 25 01:14:03 2012 +0300
@@ -61,7 +61,8 @@
 		}
 	}
 
-	i_snprintf(buf, sizeof(buf), "%08x", uid_validity);
+	if (i_snprintf(buf, sizeof(buf), "%08x", uid_validity) < 0)
+		i_unreached();
 	if (pwrite_full(fd, buf, strlen(buf), 0) < 0)
 		i_error("write(%s) failed: %m", path);
 	if (close(fd) < 0)
@@ -217,7 +218,8 @@
 
 	/* fast path succeeded. write the current value to the main
 	   uidvalidity file. */
-	i_snprintf(buf, sizeof(buf), "%08x", cur_value);
+	if (i_snprintf(buf, sizeof(buf), "%08x", cur_value) < 0)
+		i_unreached();
 	if (pwrite_full(fd, buf, strlen(buf), 0) < 0)
 		i_error("write(%s) failed: %m", path);
 	if (close(fd) < 0)
--- a/src/lib/data-stack.c	Mon Jun 25 00:01:59 2012 +0300
+++ b/src/lib/data-stack.c	Mon Jun 25 01:14:03 2012 +0300
@@ -476,13 +476,13 @@
 	i_assert(current_block->left >= size);
 
 	/* we've already reserved the space, now we just mark it used */
-	t_malloc_real(size, TRUE);
+	(void)t_malloc_real(size, TRUE);
 }
 
 void t_buffer_alloc_last_full(void)
 {
 	if (last_buffer_block != NULL)
-		t_malloc_real(last_buffer_size, TRUE);
+		(void)t_malloc_real(last_buffer_size, TRUE);
 }
 
 void data_stack_set_clean_after_pop(bool enable ATTR_UNUSED)
@@ -515,12 +515,12 @@
 	last_buffer_block = NULL;
 	last_buffer_size = 0;
 
-	t_push();
+	(void)t_push();
 }
 
 void data_stack_deinit(void)
 {
-	t_pop();
+	(void)t_pop();
 
 	if (frame_pos != BLOCK_FRAME_COUNT-1)
 		i_panic("Missing t_pop() call");
--- a/src/lib/hash.c	Mon Jun 25 00:01:59 2012 +0300
+++ b/src/lib/hash.c	Mon Jun 25 01:14:03 2012 +0300
@@ -438,16 +438,16 @@
 	for (i = 0; i < old_size; i++) {
 		node = &old_nodes[i];
 		if (node->key != NULL) {
-			hash_table_insert_node(table, node->key,
-					       node->value, FALSE);
+			(void)hash_table_insert_node(table, node->key,
+						     node->value, FALSE);
 		}
 
 		for (node = node->next; node != NULL; node = next) {
 			next = node->next;
 
 			if (node->key != NULL) {
-				hash_table_insert_node(table, node->key,
-						       node->value, FALSE);
+				(void)hash_table_insert_node(table, node->key,
+							     node->value, FALSE);
 			}
 			free_node(table, node);
 		}
--- a/src/lib/hostpid.c	Mon Jun 25 00:01:59 2012 +0300
+++ b/src/lib/hostpid.c	Mon Jun 25 01:14:03 2012 +0300
@@ -15,8 +15,10 @@
 {
 	static char hostname[256], pid[MAX_INT_STRLEN];
 
-	if (gethostname(hostname, sizeof(hostname)-1) == -1)
-		i_strocpy(hostname, "unknown", sizeof(hostname));
+	if (gethostname(hostname, sizeof(hostname)-1) == -1) {
+		if (i_strocpy(hostname, "unknown", sizeof(hostname)) < 0)
+			i_unreached();
+	}
 	hostname[sizeof(hostname)-1] = '\0';
 	my_hostname = hostname;
 
@@ -26,7 +28,8 @@
 	/* allow calling hostpid_init() multiple times to reset hostname */
 	i_free_and_null(my_domain);
 
-	i_strocpy(pid, dec2str(getpid()), sizeof(pid));
+	if (i_strocpy(pid, dec2str(getpid()), sizeof(pid)) < 0)
+		i_unreached();
 	my_pid = pid;
 }
 
--- a/src/lib/iostream-rawlog.c	Mon Jun 25 00:01:59 2012 +0300
+++ b/src/lib/iostream-rawlog.c	Mon Jun 25 01:14:03 2012 +0300
@@ -33,9 +33,10 @@
 {
 	char buf[MAX_INT_STRLEN + 6 + 2];
 
-	i_snprintf(buf, sizeof(buf), "%lu.%06u ",
-		   (unsigned long)ioloop_timeval.tv_sec,
-		   (unsigned int)ioloop_timeval.tv_usec);
+	if (i_snprintf(buf, sizeof(buf), "%lu.%06u ",
+		       (unsigned long)ioloop_timeval.tv_sec,
+		       (unsigned int)ioloop_timeval.tv_usec) < 0)
+		i_unreached();
 	rawlog_write(rstream, buf, strlen(buf));
 }
 
--- a/src/lib/md4.c	Mon Jun 25 00:01:59 2012 +0300
+++ b/src/lib/md4.c	Mon Jun 25 01:14:03 2012 +0300
@@ -193,7 +193,7 @@
 		memcpy(&ctx->buffer[used], data, free);
 		data = (const unsigned char *) data + free;
 		size -= free;
-		body(ctx, ctx->buffer, 64);
+		(void)body(ctx, ctx->buffer, 64);
 	}
 
 	if (size >= 64) {
@@ -217,7 +217,7 @@
 
 	if (free < 8) {
 		memset(&ctx->buffer[used], 0, free);
-		body(ctx, ctx->buffer, 64);
+		(void)body(ctx, ctx->buffer, 64);
 		used = 0;
 		free = 64;
 	}
@@ -234,7 +234,7 @@
 	ctx->buffer[62] = ctx->hi >> 16;
 	ctx->buffer[63] = ctx->hi >> 24;
 
-	body(ctx, ctx->buffer, 64);
+	(void)body(ctx, ctx->buffer, 64);
 
 	result[0] = ctx->a;
 	result[1] = ctx->a >> 8;
--- a/src/lib/md5.c	Mon Jun 25 00:01:59 2012 +0300
+++ b/src/lib/md5.c	Mon Jun 25 01:14:03 2012 +0300
@@ -208,7 +208,7 @@
 		memcpy(&ctx->buffer[used], data, free);
 		data = (const unsigned char *) data + free;
 		size -= free;
-		body(ctx, ctx->buffer, 64);
+		(void)body(ctx, ctx->buffer, 64);
 	}
 
 	if (size >= 64) {
@@ -232,7 +232,7 @@
 
 	if (free < 8) {
 		memset(&ctx->buffer[used], 0, free);
-		body(ctx, ctx->buffer, 64);
+		(void)body(ctx, ctx->buffer, 64);
 		used = 0;
 		free = 64;
 	}
@@ -249,7 +249,7 @@
 	ctx->buffer[62] = ctx->hi >> 16;
 	ctx->buffer[63] = ctx->hi >> 24;
 
-	body(ctx, ctx->buffer, 64);
+	(void)body(ctx, ctx->buffer, 64);
 
 	result[0] = ctx->a;
 	result[1] = ctx->a >> 8;
--- a/src/lib/mountpoint.c	Mon Jun 25 00:01:59 2012 +0300
+++ b/src/lib/mountpoint.c	Mon Jun 25 01:14:03 2012 +0300
@@ -123,7 +123,8 @@
                 point_r->dev = mnt->dev;
                 point_r->block_size = st.st_blksize;
         }
-	mountpoint_iter_deinit(&iter);
+	if (mountpoint_iter_deinit(&iter) < 0 && mnt == NULL)
+		return -1;
         return mnt != NULL ? 1 : 0;
 #endif
 }
--- a/src/lib/nfs-workarounds.c	Mon Jun 25 00:01:59 2012 +0300
+++ b/src/lib/nfs-workarounds.c	Mon Jun 25 01:14:03 2012 +0300
@@ -274,16 +274,15 @@
 	nfs_flush_chown_uid(path);
 }
 
-bool nfs_flush_attr_cache_fd_locked(const char *path ATTR_UNUSED,
+void nfs_flush_attr_cache_fd_locked(const char *path ATTR_UNUSED,
 				    int fd ATTR_UNUSED)
 {
 #ifdef __FreeBSD__
 	/* FreeBSD doesn't flush attribute cache with fcntl(), so we have
 	   to do it ourself. */
-	return nfs_flush_fchown_uid(path, fd);
+	(void)nfs_flush_fchown_uid(path, fd);
 #else
 	/* Linux and Solaris are fine. */
-	return TRUE;
 #endif
 }
 
@@ -359,10 +358,10 @@
 	p = strrchr(path, '/');
 	T_BEGIN {
 		if (p == NULL)
-			nfs_flush_file_handle_cache_dir(".", TRUE);
+			(void)nfs_flush_file_handle_cache_dir(".", TRUE);
 		else
-			nfs_flush_file_handle_cache_dir(t_strdup_until(path, p),
-							TRUE);
+			(void)nfs_flush_file_handle_cache_dir(t_strdup_until(path, p),
+							      TRUE);
 	} T_END;
 }
 
--- a/src/lib/nfs-workarounds.h	Mon Jun 25 00:01:59 2012 +0300
+++ b/src/lib/nfs-workarounds.h	Mon Jun 25 01:14:03 2012 +0300
@@ -27,7 +27,7 @@
 /* Flush attribute cache for a fcntl locked file descriptor. If locking flushes
    the attribute cache with the running OS, this function does nothing.
    The given path is used only for logging. */
-bool nfs_flush_attr_cache_fd_locked(const char *path, int fd);
+void nfs_flush_attr_cache_fd_locked(const char *path, int fd);
 /* Flush file handle cache for given file. */
 void nfs_flush_file_handle_cache(const char *path);
 
--- a/src/lib/seq-range-array.c	Mon Jun 25 00:01:59 2012 +0300
+++ b/src/lib/seq-range-array.c	Mon Jun 25 01:14:03 2012 +0300
@@ -243,8 +243,20 @@
 	return FALSE;
 }
 
-unsigned int seq_range_array_remove_range(ARRAY_TYPE(seq_range) *array,
-					  uint32_t seq1, uint32_t seq2)
+void seq_range_array_remove_range(ARRAY_TYPE(seq_range) *array,
+				  uint32_t seq1, uint32_t seq2)
+{
+	(void)seq_range_array_remove_range_count(array, seq1, seq2);
+}
+
+void seq_range_array_remove_seq_range(ARRAY_TYPE(seq_range) *dest,
+				      const ARRAY_TYPE(seq_range) *src)
+{
+	(void)seq_range_array_remove_seq_range_count(dest, src);
+}
+
+unsigned int seq_range_array_remove_range_count(ARRAY_TYPE(seq_range) *array,
+						uint32_t seq1, uint32_t seq2)
 {
 	const struct seq_range *data;
 	unsigned int idx, idx2, count, remove_count = 0;
@@ -282,22 +294,22 @@
 	return remove_count;
 }
 
-unsigned int seq_range_array_remove_seq_range(ARRAY_TYPE(seq_range) *dest,
-					      const ARRAY_TYPE(seq_range) *src)
+unsigned int
+seq_range_array_remove_seq_range_count(ARRAY_TYPE(seq_range) *dest,
+				       const ARRAY_TYPE(seq_range) *src)
 {
 	unsigned int ret = 0;
 	const struct seq_range *src_range;
 
 	array_foreach(src, src_range) {
-		ret += seq_range_array_remove_range(dest, src_range->seq1,
-						    src_range->seq2);
+		ret += seq_range_array_remove_range_count(dest, src_range->seq1,
+							  src_range->seq2);
 	}
 	return ret;
 }
 
-unsigned int
-seq_range_array_intersect(ARRAY_TYPE(seq_range) *dest,
-			  const ARRAY_TYPE(seq_range) *src)
+void seq_range_array_intersect(ARRAY_TYPE(seq_range) *dest,
+			       const ARRAY_TYPE(seq_range) *src)
 {
 	const struct seq_range *src_range;
 	unsigned int i, count, ret = 0;
@@ -306,16 +318,15 @@
 	src_range = array_get(src, &count);
 	for (i = 0; i < count; i++) {
 		if (last_seq + 1 < src_range[i].seq1) {
-			ret += seq_range_array_remove_range(dest, last_seq + 1,
-							src_range[i].seq1 - 1);
+			ret += seq_range_array_remove_range_count(dest,
+					last_seq + 1, src_range[i].seq1 - 1);
 		}
 		last_seq = src_range[i].seq2;
 	}
 	if (last_seq != (uint32_t)-1) {
-		ret += seq_range_array_remove_range(dest, last_seq + 1,
-						    (uint32_t)-1);
+		ret += seq_range_array_remove_range_count(dest, last_seq + 1,
+							  (uint32_t)-1);
 	}
-	return ret;
 }
 
 bool seq_range_exists(const ARRAY_TYPE(seq_range) *array, uint32_t seq)
--- a/src/lib/seq-range-array.h	Mon Jun 25 00:01:59 2012 +0300
+++ b/src/lib/seq-range-array.h	Mon Jun 25 01:14:03 2012 +0300
@@ -29,16 +29,20 @@
 void seq_range_array_remove(ARRAY_TYPE(seq_range) *array, uint32_t seq);
 /* Remove the given sequrence from range. Returns TRUE if it was found. */
 bool seq_range_array_try_remove(ARRAY_TYPE(seq_range) *array, uint32_t seq);
+/* Remove a sequence range. */
+void seq_range_array_remove_range(ARRAY_TYPE(seq_range) *array,
+				  uint32_t seq1, uint32_t seq2);
+void seq_range_array_remove_seq_range(ARRAY_TYPE(seq_range) *dest,
+				      const ARRAY_TYPE(seq_range) *src);
 /* Remove a sequence range. Returns number of sequences actually removed. */
-unsigned int seq_range_array_remove_range(ARRAY_TYPE(seq_range) *array,
-					  uint32_t seq1, uint32_t seq2);
-unsigned int seq_range_array_remove_seq_range(ARRAY_TYPE(seq_range) *dest,
-					      const ARRAY_TYPE(seq_range) *src);
-/* Remove sequences from dest that don't exist in src.
-   Returns the number of sequences actually removed. */
+unsigned int seq_range_array_remove_range_count(ARRAY_TYPE(seq_range) *array,
+						uint32_t seq1, uint32_t seq2);
 unsigned int
-seq_range_array_intersect(ARRAY_TYPE(seq_range) *dest,
-			  const ARRAY_TYPE(seq_range) *src);
+seq_range_array_remove_seq_range_count(ARRAY_TYPE(seq_range) *dest,
+				       const ARRAY_TYPE(seq_range) *src);
+/* Remove sequences from dest that don't exist in src. */
+void seq_range_array_intersect(ARRAY_TYPE(seq_range) *dest,
+			       const ARRAY_TYPE(seq_range) *src);
 /* Returns TRUE if sequence exists in the range. */
 bool seq_range_exists(const ARRAY_TYPE(seq_range) *array,
 		      uint32_t seq) ATTR_PURE;
--- a/src/lib/test-base64.c	Mon Jun 25 00:01:59 2012 +0300
+++ b/src/lib/test-base64.c	Mon Jun 25 01:14:03 2012 +0300
@@ -95,7 +95,7 @@
 		str_truncate(str, 0);
 		str_truncate(dest, 0);
 		base64_encode(buf, max, str);
-		base64_decode(str_data(str), str_len(str), NULL, dest);
+		test_assert(base64_decode(str_data(str), str_len(str), NULL, dest) >= 0);
 		test_assert(str_len(dest) == max &&
 			    memcmp(buf, str_data(dest), max) == 0);
 	}
--- a/src/lib/test-network.c	Mon Jun 25 00:01:59 2012 +0300
+++ b/src/lib/test-network.c	Mon Jun 25 01:14:03 2012 +0300
@@ -39,8 +39,8 @@
 	bool success;
 
 	for (i = 0; i < N_ELEMENTS(input); i++) {
-		net_addr2ip(input[i].ip, &ip);
-		net_addr2ip(input[i].net, &net_ip);
+		test_assert(net_addr2ip(input[i].ip, &ip) == 0);
+		test_assert(net_addr2ip(input[i].net, &net_ip) == 0);
 		success = net_is_in_network(&ip, &net_ip, input[i].bits) ==
 			input[i].ret;
 		test_out(t_strdup_printf("net_is_in_network(%u)", i), success);
--- a/src/lib/test-ostream-file.c	Mon Jun 25 00:01:59 2012 +0300
+++ b/src/lib/test-ostream-file.c	Mon Jun 25 01:14:03 2012 +0300
@@ -32,19 +32,19 @@
 	size = (rand() % MAX_BUFSIZE) + 1;
 	random_fill_weak(randbuf, size);
 	memcpy(buf, randbuf, size);
-	(void)o_stream_send(output, buf, size);
+	test_assert(o_stream_send(output, buf, size) > 0);
 
 	for (i = 0; i < 10; i++) {
 		offset = rand() % (MAX_BUFSIZE*3);
 		size = (rand() % MAX_BUFSIZE) + 1;
 		random_fill_weak(randbuf, size);
 		memcpy(buf + offset, randbuf, size);
-		o_stream_pwrite(output, randbuf, size, offset);
+		test_assert(o_stream_pwrite(output, randbuf, size, offset) == 0);
 		if (rand() % 10 == 0)
-			(void)o_stream_flush(output);
+			test_assert(o_stream_flush(output) > 0);
 	}
 
-	(void)o_stream_flush(output);
+	test_assert(o_stream_flush(output) > 0);
 	o_stream_uncork(output);
 	ret = pread(fd, buf2, sizeof(buf2), 0);
 	if (ret < 0)
--- a/src/lib/test-seq-range-array.c	Mon Jun 25 00:01:59 2012 +0300
+++ b/src/lib/test-seq-range-array.c	Mon Jun 25 01:14:03 2012 +0300
@@ -52,7 +52,7 @@
 			shadowbuf[seq1] = 0;
 			break;
 		case 3:
-			ret = seq_range_array_remove_range(&range, seq1, seq2);
+			ret = seq_range_array_remove_range_count(&range, seq1, seq2);
 			for (ret2 = 0; seq1 <= seq2; seq1++) {
 				if (shadowbuf[seq1] != 0) {
 					ret2++;
--- a/src/log/log-connection.c	Mon Jun 25 00:01:59 2012 +0300
+++ b/src/log/log-connection.c	Mon Jun 25 01:14:03 2012 +0300
@@ -43,6 +43,8 @@
 static struct log_connection *log_connections = NULL;
 static ARRAY_DEFINE(logs_by_fd, struct log_connection *);
 
+static void log_connection_destroy(struct log_connection *log);
+
 static struct log_client *log_client_get(struct log_connection *log, pid_t pid)
 {
 	struct log_client *client;
@@ -304,8 +306,8 @@
 	}
 }
 
-struct log_connection *
-log_connection_create(struct log_error_buffer *errorbuf, int fd, int listen_fd)
+void log_connection_create(struct log_error_buffer *errorbuf,
+			   int fd, int listen_fd)
 {
 	struct log_connection *log;
 
@@ -321,10 +323,9 @@
 
 	DLLIST_PREPEND(&log_connections, log);
 	log_connection_input(log);
-	return log;
 }
 
-void log_connection_destroy(struct log_connection *log)
+static void log_connection_destroy(struct log_connection *log)
 {
 	struct hash_iterate_context *iter;
 	void *key, *value;
--- a/src/log/log-connection.h	Mon Jun 25 00:01:59 2012 +0300
+++ b/src/log/log-connection.h	Mon Jun 25 01:14:03 2012 +0300
@@ -1,9 +1,10 @@
 #ifndef LOG_CONNECTION_H
 #define LOG_CONNECTION_H
 
-struct log_connection *
-log_connection_create(struct log_error_buffer *errorbuf, int fd, int listen_fd);
-void log_connection_destroy(struct log_connection *log);
+struct log_connection;
+
+void log_connection_create(struct log_error_buffer *errorbuf,
+			   int fd, int listen_fd);
 
 void log_connections_init(void);
 void log_connections_deinit(void);
--- a/src/login-common/client-common-auth.c	Mon Jun 25 00:01:59 2012 +0300
+++ b/src/login-common/client-common-auth.c	Mon Jun 25 01:14:03 2012 +0300
@@ -574,7 +574,7 @@
 		return;
 	}
 
-	client_unref(&client);
+	(void)client_unref(&client);
 }
 
 int client_auth_begin(struct client *client, const char *mech_name,
--- a/src/login-common/login-proxy-state.c	Mon Jun 25 00:01:59 2012 +0300
+++ b/src/login-common/login-proxy-state.c	Mon Jun 25 01:14:03 2012 +0300
@@ -160,5 +160,5 @@
 			      const char *user)
 {
 	if (!login_proxy_state_try_notify(state, user))
-		login_proxy_state_try_notify(state, user);
+		(void)login_proxy_state_try_notify(state, user);
 }
--- a/src/login-common/login-proxy.c	Mon Jun 25 00:01:59 2012 +0300
+++ b/src/login-common/login-proxy.c	Mon Jun 25 01:14:03 2012 +0300
@@ -383,7 +383,7 @@
 	i_free(proxy);
 
 	client->login_proxy = NULL;
-	client_unref(&client);
+	(void)client_unref(&client);
 }
 
 void login_proxy_free(struct login_proxy **_proxy)
--- a/src/login-common/ssl-proxy-openssl.c	Mon Jun 25 00:01:59 2012 +0300
+++ b/src/login-common/ssl-proxy-openssl.c	Mon Jun 25 01:14:03 2012 +0300
@@ -311,15 +311,15 @@
 		} else {
 			proxy->sslout_size += ret;
 			if (!corked) {
-				net_set_cork(proxy->fd_ssl, TRUE);
-				corked = TRUE;
+				if (net_set_cork(proxy->fd_ssl, TRUE) == 0)
+					corked = TRUE;
 			}
 			ssl_write(proxy);
 		}
 	}
 
 	if (corked)
-		net_set_cork(proxy->fd_ssl, FALSE);
+		(void)net_set_cork(proxy->fd_ssl, FALSE);
 
 	ssl_proxy_unref(proxy);
 }
@@ -536,9 +536,9 @@
 		if (proxy->sslout_size == 0)
 			ssl_set_io(proxy, SSL_REMOVE_OUTPUT);
 		else {
-			net_set_cork(proxy->fd_ssl, TRUE);
+			(void)net_set_cork(proxy->fd_ssl, TRUE);
 			ssl_write(proxy);
-			net_set_cork(proxy->fd_ssl, FALSE);
+			(void)net_set_cork(proxy->fd_ssl, FALSE);
 		}
 	}
 
@@ -806,7 +806,7 @@
 	(void)net_disconnect(proxy->fd_plain);
 
 	if (proxy->client != NULL)
-		client_unref(&proxy->client);
+		(void)client_unref(&proxy->client);
 	ssl_proxy_unref(proxy);
 }
 
--- a/src/master/main.c	Mon Jun 25 00:01:59 2012 +0300
+++ b/src/master/main.c	Mon Jun 25 01:14:03 2012 +0300
@@ -155,7 +155,7 @@
 		if (fd != -1) {
 			VA_COPY(args2, args);
 			str = t_strdup_vprintf(format, args2);
-			write_full(fd, str, strlen(str));
+			(void)write_full(fd, str, strlen(str));
 			(void)close(fd);
 		}
 	}
@@ -332,7 +332,7 @@
 					    services->set->instance_name);
 	if (ret == 0) {
 		/* duplicate instance names. allow without warning.. */
-		master_instance_list_update(list, services->set->base_dir);
+		(void)master_instance_list_update(list, services->set->base_dir);
 	}
 	
 	if (to_instance != NULL)
--- a/src/master/service-anvil.c	Mon Jun 25 00:01:59 2012 +0300
+++ b/src/master/service-anvil.c	Mon Jun 25 01:14:03 2012 +0300
@@ -98,7 +98,7 @@
 		service_list_anvil_discard_input(service_anvil_global);
 	else {
 		service = service_lookup_type(service_list, SERVICE_TYPE_ANVIL);
-		service_process_create(service);
+		(void)service_process_create(service);
 	}
 }
 
--- a/src/master/service-process.c	Mon Jun 25 00:01:59 2012 +0300
+++ b/src/master/service-process.c	Mon Jun 25 01:14:03 2012 +0300
@@ -365,17 +365,15 @@
 	process->refcount++;
 }
 
-int service_process_unref(struct service_process *process)
+void service_process_unref(struct service_process *process)
 {
 	i_assert(process->refcount > 0);
 
 	if (--process->refcount > 0)
-		return TRUE;
+		return;
 
 	i_assert(process->destroyed);
-
 	i_free(process);
-	return FALSE;
 }
 
 static const char *
--- a/src/master/service-process.h	Mon Jun 25 00:01:59 2012 +0300
+++ b/src/master/service-process.h	Mon Jun 25 01:14:03 2012 +0300
@@ -38,7 +38,7 @@
 void service_process_destroy(struct service_process *process);
 
 void service_process_ref(struct service_process *process);
-int service_process_unref(struct service_process *process);
+void service_process_unref(struct service_process *process);
 
 void service_process_log_status_error(struct service_process *process,
 				      int status);
--- a/src/plugins/autocreate/autocreate-plugin.c	Mon Jun 25 00:01:59 2012 +0300
+++ b/src/plugins/autocreate/autocreate-plugin.c	Mon Jun 25 01:14:03 2012 +0300
@@ -66,15 +66,16 @@
 		      bool subscriptions)
 {
 	const char *value;
-	char env_name[20];
+	char env_name[13+MAX_INT_STRLEN+1];
 	unsigned int i = 1;
 
 	value = mail_user_plugin_getenv(user, env_name_base);
 	while (value != NULL) {
 		add_autobox(user, value, subscriptions);
 
-		i_snprintf(env_name, sizeof(env_name), "%s%d",
-			   env_name_base, ++i);
+		if (i_snprintf(env_name, sizeof(env_name), "%s%u",
+			       env_name_base, ++i) < 0)
+			i_unreached();
 		value = mail_user_plugin_getenv(user, env_name);
 	}
 }
--- a/src/plugins/expire/doveadm-expire.c	Mon Jun 25 00:01:59 2012 +0300
+++ b/src/plugins/expire/doveadm-expire.c	Mon Jun 25 01:14:03 2012 +0300
@@ -166,7 +166,7 @@
 {
 	ARRAY_TYPE(const_string) patterns;
 	const char *str;
-	char set_name[20];
+	char set_name[6+MAX_INT_STRLEN+1];
 	unsigned int i;
 
 	t_array_init(&patterns, 16);
@@ -174,7 +174,8 @@
 	for (i = 2; str != NULL; i++) {
 		array_append(&patterns, &str, 1);
 
-		i_snprintf(set_name, sizeof(set_name), "expire%u", i);
+		if (i_snprintf(set_name, sizeof(set_name), "expire%u", i) < 0)
+			i_unreached();
 		str = doveadm_plugin_getenv(set_name);
 	}
 	(void)array_append_space(&patterns);
@@ -350,9 +351,10 @@
 
 	if (ectx->iter != NULL) {
 		if (dict_iterate_deinit(&ectx->iter) < 0)
-			i_error("Dictionary iteration failed");
+			i_error("expire: Dictionary iteration failed");
 	}
-	dict_transaction_commit(&ectx->trans);
+	if (dict_transaction_commit(&ectx->trans) < 0)
+		i_error("expire: Dictionary commit failed");
 	dict_deinit(&ectx->dict);
 	hash_table_destroy(&ectx->users);
 
--- a/src/plugins/expire/expire-plugin.c	Mon Jun 25 00:01:59 2012 +0300
+++ b/src/plugins/expire/expire-plugin.c	Mon Jun 25 01:14:03 2012 +0300
@@ -306,7 +306,7 @@
 {
 	ARRAY_TYPE(const_string) patterns;
 	const char *str;
-	char set_name[20];
+	char set_name[6+MAX_INT_STRLEN+1];
 	unsigned int i;
 
 	t_array_init(&patterns, 16);
@@ -314,7 +314,8 @@
 	for (i = 2; str != NULL; i++) {
 		array_append(&patterns, &str, 1);
 
-		i_snprintf(set_name, sizeof(set_name), "expire%u", i);
+		if (i_snprintf(set_name, sizeof(set_name), "expire%u", i) < 0)
+			i_unreached();
 		str = mail_user_set_plugin_getenv(user->set, set_name);
 	}
 	(void)array_append_space(&patterns);
--- a/src/plugins/fts-lucene/fts-backend-lucene.c	Mon Jun 25 00:01:59 2012 +0300
+++ b/src/plugins/fts-lucene/fts-backend-lucene.c	Mon Jun 25 01:14:03 2012 +0300
@@ -248,8 +248,10 @@
 	i_assert(backend->updating);
 
 	backend->updating = FALSE;
-	if (ctx->lucene_opened)
-		lucene_index_build_deinit(backend->index);
+	if (ctx->lucene_opened) {
+		if (lucene_index_build_deinit(backend->index) < 0)
+			ret = -1;
+	}
 
 	if (ctx->expunge_ctx != NULL) {
 		if (fts_expunge_log_append_commit(&ctx->expunge_ctx) < 0)
@@ -547,7 +549,7 @@
 {
 	/* the next refresh is going to close the index anyway, so we might as
 	   well do it now */
-	fts_backend_lucene_refresh(_backend);
+	(void)fts_backend_lucene_refresh(_backend);
 }
 
 struct fts_backend fts_backend_lucene = {
--- a/src/plugins/fts-squat/squat-trie.c	Mon Jun 25 00:01:59 2012 +0300
+++ b/src/plugins/fts-squat/squat-trie.c	Mon Jun 25 01:14:03 2012 +0300
@@ -1658,7 +1658,7 @@
 		o_stream_cork(output);
 
 		if (trie->hdr.used_file_size != 0)
-			o_stream_seek(output, trie->hdr.used_file_size);
+			(void)o_stream_seek(output, trie->hdr.used_file_size);
 		else
 			o_stream_nsend(output, &trie->hdr, sizeof(trie->hdr));
 	}
@@ -1677,7 +1677,7 @@
 		ret = squat_trie_write_lock(ctx);
 	if (ret == 0) {
 		trie->hdr.used_file_size = output->offset;
-		o_stream_seek(output, 0);
+		(void)o_stream_seek(output, 0);
 		o_stream_nsend(output, &trie->hdr, sizeof(trie->hdr));
 	}
 	if (o_stream_nfinish(output) < 0) {
--- a/src/plugins/fts-squat/squat-uidlist.c	Mon Jun 25 00:01:59 2012 +0300
+++ b/src/plugins/fts-squat/squat-uidlist.c	Mon Jun 25 01:14:03 2012 +0300
@@ -372,7 +372,7 @@
 	}
 	if (uidlist->hdr.indexid != uidlist->trie->hdr.indexid) {
 		/* see if trie was recreated */
-		squat_trie_refresh(uidlist->trie);
+		(void)squat_trie_refresh(uidlist->trie);
 	}
 	if (uidlist->hdr.indexid != uidlist->trie->hdr.indexid) {
 		squat_uidlist_set_corrupted(uidlist, "wrong indexid");
@@ -855,10 +855,10 @@
 		return -1;
 
 	if (!ctx->output->closed) {
-		o_stream_seek(ctx->output, 0);
+		(void)o_stream_seek(ctx->output, 0);
 		o_stream_nsend(ctx->output,
 			       &ctx->build_hdr, sizeof(ctx->build_hdr));
-		o_stream_seek(ctx->output, ctx->build_hdr.used_file_size);
+		(void)o_stream_seek(ctx->output, ctx->build_hdr.used_file_size);
 	}
 
 	if (o_stream_nfinish(ctx->output) < 0) {
@@ -1056,11 +1056,11 @@
 						    &ctx->new_block_offsets,
 						    &ctx->new_block_end_indexes,
 						    FALSE);
-		o_stream_seek(ctx->output, 0);
+		(void)o_stream_seek(ctx->output, 0);
 		o_stream_nsend(ctx->output, &ctx->build_ctx->build_hdr,
 			       sizeof(ctx->build_ctx->build_hdr));
-		o_stream_seek(ctx->output,
-			      ctx->build_ctx->build_hdr.used_file_size);
+		(void)o_stream_seek(ctx->output,
+				    ctx->build_ctx->build_hdr.used_file_size);
 
 		if (ctx->uidlist->corrupted)
 			ret = -1;
@@ -1176,8 +1176,8 @@
 		}
 		for (; mask <= 128; mask <<= 1, idx++) {
 			if ((old_list_idx & mask) != 0) {
-				squat_uidlist_build_add_uid(ctx,
-							    uid_list_idx, idx);
+				(void)squat_uidlist_build_add_uid(ctx,
+							uid_list_idx, idx);
 			}
 		}
 	}
@@ -1548,7 +1548,8 @@
 
 	i_array_init(&relative_uids, 128);
 	i_array_init(&dest_uids, 128);
-	squat_uidlist_get(uidlist, uid_list_idx, &relative_uids);
+	if (squat_uidlist_get(uidlist, uid_list_idx, &relative_uids) < 0)
+		ret = -1;
 
 	parent_idx = 0;
 	rel_range = array_get(&relative_uids, &rel_count);
--- a/src/plugins/fts/fts-storage.c	Mon Jun 25 00:01:59 2012 +0300
+++ b/src/plugins/fts/fts-storage.c	Mon Jun 25 01:14:03 2012 +0300
@@ -356,8 +356,9 @@
 	}
 	if (scores != NULL) {
 		i_assert(scores->uid == _mail->uid);
-		i_snprintf(fmail->score, sizeof(fmail->score),
-			   "%f", scores->score);
+		(void)i_snprintf(fmail->score, sizeof(fmail->score),
+				 "%f", scores->score);
+			
 		*value_r = fmail->score;
 		return 0;
 	}
--- a/src/plugins/imap-acl/imap-acl-plugin.c	Mon Jun 25 00:01:59 2012 +0300
+++ b/src/plugins/imap-acl/imap-acl-plugin.c	Mon Jun 25 01:14:03 2012 +0300
@@ -687,7 +687,7 @@
 	command_unregister("DELETEACL");
 	command_unregister("LISTRIGHTS");
 
-	imap_client_created_hook_set(next_hook_client_created);
+	(void)imap_client_created_hook_set(next_hook_client_created);
 }
 
 const char *imap_acl_plugin_dependencies[] = { "acl", NULL };
--- a/src/plugins/imap-quota/imap-quota-plugin.c	Mon Jun 25 00:01:59 2012 +0300
+++ b/src/plugins/imap-quota/imap-quota-plugin.c	Mon Jun 25 01:14:03 2012 +0300
@@ -230,7 +230,7 @@
 	command_unregister("GETQUOTA");
 	command_unregister("SETQUOTA");
 
-	imap_client_created_hook_set(next_hook_client_created);
+	(void)imap_client_created_hook_set(next_hook_client_created);
 }
 
 const char *imap_quota_plugin_dependencies[] = { "quota", NULL };
--- a/src/plugins/imap-zlib/imap-zlib-plugin.c	Mon Jun 25 00:01:59 2012 +0300
+++ b/src/plugins/imap-zlib/imap-zlib-plugin.c	Mon Jun 25 01:14:03 2012 +0300
@@ -153,7 +153,7 @@
 {
 	command_unregister("COMPRESS");
 
-	imap_client_created_hook_set(next_hook_client_created);
+	(void)imap_client_created_hook_set(next_hook_client_created);
 }
 
 const char *imap_zlib_plugin_dependencies[] = { "zlib", NULL };
--- a/src/plugins/quota/quota-maildir.c	Mon Jun 25 00:01:59 2012 +0300
+++ b/src/plugins/quota/quota-maildir.c	Mon Jun 25 01:14:03 2012 +0300
@@ -696,7 +696,7 @@
 static int maildirsize_update(struct maildir_quota_root *root,
 			      int count_diff, int64_t bytes_diff)
 {
-	char str[MAX_INT_STRLEN*2 + 2];
+	char str[MAX_INT_STRLEN*2 + 2 + 1];
 	int ret = 0;
 
 	if (count_diff == 0 && bytes_diff == 0)
@@ -707,8 +707,9 @@
 	   a while, and sooner if corruption causes calculations to go
 	   over quota. This is also how Maildir++ spec specifies it should be
 	   done.. */
-	i_snprintf(str, sizeof(str), "%lld %d\n",
-		   (long long)bytes_diff, count_diff);
+	if (i_snprintf(str, sizeof(str), "%lld %d\n",
+		       (long long)bytes_diff, count_diff) < 0)
+		i_unreached();
 	if (write_full(root->fd, str, strlen(str)) < 0) {
 		ret = -1;
 		if (errno == ESTALE) {
--- a/src/plugins/quota/quota.c	Mon Jun 25 00:01:59 2012 +0300
+++ b/src/plugins/quota/quota.c	Mon Jun 25 01:14:03 2012 +0300
@@ -183,7 +183,7 @@
 			     const char **error_r)
 {
 	struct quota_settings *quota_set;
-	char root_name[6 + MAX_INT_STRLEN];
+	char root_name[5 + MAX_INT_STRLEN + 1];
 	const char *env, *error;
 	unsigned int i;
 	pool_t pool;
@@ -199,7 +199,8 @@
 		quota_set->quota_exceeded_msg = DEFAULT_QUOTA_EXCEEDED_MSG;
 
 	p_array_init(&quota_set->root_sets, pool, 4);
-	i_strocpy(root_name, "quota", sizeof(root_name));
+	if (i_strocpy(root_name, "quota", sizeof(root_name)) < 0)
+		i_unreached();
 	for (i = 2;; i++) {
 		env = mail_user_plugin_getenv(user, root_name);
 		if (env == NULL || *env == '\0')
@@ -212,7 +213,8 @@
 			pool_unref(&pool);
 			return -1;
 		}
-		i_snprintf(root_name, sizeof(root_name), "quota%d", i);
+		if (i_snprintf(root_name, sizeof(root_name), "quota%d", i) < 0)
+			i_unreached();
 	}
 	if (array_count(&quota_set->root_sets) == 0) {
 		pool_unref(&pool);
--- a/src/plugins/stats/stats-connection.c	Mon Jun 25 00:01:59 2012 +0300
+++ b/src/plugins/stats/stats-connection.c	Mon Jun 25 01:14:03 2012 +0300
@@ -40,7 +40,7 @@
 	conn = i_new(struct stats_connection, 1);
 	conn->refcount = 1;
 	conn->path = i_strdup(path);
-	stats_connection_open(conn);
+	(void)stats_connection_open(conn);
 	return conn;
 }
 
--- a/src/plugins/virtual/virtual-mail.c	Mon Jun 25 00:01:59 2012 +0300
+++ b/src/plugins/virtual/virtual-mail.c	Mon Jun 25 01:14:03 2012 +0300
@@ -124,7 +124,7 @@
 	bbox = virtual_backend_box_lookup(mbox, vrec->mailbox_id);
 	vmail->backend_mail = backend_mail_find(vmail, bbox->box);
 	if (vmail->backend_mail == NULL)
-		virtual_mail_set_backend_mail(mail, bbox);
+		(void)virtual_mail_set_backend_mail(mail, bbox);
 	vmail->lost = !mail_set_uid(vmail->backend_mail, vrec->real_uid);
 	memset(&vmail->imail.data, 0, sizeof(vmail->imail.data));
 	p_clear(vmail->imail.data_pool);
--- a/src/plugins/virtual/virtual-sync.c	Mon Jun 25 00:01:59 2012 +0300
+++ b/src/plugins/virtual/virtual-sync.c	Mon Jun 25 01:14:03 2012 +0300
@@ -835,7 +835,7 @@
 	if (count1 > 0 && count2 > 0) {
 		t_array_init(&temp_uids, count1);
 		array_append_array(&temp_uids, &bbox->sync_pending_removes);
-		if (seq_range_array_remove_seq_range(
+		if (seq_range_array_remove_seq_range_count(
 				&bbox->sync_pending_removes, &added_uids) > 0) {
 			seq_range_array_remove_seq_range(&added_uids,
 							 &temp_uids);
--- a/src/plugins/zlib/doveadm-zlib.c	Mon Jun 25 00:01:59 2012 +0300
+++ b/src/plugins/zlib/doveadm-zlib.c	Mon Jun 25 01:14:03 2012 +0300
@@ -75,7 +75,7 @@
 	ret = read(fd, buf, sizeof(buf)-1);
 	if (ret > 0) {
 		buf[ret] = '\0';
-		str_lcase(buf);
+		(void)str_lcase(buf);
 		match = strstr(buf, " ok begin compression.") != NULL ||
 			strstr(buf, " compress deflate") != NULL;
 	}
--- a/src/plugins/zlib/ostream-zlib.c	Mon Jun 25 00:01:59 2012 +0300
+++ b/src/plugins/zlib/ostream-zlib.c	Mon Jun 25 01:14:03 2012 +0300
@@ -115,8 +115,10 @@
 	flush = zstream->ostream.corked || zstream->gz ?
 		Z_NO_FLUSH : Z_SYNC_FLUSH;
 
-	if (!zstream->header_sent)
-		o_stream_zlib_send_gz_header(zstream);
+	if (!zstream->header_sent) {
+		if (o_stream_zlib_send_gz_header(zstream) < 0)
+			return -1;
+	}
 
 	zs->next_in = (void *)data;
 	zs->avail_in = size;
@@ -169,8 +171,10 @@
 
 	if (zstream->flushed)
 		return 0;
-	if (!zstream->header_sent)
-		o_stream_zlib_send_gz_header(zstream);
+	if (!zstream->header_sent) {
+		if (o_stream_zlib_send_gz_header(zstream) < 0)
+			return -1;
+	}
 
 	if ((ret = o_stream_zlib_send_outbuf(zstream)) <= 0)
 		return ret;
--- a/src/pop3/main.c	Mon Jun 25 00:01:59 2012 +0300
+++ b/src/pop3/main.c	Mon Jun 25 01:14:03 2012 +0300
@@ -138,9 +138,9 @@
 	if (input.username == NULL)
 		i_fatal("USER environment missing");
 	if ((value = getenv("IP")) != NULL)
-		net_addr2ip(value, &input.remote_ip);
+		(void)net_addr2ip(value, &input.remote_ip);
 	if ((value = getenv("LOCAL_IP")) != NULL)
-		net_addr2ip(value, &input.local_ip);
+		(void)net_addr2ip(value, &input.local_ip);
 
 	input_base64 = getenv("CLIENT_INPUT");
 	input_buf = input_base64 == NULL ? NULL :
--- a/src/pop3/pop3-client.c	Mon Jun 25 00:01:59 2012 +0300
+++ b/src/pop3/pop3-client.c	Mon Jun 25 01:14:03 2012 +0300
@@ -485,7 +485,7 @@
 static void client_default_destroy(struct client *client, const char *reason)
 {
 	if (client->seen_change_count > 0)
-		client_update_mails(client);
+		(void)client_update_mails(client);
 
 	if (!client->disconnected) {
 		if (reason == NULL)
@@ -568,13 +568,13 @@
 	client->to_idle = timeout_add(0, client_destroy_timeout, client);
 }
 
-int client_send_line(struct client *client, const char *fmt, ...)
+void client_send_line(struct client *client, const char *fmt, ...)
 {
 	va_list va;
 	ssize_t ret;
 
 	if (client->output->closed)
-		return -1;
+		return;
 
 	va_start(va, fmt);
 
@@ -592,10 +592,8 @@
 	if (ret >= 0) {
 		if (o_stream_get_buffer_used_size(client->output) <
 		    OUTBUF_THROTTLE_SIZE) {
-			ret = 1;
 			client->last_output = ioloop_time;
 		} else {
-			ret = 0;
 			if (client->io != NULL) {
 				/* no more input until client has read
 				   our output */
@@ -609,9 +607,7 @@
 			}
 		}
 	}
-
 	va_end(va);
-	return (int)ret;
 }
 
 void client_send_storage_error(struct client *client)
--- a/src/pop3/pop3-client.h	Mon Jun 25 00:01:59 2012 +0300
+++ b/src/pop3/pop3-client.h	Mon Jun 25 01:14:03 2012 +0300
@@ -9,6 +9,9 @@
 #define MSGS_BITMASK_SIZE(client) \
 	(((client)->messages_count + (CHAR_BIT-1)) / CHAR_BIT)
 
+#define POP3_CLIENT_OUTPUT_FULL(client) \
+	((client)->io == NULL)
+
 struct pop3_client_vfuncs {
 	void (*destroy)(struct client *client, const char *reason);
 
@@ -110,7 +113,7 @@
 void client_disconnect(struct client *client, const char *reason);
 
 /* Send a line of data to client */
-int client_send_line(struct client *client, const char *fmt, ...)
+void client_send_line(struct client *client, const char *fmt, ...)
 	ATTR_FORMAT(2, 3);
 void client_send_storage_error(struct client *client);
 
--- a/src/pop3/pop3-commands.c	Mon Jun 25 00:01:59 2012 +0300
+++ b/src/pop3/pop3-commands.c	Mon Jun 25 01:14:03 2012 +0300
@@ -130,10 +130,9 @@
 static void cmd_list_callback(struct client *client)
 {
 	struct cmd_list_context *ctx = client->cmd_context;
-	int ret = 1;
 
 	for (; ctx->msgnum != client->messages_count; ctx->msgnum++) {
-		if (ret == 0) {
+		if (POP3_CLIENT_OUTPUT_FULL(client)) {
 			/* buffer full */
 			return;
 		}
@@ -144,9 +143,9 @@
 				continue;
 		}
 
-		ret = client_send_line(client, "%u %"PRIuUOFF_T, ctx->msgnum+1,
-				       client->message_sizes[ctx->msgnum]);
-		if (ret < 0)
+		client_send_line(client, "%u %"PRIuUOFF_T, ctx->msgnum+1,
+				 client->message_sizes[ctx->msgnum]);
+		if (client->output->closed)
 			break;
 	}
 
@@ -512,7 +511,7 @@
 			mail_update_flags(mail, MODIFY_REMOVE, MAIL_SEEN);
 		(void)mailbox_search_deinit(&search_ctx);
 
-		mailbox_transaction_commit(&client->trans);
+		(void)mailbox_transaction_commit(&client->trans);
 		client->trans = mailbox_transaction_begin(client->mailbox, 0);
 	}
 
@@ -587,8 +586,9 @@
 	tab[0].value = t_strdup_printf("%u", client->uid_validity);
 
 	if ((client->uidl_keymask & UIDL_UID) != 0) {
-		i_snprintf(uid_str, sizeof(uid_str), "%u",
-			   mail->uid);
+		if (i_snprintf(uid_str, sizeof(uid_str), "%u",
+			       mail->uid) < 0)
+			i_unreached();
 		tab[1].value = uid_str;
 	}
 	if ((client->uidl_keymask & UIDL_MD5) != 0) {
@@ -625,7 +625,6 @@
 list_uidls_saved_iter(struct client *client, struct cmd_uidl_context *ctx)
 {
 	bool found = FALSE;
-	int ret;
 
 	while (ctx->msgnum < client->messages_count) {
 		uint32_t msgnum = ctx->msgnum++;
@@ -637,12 +636,12 @@
 		}
 		found = TRUE;
 
-		ret = client_send_line(client,
-				       ctx->list_all ? "%u %s" : "+OK %u %s",
-				       msgnum+1, client->message_uidls[msgnum]);
-		if (ret < 0 || !ctx->list_all)
+		client_send_line(client,
+				 ctx->list_all ? "%u %s" : "+OK %u %s",
+				 msgnum+1, client->message_uidls[msgnum]);
+		if (client->output->closed || !ctx->list_all)
 			break;
-		if (ret == 0) {
+		if (POP3_CLIENT_OUTPUT_FULL(client)) {
 			/* output is being buffered, continue when there's
 			   more space */
 			return FALSE;
@@ -660,7 +659,6 @@
 static bool list_uids_iter(struct client *client, struct cmd_uidl_context *ctx)
 {
 	string_t *str;
-	int ret;
 	bool permanent_uidl, found = FALSE;
 
 	if (client->message_uidls != NULL)
@@ -684,12 +682,11 @@
 		if (client->set->pop3_save_uidl && !permanent_uidl)
 			mail_update_pop3_uidl(ctx->mail, str_c(str));
 
-		ret = client_send_line(client,
-				       ctx->list_all ? "%u %s" : "+OK %u %s",
-				       msgnum+1, str_c(str));
-		if (ret < 0)
+		client_send_line(client, ctx->list_all ? "%u %s" : "+OK %u %s",
+				 msgnum+1, str_c(str));
+		if (client->output->closed)
 			break;
-		if (ret == 0 && ctx->list_all) {
+		if (POP3_CLIENT_OUTPUT_FULL(client) && ctx->list_all) {
 			/* output is being buffered, continue when there's
 			   more space */
 			return FALSE;
--- a/src/replication/aggregator/notify-connection.c	Mon Jun 25 00:01:59 2012 +0300
+++ b/src/replication/aggregator/notify-connection.c	Mon Jun 25 01:14:03 2012 +0300
@@ -82,7 +82,7 @@
 	case -2:
 		/* buffer full */
 		i_error("Client sent too long line");
-		notify_input_error(conn);
+		(void)notify_input_error(conn);
 		return;
 	case -1:
 		/* disconnected */
--- a/src/replication/replicator/notify-connection.c	Mon Jun 25 00:01:59 2012 +0300
+++ b/src/replication/replicator/notify-connection.c	Mon Jun 25 01:14:03 2012 +0300
@@ -73,7 +73,7 @@
 		return -1;
 	}
 	if (priority != REPLICATION_PRIORITY_SYNC)
-		replicator_queue_add(conn->queue, args[1], priority);
+		(void)replicator_queue_add(conn->queue, args[1], priority);
 	else if (args[3] == NULL || str_to_uint(args[3], &id) < 0) {
 		i_error("notify client sent invalid sync id: %s", line);
 		return -1;
--- a/src/stats/main.c	Mon Jun 25 00:01:59 2012 +0300
+++ b/src/stats/main.c	Mon Jun 25 01:14:03 2012 +0300
@@ -26,7 +26,7 @@
 		}
 		mail_server_conn = mail_server_connection_create(conn->fd);
 	} else {
-		client_create(conn->fd);
+		(void)client_create(conn->fd);
 	}
 	master_service_client_connection_accept(conn);
 }
--- a/src/util/rawlog.c	Mon Jun 25 00:01:59 2012 +0300
+++ b/src/util/rawlog.c	Mon Jun 25 01:14:03 2012 +0300
@@ -348,7 +348,7 @@
 					  dec2str(getppid())));
 
 	ioloop = io_loop_create();
-	rawlog_proxy_create(0, 1, sfd[0], path, flags);
+	(void)rawlog_proxy_create(0, 1, sfd[0], path, flags);
 	io_loop_run(ioloop);
 	io_loop_destroy(&ioloop);