summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEmmanuele Bassi <ebassi@gnome.org>2015-05-15 12:34:53 +0100
committerEmmanuele Bassi <ebassi@gnome.org>2015-05-19 15:27:29 +0100
commite72a1a44e6e339c55acecba67e2f99412982b832 (patch)
tree2c81ea81cbb0be58fd4217ada39907b67adfcb15
parent5dfd4445e23b662c40e97a9058bcca9899631ff8 (diff)
downloadclutter-e72a1a44e6e339c55acecba67e2f99412982b832.tar.gz
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.
-rw-r--r--clutter/clutter-actor.c30
1 files 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);