From 313e5cabba172c79a0a8d2bab0b8a99c204616fc Mon Sep 17 00:00:00 2001 From: Vincent Sanders Date: Sun, 12 Jul 2020 13:47:52 +0100 Subject: ensure the html layout is present for text selection The text selection operations can be called regardless of when the html layout box tree is actually available (e.g. if it is still loading when opened) This change ensures the layout box tree is available before attempting to traverse it for a selection operation. --- content/handlers/html/textselection.c | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/content/handlers/html/textselection.c b/content/handlers/html/textselection.c index 51c6ce1a9..cc08aeff2 100644 --- a/content/handlers/html/textselection.c +++ b/content/handlers/html/textselection.c @@ -444,7 +444,11 @@ selection_copy(struct box *box, */ static unsigned selection_label_subtree(struct box *box, unsigned idx) { - struct box *child = box->children; + struct box *child; + + assert(box != NULL); + + box = box->children; box->byte_offset = idx; @@ -475,6 +479,10 @@ html_textselection_redraw(struct content *c, html_content *html = (html_content *)c; struct rdw_info rdw; + if (html->layout == NULL) { + return NSERROR_INVALID; + } + rdw.inited = false; res = coords_from_range(html->layout, start_idx, end_idx, &rdw, false); @@ -505,6 +513,10 @@ html_textselection_copy(struct content *c, save_text_whitespace before = WHITESPACE_NONE; bool first = true; + if (html->layout == NULL) { + return NSERROR_INVALID; + } + return selection_copy(html->layout, &html->len_ctx, start_idx, @@ -523,6 +535,10 @@ html_textselection_get_end(struct content *c, unsigned *end_idx) html_content *html = (html_content *)c; unsigned root_idx; + if (html->layout == NULL) { + return NSERROR_INVALID; + } + root_idx = 0; *end_idx = selection_label_subtree(html->layout, root_idx); -- cgit v1.2.3