From 525bf15f73edcaba6febfc531951409582bfd28d Mon Sep 17 00:00:00 2001 From: Michael Drake Date: Tue, 30 Aug 2011 18:13:23 +0000 Subject: More robustification. svn path=/trunk/netsurf/; revision=12678 --- desktop/scrollbar.c | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) (limited to 'desktop/scrollbar.c') diff --git a/desktop/scrollbar.c b/desktop/scrollbar.c index 3fc36bf18..1c4b46d47 100644 --- a/desktop/scrollbar.c +++ b/desktop/scrollbar.c @@ -412,8 +412,9 @@ void scrollbar_set(struct scrollbar *s, int value, bool bar_pos) else s->bar_pos = value; - s->offset = ((s->full_size - s->visible_size) * (s->bar_pos)) / - (well_length - s->bar_len); + s->offset = ((well_length - s->bar_len) < 1) ? 0 : + (((s->full_size - s->visible_size) * + s->bar_pos) / (well_length - s->bar_len)); } else { if (value > s->full_size - s->visible_size) @@ -421,7 +422,8 @@ void scrollbar_set(struct scrollbar *s, int value, bool bar_pos) else s->offset = value; - s->bar_pos = (well_length * s->offset) / s->full_size; + s->bar_pos = (s->full_size < 1) ? 0 : + ((well_length * s->offset) / s->full_size); } msg.scrollbar = s; @@ -478,8 +480,13 @@ void scrollbar_set_extents(struct scrollbar *s, int length, well_length = s->length - 2 * SCROLLBAR_WIDTH; - s->bar_len = (well_length * s->visible_size) / s->full_size; - s->bar_pos = (well_length * s->offset) / s->full_size; + if (s->full_size < 1) { + s->bar_len = well_length; + s->bar_pos = 0; + } else { + s->bar_len = (well_length * s->visible_size) / s->full_size; + s->bar_pos = (well_length * s->offset) / s->full_size; + } } -- cgit v1.2.3