From e72a1a44e6e339c55acecba67e2f99412982b832 Mon Sep 17 00:00:00 2001 From: Emmanuele Bassi Date: Fri, 15 May 2015 12:34:53 +0100 Subject: [PATCH] actor: Ensure allocation adjustment is safe against zero sizes We already copy with negative end results, but there's no point in doing the work in the first place. --- clutter/clutter-actor.c | 30 ++++++++++++++++++++++++++---- 1 file changed, 26 insertions(+), 4 deletions(-) diff --git a/clutter/clutter-actor.c b/clutter/clutter-actor.c index 203256765..cffc61b83 100644 --- a/clutter/clutter-actor.c +++ b/clutter/clutter-actor.c @@ -9203,10 +9203,25 @@ adjust_for_margin (float margin_start, float *allocated_start, float *allocated_end) { - *minimum_size -= (margin_start + margin_end); - *natural_size -= (margin_start + margin_end); - *allocated_start += margin_start; - *allocated_end -= margin_end; + float min_size = *minimum_size; + float nat_size = *natural_size; + float start = *allocated_start; + float end = *allocated_end; + + min_size = MAX (min_size - (margin_start + margin_end), 0); + nat_size = MAX (nat_size - (margin_start + margin_end), 0); + + *minimum_size = min_size; + *natural_size = nat_size; + + start += margin_start; + end -= margin_end; + + if (end - start >= 0) + { + *allocated_start = start; + *allocated_end = end; + } } static inline void @@ -9217,6 +9232,9 @@ adjust_for_alignment (ClutterActorAlign alignment, { float allocated_size = *allocated_end - *allocated_start; + if (allocated_size <= 0.f) + return; + switch (alignment) { case CLUTTER_ACTOR_ALIGN_FILL: @@ -9805,6 +9823,10 @@ clutter_actor_adjust_allocation (ClutterActor *self, clutter_actor_box_get_size (allocation, &alloc_width, &alloc_height); + /* There's no point in trying to adjust a zero-sized actor */ + if (alloc_width == 0.f && alloc_height == 0.f) + return; + /* we want to hit the cache, so we use the public API */ req_mode = clutter_actor_get_request_mode (self);