[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [52554] trunk/blender/source/blender/ blenlib/BLI_array.h: fix [#33305] Bevel tool crashes Blender if the number of segments exceeds 28
Campbell Barton
ideasman42 at gmail.com
Mon Nov 26 05:58:38 CET 2012
Revision: 52554
http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=52554
Author: campbellbarton
Date: 2012-11-26 04:58:33 +0000 (Mon, 26 Nov 2012)
Log Message:
-----------
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.
Modified Paths:
--------------
trunk/blender/source/blender/blenlib/BLI_array.h
Modified: trunk/blender/source/blender/blenlib/BLI_array.h
===================================================================
--- trunk/blender/source/blender/blenlib/BLI_array.h 2012-11-26 03:47:20 UTC (rev 52553)
+++ trunk/blender/source/blender/blenlib/BLI_array.h 2012-11-26 04:58:33 UTC (rev 52554)
@@ -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,16 +127,9 @@
(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 */
#define BLI_array_grow_one(arr) BLI_array_grow_items(arr, 1)
More information about the Bf-blender-cvs
mailing list