From: Behdad Esfahbod Date: Mon, 2 May 2011 23:54:29 +0000 (-0400) Subject: Fix bug in array growth implementation X-Git-Tag: submit/2.0alpha-wayland/20121130.004132~9^2~271 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=5a5030366e40baa8d96ca67b47a52ad5af143157;p=profile%2Fivi%2Forg.tizen.video-player.git Fix bug in array growth implementation With this, test/object is now passing. Yay! --- diff --git a/src/hb-private.hh b/src/hb-private.hh index dc47000..02fc099 100644 --- a/src/hb-private.hh +++ b/src/hb-private.hh @@ -294,30 +294,28 @@ struct hb_static_array_t { } if (likely (len < allocated)) return &array[len++]; + /* Need to reallocate */ unsigned int new_allocated = allocated + (allocated >> 1) + 8; - Type *new_array; + Type *new_array = NULL; + if (array == static_array) { new_array = (Type *) calloc (new_allocated, sizeof (Type)); - if (new_array) { + if (new_array) memcpy (new_array, array, len * sizeof (Type)); - array = new_array; - } } else { bool overflows = (new_allocated < allocated) || _hb_unsigned_int_mul_overflows (new_allocated, sizeof (Type)); - if (unlikely (overflows)) - new_array = NULL; - else + if (likely (!overflows)) { new_array = (Type *) realloc (array, new_allocated * sizeof (Type)); - if (new_array) { - free (array); - array = new_array; } } - if ((len < allocated)) - return &array[len++]; - else + + if (unlikely (!new_array)) return NULL; + + array = new_array; + allocated = new_allocated; + return &array[len++]; } inline void pop (void)