Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCampbell Barton <ideasman42@gmail.com>2012-11-26 08:58:33 +0400
committerCampbell Barton <ideasman42@gmail.com>2012-11-26 08:58:33 +0400
commit6857d3118063caca392e1dd4034bca24e2f125cb (patch)
treef9cdd225f99dd460a091febd04190d89aa6aadc3 /source/blender/blenlib/BLI_array.h
parente77e1f183ae6732eadda82ba1d7ab9975a9224f8 (diff)
fix [#33305] Bevel tool crashes Blender if the number of segments exceeds 28
this was infact a general bug in BLI_array_grow_items(), surprising we didnt run into it before. - growing the array for the first time would use the static var even if it wasn't big enough.
Diffstat (limited to 'source/blender/blenlib/BLI_array.h')
-rw-r--r--source/blender/blenlib/BLI_array.h27
1 files changed, 16 insertions, 11 deletions
diff --git a/source/blender/blenlib/BLI_array.h b/source/blender/blenlib/BLI_array.h
index 84cfe89f1b8..a21778307c1 100644
--- a/source/blender/blenlib/BLI_array.h
+++ b/source/blender/blenlib/BLI_array.h
@@ -77,11 +77,13 @@
MEM_allocN_len(arr) / sizeof(*arr) \
)
+#define _bli_array_totalsize_static(arr) \
+ (sizeof(_##arr##_static) / sizeof(*arr))
#define BLI_array_totalsize(arr) ( \
(size_t) \
(((void *)(arr) == (void *)_##arr##_static && (void *)(arr) != NULL) ? \
- (sizeof(_##arr##_static) / sizeof(*arr)) : \
+ _bli_array_totalsize_static(arr) : \
BLI_array_totalsize_dyn(arr)) \
)
@@ -93,8 +95,18 @@
*
* Allow for a large 'num' value when the new size is more then double
* to allocate the exact sized array. */
-#define _bli_array_grow_items(arr, num) ( \
- (BLI_array_totalsize(arr) >= _##arr##_count + num) ? \
+
+/* grow an array by a specified number of items */
+#define BLI_array_grow_items(arr, num) ( \
+ (((void *)(arr) == NULL) && \
+ ((void *)(_##arr##_static) != NULL) && \
+ /* dont add _##arr##_count below because it must be zero */ \
+ (_bli_array_totalsize_static(arr) >= _##arr##_count + num)) ? \
+ /* we have an empty array and a static var big enough */ \
+ ((arr = (void *)_##arr##_static), (_##arr##_count += (num))) \
+ : \
+ /* use existing static array or allocate */ \
+ ((BLI_array_totalsize(arr) >= _##arr##_count + num) ? \
(_##arr##_count += num) : \
( \
(void) (_##arr##_tmp = MEM_callocN( \
@@ -115,14 +127,7 @@
(void) (arr = _##arr##_tmp \
), \
(_##arr##_count += num) \
- ) \
-)
-
-/* grow an array by a specified number of items */
-#define BLI_array_grow_items(arr, num) ( \
- ((void *)(arr) == NULL && (void *)(_##arr##_static) != NULL) ? \
- ((arr = (void *)_##arr##_static), (_##arr##_count += num)) : \
- _bli_array_grow_items(arr, num) \
+ )) \
)
/* returns length of array */