[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[or-cvs] avoid case (not yet triggered) where smartlists could grow ...



Update of /home2/or/cvsroot/tor/src/common
In directory moria.mit.edu:/home2/arma/work/onion/cvs/tor/src/common

Modified Files:
	container.c 
Log Message:
avoid case (not yet triggered) where smartlists could grow out
of control


Index: container.c
===================================================================
RCS file: /home2/or/cvsroot/tor/src/common/container.c,v
retrieving revision 1.17
retrieving revision 1.18
diff -u -d -r1.17 -r1.18
--- container.c	31 Jan 2005 00:24:59 -0000	1.17
+++ container.c	19 Feb 2005 03:02:33 -0000	1.18
@@ -88,7 +88,9 @@
 /** Append element to the end of the list. */
 void smartlist_add(smartlist_t *sl, void *element) {
   if (sl->num_used >= sl->capacity) {
-    sl->capacity *= 2;
+    int higher = sl->capacity * 2;
+    tor_assert(higher > sl->capacity); /* detect overflow */
+    sl->capacity = higher;
     sl->list = tor_realloc(sl->list, sizeof(void*)*sl->capacity);
   }
   sl->list[sl->num_used++] = element;