dovecot-1.1: Avoid using shadow variables. Unfortunately -Wshado...

dovecot at dovecot.org dovecot at dovecot.org
Tue May 27 02:09:56 EEST 2008


details:   http://hg.dovecot.org/dovecot-1.1/rev/1a58b18652a6
changeset: 7561:1a58b18652a6
user:      Timo Sirainen <tss at iki.fi>
date:      Tue May 27 02:09:47 2008 +0300
description:
Avoid using shadow variables. Unfortunately -Wshadow also complains about
index variable conflicting with index(), which is used in way too many
places to change.

diffstat:

32 files changed, 197 insertions(+), 189 deletions(-)
src/auth/auth-master-listener.c             |   14 ++---
src/auth/db-passwd-file.c                   |    5 --
src/auth/userdb-nss.c                       |   12 ++--
src/deliver/auth-client.c                   |   14 ++---
src/deliver/deliver.c                       |    7 +-
src/deliver/duplicate.c                     |    4 -
src/deliver/duplicate.h                     |    2 
src/imap/imap-fetch-body.c                  |   12 ++--
src/imap/imap-thread.c                      |    3 -
src/lib-imap/imap-date.c                    |   19 ++++---
src/lib-imap/imap-date.h                    |    7 +-
src/lib-index/mail-cache-compress.c         |   18 +++----
src/lib-index/mail-index-map.c              |   12 ++--
src/lib-mail/mbox-from.c                    |   16 +++---
src/lib-mail/mbox-from.h                    |    2 
src/lib-mail/message-date.c                 |   31 ++++++------
src/lib-mail/message-date.h                 |    4 -
src/lib-storage/index/dbox/dbox-index.c     |   10 ++--
src/lib-storage/index/index-sync.c          |    9 ++-
src/lib-storage/index/mbox/mbox-sync.c      |    1 
src/lib-storage/list/mailbox-list-fs-iter.c |    4 -
src/lib/module-dir.c                        |    2 
src/lib/restrict-access.c                   |   67 ++++++++++++++-------------
src/master/dict-process.c                   |   10 +++-
src/master/listener.c                       |   12 ++--
src/master/mail-process.c                   |   18 +++----
src/master/mail-process.h                   |    2 
src/master/master-settings.c                |   16 +++---
src/plugins/fts-squat/squat-trie.c          |   35 +++++++-------
src/plugins/quota/quota-fs.c                |    2 
src/util/idxview.c                          |    4 -
src/util/rawlog.c                           |   12 ++--

diffs (truncated from 1164 to 300 lines):

diff -r fedeb23a3d53 -r 1a58b18652a6 src/auth/auth-master-listener.c
--- a/src/auth/auth-master-listener.c	Tue May 27 00:16:12 2008 +0300
+++ b/src/auth/auth-master-listener.c	Tue May 27 02:09:47 2008 +0300
@@ -40,16 +40,16 @@ struct auth_master_listener *auth_master
 }
 
 static void
