[dovecot-cvs] dovecot/src/lib buffer.c,1.3,1.4

cras at procontrol.fi cras at procontrol.fi
Sat Dec 21 23:56:17 EET 2002


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

Modified Files:
	buffer.c 
Log Message:
Last update broke used size.



Index: buffer.c
===================================================================
RCS file: /home/cvs/dovecot/src/lib/buffer.c,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -d -r1.3 -r1.4
--- buffer.c	21 Dec 2002 19:10:35 -0000	1.3
+++ buffer.c	21 Dec 2002 21:56:15 -0000	1.4
@@ -27,11 +27,14 @@
 #include "buffer.h"
 
 struct _Buffer {
-	Pool pool;
-
+	/* public for String: */
 	const unsigned char *r_buffer;
+	size_t used;
+
+	/* private: */
+	Pool pool;
 	unsigned char *w_buffer;
-	size_t used, alloc, max_alloc, limit, start_pos;
+	size_t alloc, max_alloc, limit, start_pos;
 
 	unsigned int alloced:1;
 	unsigned int readonly:1;
@@ -72,7 +75,7 @@
 static int buffer_check_write(Buffer *buf, size_t *pos, size_t *data_size,
 			      int accept_partial)
 {
-	size_t max_size, new_size;
+	size_t max_size, new_size, alloc_size;
 
 	if (buf->readonly)
 		return FALSE;
@@ -94,24 +97,29 @@
 
 	/* see if we need to grow the buffer */
 	if (new_size > buf->alloc) {
-		if (new_size > buf->limit) {
+		alloc_size = nearest_power(new_size);
+		if (alloc_size > buf->limit) {
 			if (buf->hard) {
 				i_panic("Buffer full (%"PRIuSIZE_T" > "
-					"%"PRIuSIZE_T")", new_size, buf->limit);
+					"%"PRIuSIZE_T")",
+					alloc_size, buf->limit);
 			}
 
 			if (!accept_partial)
 				return FALSE;
 
-			new_size = buf->limit;
-			if (*pos >= new_size)
+			alloc_size = buf->limit;
+			if (*pos >= alloc_size)
 				return FALSE;
 
-			*data_size = new_size - *pos;
+			*data_size = alloc_size - *pos;
 		}
 
-		if (new_size != buf->alloc)
-			buffer_alloc(buf, new_size);
+		if (new_size > alloc_size)
+			new_size = alloc_size;
+
+		if (alloc_size != buf->alloc)
+			buffer_alloc(buf, alloc_size);
 	}
 
 	if (new_size > buf->used)




More information about the dovecot-cvs mailing list