[dovecot-cvs] dovecot/src/lib data-stack.c,1.3,1.4 data-stack.h,1.3,1.4 ioloop-poll.c,1.2,1.3 ioloop.c,1.6,1.7 temp-string.c,1.4,1.5

cras at procontrol.fi cras at procontrol.fi
Mon Oct 28 06:50:16 EET 2002


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

Modified Files:
	data-stack.c data-stack.h ioloop-poll.c ioloop.c temp-string.c 
Log Message:
changed t_push() and t_pop() to return unsigned int. added global
data_stack_frame which is used by TempString to verify it's accessed only
in the same frame.



Index: data-stack.c
===================================================================
RCS file: /home/cvs/dovecot/src/lib/data-stack.c,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -d -r1.3 -r1.4
--- data-stack.c	13 Oct 2002 23:49:11 -0000	1.3
+++ data-stack.c	28 Oct 2002 04:50:14 -0000	1.4
@@ -70,6 +70,8 @@
 	size_t last_alloc_size[BLOCK_FRAME_COUNT];
 };
 
+unsigned int data_stack_frame;
+
 static int frame_pos; /* current frame position current_frame_block */
 static StackFrameBlock *current_frame_block; /* current stack frame block */
 static StackFrameBlock *unused_frame_blocks; /* unused stack frames */
@@ -80,7 +82,7 @@
 static StackBlock *last_buffer_block;
 static size_t last_buffer_size;
 
-int t_push(void)
+unsigned int t_push(void)
 {
         StackFrameBlock *frame_block;
 
@@ -108,7 +110,7 @@
 	current_frame_block->block_space_used[frame_pos] = current_block->left;
         current_frame_block->last_alloc_size[frame_pos] = 0;
 
-        return frame_pos;
+        return data_stack_frame++;
 }
 
 static void free_blocks(StackBlock *block)
@@ -127,7 +129,7 @@
 	}
 }
 
-int t_pop(void)
+unsigned int t_pop(void)
 {
 	StackFrameBlock *frame_block;
 	int popped_frame_pos;
@@ -159,7 +161,7 @@
 		unused_frame_blocks = frame_block;
 	}
 
-        return popped_frame_pos;
+        return --data_stack_frame;
 }
 
 static StackBlock *mem_block_alloc(size_t min_size)
@@ -309,6 +311,8 @@
 
 void data_stack_init(void)
 {
+        data_stack_frame = 0;
+
 	current_block = mem_block_alloc(INITIAL_STACK_SIZE);
 	current_block->left = current_block->size;
 	current_block->next = NULL;
@@ -356,11 +360,10 @@
 	void *mem;
 };
 
-static int stack_counter;
 static StackFrame *current_frame;
 static void *buffer_mem;
 
-int t_push(void)
+unsigned int t_push(void)
 {
 	StackFrame *frame;
 
@@ -371,10 +374,10 @@
 
 	frame->next = current_frame;
 	current_frame = frame;
-	return stack_counter++;
+	return data_stack_frame++;
 }
 
-int t_pop(void)
+unsigned int t_pop(void)
 {
 	StackFrame *frame;
 	FrameAlloc *alloc;
@@ -391,7 +394,7 @@
 	}
 
 	free(frame);
-	return --stack_counter;
+	return --data_stack_frame;
 }
 
 static void add_alloc(void *mem)