-auth_master_listener_socket_free(struct auth_master_listener_socket *socket)
+auth_master_listener_socket_free(struct auth_master_listener_socket *s)
 {
-	if (socket->path != NULL) {
-		(void)unlink(socket->path);
-		i_free(socket->path);
+	if (s->path != NULL) {
+		(void)unlink(s->path);
+		i_free(s->path);
 	}
 
-	io_remove(&socket->io);
-	net_disconnect(socket->fd);
-	i_free(socket);
+	io_remove(&s->io);
+	net_disconnect(s->fd);
+	i_free(s);
 }
 
 void auth_master_listener_destroy(struct auth_master_listener *listener)
diff -r fedeb23a3d53 -r 1a58b18652a6 src/auth/db-passwd-file.c
--- a/src/auth/db-passwd-file.c	Tue May 27 00:16:12 2008 +0300
+++ b/src/auth/db-passwd-file.c	Tue May 27 02:09:47 2008 +0300
@@ -385,15 +385,12 @@ db_passwd_file_lookup(struct db_passwd_f
 	struct passwd_file *pw;
 	struct passwd_user *pu;
 	const struct var_expand_table *table;
-	string_t *username;
+	string_t *username, *dest;
 	const char *path;
 
 	if (!db->vars)
 		pw = db->default_file;
 	else {
-		const struct var_expand_table *table;
-		string_t *dest;
-
 		table = auth_request_get_var_expand_table(request, path_fix);
 		dest = t_str_new(256);
 		var_expand(dest, db->path, table);
diff -r fedeb23a3d53 -r 1a58b18652a6 src/auth/userdb-nss.c
--- a/src/auth/userdb-nss.c	Tue May 27 00:16:12 2008 +0300
+++ b/src/auth/userdb-nss.c	Tue May 27 02:09:47 2008 +0300
@@ -130,13 +130,13 @@ static void userdb_nss_deinit(struct use
 static void userdb_nss_deinit(struct userdb_module *_module)
 {
 	struct nss_userdb_module *module = (struct nss_userdb_module *)_module;
-	void (*endpwent)(void);
+	void (*mod_endpwent)(void);
+	const char *symbol;
 
-	endpwent = module_get_symbol(&module->nss_module,
-				     t_strdup_printf("_nss_%s_endpwent",
-						     module->nss_module.name));
-	if (endpwent != NULL)
-		endpwent();
+	symbol = t_strdup_printf("_nss_%s_endpwent", module->nss_module.name);
+	mod_endpwent = module_get_symbol(&module->nss_module, symbol);
+	if (mod_endpwent != NULL)
+		mod_endpwent();
 }
 
 struct userdb_module_interface userdb_nss = {
diff -r fedeb23a3d53 -r 1a58b18652a6 src/deliver/auth-client.c
--- a/src/deliver/auth-client.c	Tue May 27 00:16:12 2008 +0300
+++ b/src/deliver/auth-client.c	Tue May 27 02:09:47 2008 +0300
@@ -95,7 +95,7 @@ static void auth_parse_input(struct auth
 	const char *const *tmp, *extra_groups;
 	uid_t uid = 0;
 	gid_t gid = 0;
-	const char *chroot = getenv("MAIL_CHROOT");
+	const char *chroot_dir = getenv("MAIL_CHROOT");
 	const char *home_dir = NULL;
 	bool debug = getenv("DEBUG") != NULL;
 	unsigned int len;
@@ -121,7 +121,7 @@ static void auth_parse_input(struct auth
 				return_value = EX_TEMPFAIL;
 			}
 		} else if (strncmp(*tmp, "chroot=", 7) == 0) {
-			chroot = *tmp + 7;
+			chroot_dir = *tmp + 7;
 		} else {
 			char *field = i_strdup(*tmp);
 
@@ -162,15 +162,15 @@ static void auth_parse_input(struct auth
 	if (conn->euid == 0 || getegid() != gid)
 		env_put(t_strconcat("RESTRICT_SETGID=", dec2str(gid), NULL));
 
-	if (chroot != NULL) {
-		len = strlen(chroot);
-		if (len > 2 && strcmp(chroot + len - 2, "/.") == 0 &&
+	if (chroot_dir != NULL) {
+		len = strlen(chroot_dir);
+		if (len > 2 && strcmp(chroot_dir + len - 2, "/.") == 0 &&
 		    home_dir != NULL &&
-		    strncmp(home_dir, chroot, len - 2) == 0) {
+		    strncmp(home_dir, chroot_dir, len - 2) == 0) {
 			/* strip chroot dir from home dir */
 			home_dir += len - 2;
 		}
-		env_put(t_strconcat("RESTRICT_CHROOT=", chroot, NULL));
+		env_put(t_strconcat("RESTRICT_CHROOT=", chroot_dir, NULL));
 	}
 	if (home_dir != NULL)
 		env_put(t_strconcat("HOME=", home_dir, NULL));
diff -r fedeb23a3d53 -r 1a58b18652a6 src/deliver/deliver.c
--- a/src/deliver/deliver.c	Tue May 27 00:16:12 2008 +0300
+++ b/src/deliver/deliver.c	Tue May 27 02:09:47 2008 +0300
@@ -711,7 +711,7 @@ int main(int argc, char *argv[])
 	const char *config_path = DEFAULT_CONFIG_FILE;
 	const char *mailbox = "INBOX";
 	const char *auth_socket;
-	const char *home, *destaddr, *user, *value, *error;
+	const char *home, *destaddr, *user, *value, *errstr;
 	ARRAY_TYPE(string) extra_fields;
 	struct mail_namespace *ns, *raw_ns;
 	struct mail_storage *storage;
@@ -938,8 +938,8 @@ int main(int argc, char *argv[])
 	raw_ns = mail_namespaces_init_empty(namespace_pool);
 	raw_ns->flags |= NAMESPACE_FLAG_INTERNAL;
 	if (mail_storage_create(raw_ns, "raw", "/tmp", user,
-				0, FILE_LOCK_METHOD_FCNTL, &error) < 0)
-		i_fatal("Couldn't create internal raw storage: %s", error);
+				0, FILE_LOCK_METHOD_FCNTL, &errstr) < 0)
+		i_fatal("Couldn't create internal raw storage: %s", errstr);
 	input = create_raw_stream(0, &mtime);
 	box = mailbox_open(raw_ns->storage, "Dovecot Delivery Mail", input,
 			   MAILBOX_OPEN_NO_INDEX_FILES);
@@ -991,7 +991,6 @@ int main(int argc, char *argv[])
 	if (ret < 0 ) {
 		const char *error_string;
 		enum mail_error error;
-		int ret;
 
 		if (storage == NULL) {
 			/* This shouldn't happen */
diff -r fedeb23a3d53 -r 1a58b18652a6 src/deliver/duplicate.c
--- a/src/deliver/duplicate.c	Tue May 27 00:16:12 2008 +0300
+++ b/src/deliver/duplicate.c	Tue May 27 02:09:47 2008 +0300
@@ -245,7 +245,7 @@ int duplicate_check(const void *id, size
 }
 
 void duplicate_mark(const void *id, size_t id_size,
-                    const char *user, time_t time)
+                    const char *user, time_t timestamp)
 {
 	struct duplicate *d;
 	void *new_id;
@@ -260,7 +260,7 @@ void duplicate_mark(const void *id, size
 	d->id = new_id;
 	d->id_size = id_size;
 	d->user = p_strdup(duplicate_file->pool, user);
-	d->time = time;
+	d->time = timestamp;
 
 	duplicate_file->changed = TRUE;
 	hash_insert(duplicate_file->hash, d, d);
diff -r fedeb23a3d53 -r 1a58b18652a6 src/deliver/duplicate.h
--- a/src/deliver/duplicate.h	Tue May 27 00:16:12 2008 +0300
+++ b/src/deliver/duplicate.h	Tue May 27 02:09:47 2008 +0300
@@ -5,7 +5,7 @@
 
 int duplicate_check(const void *id, size_t id_size, const char *user);
 void duplicate_mark(const void *id, size_t id_size,
-                    const char *user, time_t time);
+                    const char *user, time_t timestamp);
 
 void duplicate_flush(void);
 
diff -r fedeb23a3d53 -r 1a58b18652a6 src/imap/imap-fetch-body.c
--- a/src/imap/imap-fetch-body.c	Tue May 27 00:16:12 2008 +0300
+++ b/src/imap/imap-fetch-body.c	Tue May 27 02:09:47 2008 +0300
@@ -41,7 +41,7 @@ struct partial_cache {
 	struct message_size pos;
 };
 
-static struct partial_cache partial = { 0, 0, 0, 0, { 0, 0, 0 } };
+static struct partial_cache last_partial = { 0, 0, 0, 0, { 0, 0, 0 } };
 
 static bool seek_partial(unsigned int select_counter, unsigned int uid,
 			 struct partial_cache *partial, struct istream *stream,
@@ -224,10 +224,10 @@ static int fetch_stream_send(struct imap
 
 	ctx->cur_offset += ret;
 	if (ctx->update_partial) {
-		partial.cr_skipped = ctx->skip_cr != 0;
-		partial.pos.physical_size =
-			ctx->cur_input->v_offset - partial.physical_start;
-		partial.pos.virtual_size += ret;
+		last_partial.cr_skipped = ctx->skip_cr != 0;
+		last_partial.pos.physical_size =
+			ctx->cur_input->v_offset - last_partial.physical_start;
+		last_partial.pos.virtual_size += ret;
 	}
 
 	return ctx->cur_offset == ctx->cur_size;
@@ -312,7 +312,7 @@ static int fetch_data(struct imap_fetch_
 	} else {
 		ctx->skip_cr =
 			seek_partial(ctx->select_counter, ctx->cur_mail->uid,
-				     &partial, ctx->cur_input, body->skip);
+				     &last_partial, ctx->cur_input, body->skip);
 	}
 
 	return fetch_stream(ctx, size);
diff -r fedeb23a3d53 -r 1a58b18652a6 src/imap/imap-thread.c
--- a/src/imap/imap-thread.c	Tue May 27 00:16:12 2008 +0300
+++ b/src/imap/imap-thread.c	Tue May 27 02:09:47 2008 +0300
@@ -939,8 +939,7 @@ static void mail_thread_finish(struct th
 	/* (2) save root nodes and drop the msgids */
 	iter = hash_iterate_init(ctx->msgid_hash);
 	while (hash_iterate(iter, &key, &value)) {
-		struct node *node = value;
-
+		node = value;
 		if (node->parent == NULL)
 			add_root(ctx, node);
 	}
diff -r fedeb23a3d53 -r 1a58b18652a6 src/lib-imap/imap-date.c
--- a/src/lib-imap/imap-date.c	Tue May 27 00:16:12 2008 +0300
+++ b/src/lib-imap/imap-date.c	Tue May 27 02:09:47 2008 +0300
@@ -105,7 +105,7 @@ static bool imap_mktime(struct tm *tm, t
 	return FALSE;
 }
 
-bool imap_parse_date(const char *str, time_t *time)
+bool imap_parse_date(const char *str, time_t *timestamp_r)
 {
 	struct tm tm;
 
@@ -114,11 +114,12 @@ bool imap_parse_date(const char *str, ti
 		return FALSE;
 
 	tm.tm_isdst = -1;
-	(void)imap_mktime(&tm, time);
+	(void)imap_mktime(&tm, timestamp_r);
 	return TRUE;
 }
 
-bool imap_parse_datetime(const char *str, time_t *time, int *timezone_offset)
+bool imap_parse_datetime(const char *str, time_t *timestamp_r,
+			 int *timezone_offset_r)
 {
 	struct tm tm;
 
@@ -149,22 +150,22 @@ bool imap_parse_datetime(const char *str
 	str += 3;
 
 	/* timezone */
-	*timezone_offset = parse_timezone(str);
+	*timezone_offset_r = parse_timezone(str);
 
 	tm.tm_isdst = -1;
-	if (imap_mktime(&tm, time))
-		*time -= *timezone_offset * 60;
+	if (imap_mktime(&tm, timestamp_r))
+		*timestamp_r -= *timezone_offset_r * 60;
 	return TRUE;
 }
 
-const char *imap_to_datetime(time_t time)
+const char *imap_to_datetime(time_t timestamp)
 {
 	char *buf;
 	struct tm *tm;
 	int timezone_offset, year;
 
-	tm = localtime(&time);
-	timezone_offset = utc_offset(tm, time);
+	tm = localtime(&timestamp);
+	timezone_offset = utc_offset(tm, timestamp);
 
 	/* @UNSAFE: but faster than t_strdup_printf() call.. */
 	buf = t_malloc(27);
diff -r fedeb23a3d53 -r 1a58b18652a6 src/lib-imap/imap-date.h
--- a/src/lib-imap/imap-date.h	Tue May 27 00:16:12 2008 +0300
+++ b/src/lib-imap/imap-date.h	Tue May 27 02:09:47 2008 +0300
@@ -8,10 +8,11 @@
    If date is too low or too high to fit to time_t, it's set to lowest/highest
    allowed value. This allows you to use the value directly for comparing
    timestamps. */
-bool imap_parse_date(const char *str, time_t *time);
-bool imap_parse_datetime(const char *str, time_t *time, int *timezone_offset);
+bool imap_parse_date(const char *str, time_t *timestamp_r);
+bool imap_parse_datetime(const char *str, time_t *timestamp_r,
+			 int *timezone_offset_r);
 
 /* Returns given UTC time in local timezone. */
-const char *imap_to_datetime(time_t time);
+const char *imap_to_datetime(time_t timestamp);
 
 #endif
diff -r fedeb23a3d53 -r 1a58b18652a6 src/lib-index/mail-cache-compress.c


More information about the dovecot-cvs mailing list