From cc684469dfd56079949a0b0377b606502d68bbf3 Mon Sep 17 00:00:00 2001 From: John Mark Bell Date: Tue, 7 Aug 2007 07:58:04 +0000 Subject: Fix division by 0 caused by uninitialised scale value. Break out initialisation of common parts of struct browser_window into their own function. svn path=/trunk/netsurf/; revision=3481 --- desktop/browser.c | 51 +++++++++++++++++++++++++++++++++++---------------- desktop/browser.h | 2 ++ desktop/frames.c | 14 ++++---------- 3 files changed, 41 insertions(+), 26 deletions(-) (limited to 'desktop') diff --git a/desktop/browser.c b/desktop/browser.c index a55932ab4..b1c4d92c1 100644 --- a/desktop/browser.c +++ b/desktop/browser.c @@ -136,22 +136,10 @@ struct browser_window *browser_window_create(const char *url, return NULL; } - /* content */ - if (!clone) - bw->history = history_create(); - else - bw->history = history_clone(clone->history); - if (!clone || (clone && !clone->gesturer)) - bw->gesturer = NULL; - else - bw->gesturer = gesturer_clone(clone->gesturer); + /* Initialise common parts */ + browser_window_initialise_common(bw, clone); /* window characteristics */ - bw->sel = selection_create(bw); - bw->refresh_interval = -1; - bw->reformat_pending = false; - bw->drag_type = DRAGGING_NONE; - bw->scale = (float) option_scale / 100.0; bw->browser_window_type = BROWSER_WINDOW_NORMAL; bw->scrolling = SCROLLING_YES; bw->border = true; @@ -169,6 +157,37 @@ struct browser_window *browser_window_create(const char *url, } +/** + * Initialise common parts of a browser window + * + * \param bw The window to initialise + * \param clone The window to clone, or NULL if none + */ +void browser_window_initialise_common(struct browser_window *bw, + struct browser_window *clone) +{ + assert(bw); + + if (!clone) + bw->history = history_create(); + else + bw->history = history_clone(clone->history); + + if (!clone || (clone && !clone->gesturer)) + bw->gesturer = NULL; + else + bw->gesturer = gesturer_clone(clone->gesturer); + + /* window characteristics */ + bw->sel = selection_create(bw); + bw->refresh_interval = -1; + + bw->reformat_pending = false; + bw->drag_type = DRAGGING_NONE; + bw->scale = (float) option_scale / 100.0; +} + + /** * Start fetching a page in a browser window. * @@ -1073,14 +1092,14 @@ struct browser_window *browser_window_find_target(struct browser_window *bw, con browser_window_find_target_internal(top, target, 0, bw, &rdepth, &bw_target); if (bw_target) return bw_target; - + /* we require a new window using the target name */ if (!option_target_blank) return bw; bw_target = browser_window_create(NULL, bw, NULL, false); if (!bw_target) return bw; - + /* frame names should begin with an alphabetic character (a-z,A-Z), however in * practice you get things such as '_new' and '2left'. The only real effect this * has is when giving out names as it can be assumed that an author intended '_new' diff --git a/desktop/browser.h b/desktop/browser.h index 3e1285324..1e1bf7704 100644 --- a/desktop/browser.h +++ b/desktop/browser.h @@ -188,6 +188,8 @@ extern bool browser_reformat_pending; struct browser_window * browser_window_create(const char *url, struct browser_window *clone, const char *referer, bool history_add); +void browser_window_initialise_common(struct browser_window *bw, + struct browser_window *clone); void browser_window_go(struct browser_window *bw, const char *url, const char *referer, bool history_add); void browser_window_go_unverifiable(struct browser_window *bw, diff --git a/desktop/frames.c b/desktop/frames.c index cd2dc9e21..b0f6a7ea8 100644 --- a/desktop/frames.c +++ b/desktop/frames.c @@ -66,13 +66,10 @@ void browser_window_create_iframes(struct browser_window *bw, for (cur = iframe; cur; cur = cur->next) { window = &(bw->iframes[index++]); - /* content */ - window->history = history_create(); - window->sel = selection_create(window); - window->refresh_interval = -1; + /* Initialise common parts */ + browser_window_initialise_common(window, NULL); /* window characteristics */ - window->drag_type = DRAGGING_NONE; window->browser_window_type = BROWSER_WINDOW_IFRAME; window->scrolling = cur->scrolling; window->border = cur->border; @@ -171,13 +168,10 @@ void browser_window_create_frameset(struct browser_window *bw, frame = &frameset->children[index]; window = &bw->children[index]; - /* content */ - window->history = history_create(); - window->sel = selection_create(window); - window->refresh_interval = -1; + /* Initialise common parts */ + browser_window_initialise_common(window, NULL); /* window characteristics */ - window->drag_type = DRAGGING_NONE; if (frame->children) window->browser_window_type = BROWSER_WINDOW_FRAMESET; -- cgit v1.2.3