@@ -479,7 +482,7 @@
 
 void data_stack_init(void)
 {
-        stack_counter = 0;
+        data_stack_frame = 0;
 	current_frame = NULL;
 	buffer_mem = NULL;
 
@@ -490,7 +493,7 @@
 {
 	t_pop();
 
-	if (stack_counter != 0)
+	if (data_stack_frame != 0)
 		i_panic("Missing t_pop() call");
 }
 

Index: data-stack.h
===================================================================
RCS file: /home/cvs/dovecot/src/lib/data-stack.h,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -d -r1.3 -r1.4
--- data-stack.h	9 Oct 2002 20:49:07 -0000	1.3
+++ data-stack.h	28 Oct 2002 04:50:14 -0000	1.4
@@ -32,16 +32,16 @@
       slower.
 */
 
+extern unsigned int data_stack_frame;
+
 /* All t_..() allocations between t_push() and t_pop() are free'd
    after t_pop() is called. Returns stack frame number which can be used
    to detect missing t_pop() calls:
 
    x = t_push(); .. if (t_pop() != x) abort();
-
-   Note that the frame number wraps at some point (but t_pop() wraps it back).
 */
-int t_push(void);
-int t_pop(void);
+unsigned int t_push(void);
+unsigned int t_pop(void);
 
 /* WARNING: Be careful when using this functions, it's too easy to
    accidentally save the returned value somewhere permanently.

Index: ioloop-poll.c
===================================================================
RCS file: /home/cvs/dovecot/src/lib/ioloop-poll.c,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -d -r1.2 -r1.3
--- ioloop-poll.c	22 Aug 2002 12:48:38 -0000	1.2
+++ ioloop-poll.c	28 Oct 2002 04:50:14 -0000	1.3
@@ -139,7 +139,8 @@
         struct pollfd *pollfd;
         struct timeval tv;
 	IO io, next;
-	int msecs, ret, t_id;
+	unsigned int t_id;
+	int msecs, ret;
 
         data = ioloop->handler_data;
 

Index: ioloop.c
===================================================================
RCS file: /home/cvs/dovecot/src/lib/ioloop.c,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -d -r1.6 -r1.7
--- ioloop.c	24 Oct 2002 00:15:38 -0000	1.6
+++ ioloop.c	28 Oct 2002 04:50:14 -0000	1.7
@@ -252,7 +252,7 @@
 {
 	Timeout t, next;
 	struct timeval tv;
-        int t_id;
+        unsigned int t_id;
 
 	gettimeofday(&ioloop_timeval, &ioloop_timezone);
 	ioloop_time = ioloop_timeval.tv_sec;

Index: temp-string.c
===================================================================
RCS file: /home/cvs/dovecot/src/lib/temp-string.c,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -d -r1.4 -r1.5
--- temp-string.c	9 Oct 2002 20:49:07 -0000	1.4
+++ temp-string.c	28 Oct 2002 04:50:14 -0000	1.5
@@ -33,6 +33,7 @@
 	size_t len;
 
 	size_t alloc_size;
+	unsigned int data_stack_frame;
 } RealTempString;
 
 TempString *t_string_new(size_t initial_size)
@@ -43,6 +44,7 @@
 		initial_size = 64;
 
 	rstr = t_new(RealTempString, 1);
+	rstr->data_stack_frame = data_stack_frame;
 	rstr->alloc_size = initial_size;
 	rstr->str = t_malloc(rstr->alloc_size);
 	rstr->str[0] = '\0';
@@ -54,6 +56,8 @@
 	RealTempString *rstr = (RealTempString *) tstr;
 	char *str;
 
+	i_assert(data_stack_frame == rstr->data_stack_frame);
+
 	size += rstr->len + 1;
 	if (size <= rstr->len || size > SSIZE_T_MAX) {
 		/* overflow */
@@ -111,6 +115,9 @@
 
 void t_string_erase(TempString *tstr, size_t pos, size_t len)
 {
+	RealTempString *rstr = (RealTempString *) tstr;
+
+	i_assert(data_stack_frame == rstr->data_stack_frame);
 	i_assert(pos < tstr->len && tstr->len - pos >= len);
 
 	memmove(tstr->str + pos + len, tstr->str + pos,
@@ -119,6 +126,9 @@
 
 void t_string_truncate(TempString *tstr, size_t len)
 {
+	RealTempString *rstr = (RealTempString *) tstr;
+
+	i_assert(data_stack_frame == rstr->data_stack_frame);
 	i_assert(len <= tstr->len);
 
 	tstr->len = len;




More information about the dovecot-cvs mailing list