]> git.ipfire.org Git - thirdparty/tor.git/commitdiff
avoid case (not yet triggered) where smartlists could grow out
authorRoger Dingledine <arma@torproject.org>
Sat, 19 Feb 2005 03:02:33 +0000 (03:02 +0000)
committerRoger Dingledine <arma@torproject.org>
Sat, 19 Feb 2005 03:02:33 +0000 (03:02 +0000)
of control

svn:r3636

src/common/container.c

index 4dc0a7ad77df0e31bd559b860f57254a8d4b4178..1824645ad563b42bac0461c3f91c3598019fd88a 100644 (file)
@@ -88,7 +88,9 @@ void smartlist_truncate(smartlist_t *sl, int len)
 /** 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;