[dovecot-cvs] dovecot/src/lib ostream-file.c,1.39,1.40

cras at dovecot.org cras at dovecot.org
Sat Oct 16 19:32:12 EEST 2004


Update of /var/lib/cvs/dovecot/src/lib
In directory talvi:/tmp/cvs-serv17486

Modified Files:
	ostream-file.c 
Log Message:
Growing output buffer size broke the data inside it.



Index: ostream-file.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib/ostream-file.c,v
retrieving revision 1.39
retrieving revision 1.40
diff -u -d -r1.39 -r1.40
--- ostream-file.c	15 Oct 2004 13:03:11 -0000	1.39
+++ ostream-file.c	16 Oct 2004 16:32:09 -0000	1.40
@@ -296,7 +296,7 @@
 
 static void o_stream_grow_buffer(struct file_ostream *fstream, size_t bytes)
 {
-	size_t size, head_size, new_size;
+	size_t size, new_size, end_size;
 
 	size = nearest_power(fstream->buffer_size + bytes);
 	if (size > fstream->max_buffer_size) {
@@ -318,17 +318,11 @@
 				    fstream->buffer_size, size);
 
 	if (fstream->tail <= fstream->head && !IS_STREAM_EMPTY(fstream)) {
-		head_size = I_MIN(fstream->head, size - fstream->buffer_size);
-		memcpy(fstream->buffer + fstream->buffer_size, fstream->buffer,
-		       head_size);
-
-		if (head_size == fstream->head)
-			fstream->tail = fstream->buffer_size + head_size;
-		else {
-			memmove(fstream->buffer, fstream->buffer + head_size,
-				fstream->head - head_size);
-			fstream->tail = fstream->head - head_size;
-		}
+		/* move head forward to end of buffer */
+		end_size = fstream->buffer_size - fstream->head;
+		memmove(fstream->buffer + size - end_size,
+			fstream->buffer + fstream->head, end_size);
+		fstream->head = size - end_size;
 	}
 
 	fstream->full = FALSE;



More information about the dovecot-cvs mailing list