[dovecot-cvs] dovecot/src/lib-index mail-index-open.c,1.20,1.21

cras at procontrol.fi cras at procontrol.fi
Thu Dec 19 03:02:37 EET 2002


Update of /home/cvs/dovecot/src/lib-index
In directory danu:/tmp/cvs-serv11467/lib-index

Modified Files:
	mail-index-open.c 
Log Message:
Buffer related cleanups. Use PATH_MAX instead of hardcoded 1024 for paths.
Added str_path() and str_ppath() functions. i_snprintf() now returns only -1
or 0 depending on if buffer got full. dec2str() returns the string allocated
from data stack. Instead of just casting to (long) or (int), we now use
dec2str() with printf-like functions. Added o_stream_send_str(). Added
strocpy() and replaced all strcpy()s and strncpy()s with it.

Pretty much untested, hope it doesn't break too badly :)



Index: mail-index-open.c
===================================================================
RCS file: /home/cvs/dovecot/src/lib-index/mail-index-open.c,v
retrieving revision 1.20
retrieving revision 1.21
diff -u -d -r1.20 -r1.21
--- mail-index-open.c	26 Nov 2002 19:49:17 -0000	1.20
+++ mail-index-open.c	19 Dec 2002 01:02:35 -0000	1.21
@@ -26,7 +26,7 @@
 
 static int delete_index(const char *path)
 {
-	char tmp[1024];
+	char tmp[PATH_MAX];
 	int i;
 
 	/* main index */
@@ -34,8 +34,10 @@
 		return FALSE;
 
 	for (i = 0; index_file_prefixes[i] != NULL; i++) {
-		i_snprintf(tmp, sizeof(tmp), "%s.%s",
-			   path, index_file_prefixes[i]);
+		if (i_snprintf(tmp, sizeof(tmp), "%s.%s",
+			       path, index_file_prefixes[i]) < 0)
+			return FALSE;
+
 		if (unlink(tmp) < 0)
 			return FALSE;
 		i++;
@@ -95,20 +97,20 @@
 static const char *mail_find_index(MailIndex *index)
 {
 	const char *name;
-	char path[1024];
+	char path[PATH_MAX];
 
 	hostpid_init();
 
 	/* first try .imap.index-<hostname> */
 	name = t_strconcat(INDEX_FILE_PREFIX "-", my_hostname, NULL);
-	i_snprintf(path, sizeof(path), "%s/%s", index->dir, name);
-	if (mail_check_compatible_index(index, path))
+	if (str_path(path, sizeof(path), index->dir, name) == 0 &&
+	    mail_check_compatible_index(index, path))
 		return name;
 
 	/* then try the generic .imap.index */
 	name = INDEX_FILE_PREFIX;
-	i_snprintf(path, sizeof(path), "%s/%s", index->dir, name);
-	if (mail_check_compatible_index(index, path))
+	if (str_path(path, sizeof(path), index->dir, name) == 0 &&
+	    mail_check_compatible_index(index, path))
 		return name;
 
 	return NULL;




More information about the dovecot-cvs mailing list