diff --git a/dlls/d2d1/d2d1_private.h b/dlls/d2d1/d2d1_private.h index 2c1025264dd..07f71a0a608 100644 --- a/dlls/d2d1/d2d1_private.h +++ b/dlls/d2d1/d2d1_private.h @@ -62,8 +62,8 @@ extern struct d2d_settings d2d_settings DECLSPEC_HIDDEN; struct d2d_clip_stack { D2D1_RECT_F *stack; - unsigned int size; - unsigned int count; + size_t size; + size_t count; }; struct d2d_error_state @@ -486,6 +486,32 @@ static inline void *d2d_calloc(size_t count, size_t size) return heap_alloc(s); } +static inline BOOL d2d_array_reserve(void **elements, size_t *capacity, size_t count, size_t size) +{ + size_t new_capacity, max_capacity; + void *new_elements; + + if (count <= *capacity) + return TRUE; + + max_capacity = ~(SIZE_T)0 / size; + if (count > max_capacity) + return FALSE; + + new_capacity = max(4, *capacity); + while (new_capacity < count && new_capacity <= max_capacity / 2) + new_capacity *= 2; + if (new_capacity < count) + new_capacity = max_capacity; + + if (!(new_elements = heap_realloc(*elements, new_capacity * size))) + return FALSE; + + *elements = new_elements; + *capacity = new_capacity; + return TRUE; +} + static inline void d2d_matrix_multiply(D2D_MATRIX_3X2_F *a, const D2D_MATRIX_3X2_F *b) { D2D_MATRIX_3X2_F tmp = *a; diff --git a/dlls/d2d1/geometry.c b/dlls/d2d1/geometry.c index c8050849784..4a2f7d7ac85 100644 --- a/dlls/d2d1/geometry.c +++ b/dlls/d2d1/geometry.c @@ -562,33 +562,6 @@ static void d2d_rect_get_bezier_segment_bounds(D2D_RECT_F *bounds, const D2D1_PO d2d_rect_get_bezier_bounds(bounds, &q[0], &q[1], &q[2]); } -static BOOL d2d_array_reserve(void **elements, size_t *capacity, size_t element_count, size_t element_size) -{ - size_t new_capacity, max_capacity; - void *new_elements; - - if (element_count <= *capacity) - return TRUE; - - max_capacity = ~(size_t)0 / element_size; - if (max_capacity < element_count) - return FALSE; - - new_capacity = max(*capacity, 4); - while (new_capacity < element_count && new_capacity <= max_capacity / 2) - new_capacity *= 2; - - if (new_capacity < element_count) - new_capacity = max_capacity; - - if (!(new_elements = heap_realloc(*elements, new_capacity * element_size))) - return FALSE; - - *elements = new_elements; - *capacity = new_capacity; - return TRUE; -} - static BOOL d2d_figure_insert_vertex(struct d2d_figure *figure, size_t idx, D2D1_POINT_2F vertex) { if (!d2d_array_reserve((void **)&figure->vertices, &figure->vertices_size, diff --git a/dlls/d2d1/render_target.c b/dlls/d2d1/render_target.c index cc820cf8a98..a202279c7d4 100644 --- a/dlls/d2d1/render_target.c +++ b/dlls/d2d1/render_target.c @@ -95,21 +95,8 @@ static BOOL d2d_clip_stack_push(struct d2d_clip_stack *stack, const D2D1_RECT_F { D2D1_RECT_F r; - if (stack->count == stack->size) - { - D2D1_RECT_F *new_stack; - unsigned int new_size; - - if (stack->size > UINT_MAX / 2) - return FALSE; - - new_size = stack->size * 2; - if (!(new_stack = heap_realloc(stack->stack, new_size * sizeof(*stack->stack)))) - return FALSE; - - stack->stack = new_stack; - stack->size = new_size; - } + if (!d2d_array_reserve((void **)&stack->stack, &stack->size, stack->count + 1, sizeof(*stack->stack))) + return FALSE; r = *rect; if (stack->count)