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

[tor-commits] [tor/maint-0.2.7] Merge branch 'maint-0.2.5' into maint-0.2.6



commit 740421af194b890c24242a834ed03ffc5c4c16ab
Merge: 44ad3be ce289e2
Author: Nick Mathewson <nickm@xxxxxxxxxxxxxx>
Date:   Thu Feb 11 12:57:28 2016 -0500

    Merge branch 'maint-0.2.5' into maint-0.2.6

 changes/bug18162       |  7 +++++++
 src/common/container.c | 37 ++++++++++++++++++++-----------------
 2 files changed, 27 insertions(+), 17 deletions(-)

diff --cc src/common/container.c
index 864fd8a,c668068..76c129d
--- a/src/common/container.c
+++ b/src/common/container.c
@@@ -66,28 -71,22 +71,25 @@@ smartlist_ensure_capacity(smartlist_t *
  #define MAX_CAPACITY (INT_MAX)
  #else
  #define MAX_CAPACITY (int)((SIZE_MAX / (sizeof(void*))))
- #define ASSERT_CAPACITY
  #endif
-   if (size > sl->capacity) {
-     int higher = sl->capacity;
++
+   tor_assert(size <= MAX_CAPACITY);
+ 
+   if (size > (size_t) sl->capacity) {
+     size_t higher = (size_t) sl->capacity;
      if (PREDICT_UNLIKELY(size > MAX_CAPACITY/2)) {
- #ifdef ASSERT_CAPACITY
-       /* We don't include this assertion when MAX_CAPACITY == INT_MAX,
-        * since int size; (size <= INT_MAX) makes analysis tools think we're
-        * doing something stupid. */
--      tor_assert(size <= MAX_CAPACITY);
- #endif
        higher = MAX_CAPACITY;
      } else {
        while (size > higher)
          higher *= 2;
      }
-     sl->capacity = higher;
+     tor_assert(higher <= INT_MAX); /* Redundant */
+     sl->capacity = (int) higher;
 -    sl->list = tor_realloc(sl->list, sizeof(void*)*((size_t)sl->capacity));
 +    sl->list = tor_reallocarray(sl->list, sizeof(void *),
 +                                ((size_t)sl->capacity));
    }
 +#undef ASSERT_CAPACITY
 +#undef MAX_CAPACITY
  }
  
  /** Append element to the end of the list. */



_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits