r7645 jmb - /trunk/netsurf/riscos/wimp.c
by netsurf@semichrome.net
Author: jmb
Date: Fri May 29 19:26:04 2009
New Revision: 7645
URL: http://source.netsurf-browser.org?rev=7645&view=rev
Log:
Stop ro_gui_get_icon_string() returning a pointer to a location on the stack.
Make explicit the semantics that strings returned from this call are transient
and will be invalidated by subsequent calls.
Modified:
trunk/netsurf/riscos/wimp.c
Modified: trunk/netsurf/riscos/wimp.c
URL: http://source.netsurf-browser.org/trunk/netsurf/riscos/wimp.c?rev=7645&r1...
==============================================================================
--- trunk/netsurf/riscos/wimp.c (original)
+++ trunk/netsurf/riscos/wimp.c Fri May 29 19:26:04 2009
@@ -220,12 +220,18 @@
* \param i icon handle
* \return NUL terminated string in icon
*
+ * If the icon contains direct text then the returned data will
+ * be invalidated by the next call to this function. Therefore,
+ * all client calls to this function must either copy the string or
+ * ensure that this function is not called again until they are
+ * finished with the string data returned.
+ *
* \todo this doesn't do local encoding -> UTF-8 to match what is done in
* ro_gui_set_icon_string.
*/
const char *ro_gui_get_icon_string(wimp_w w, wimp_i i)
{
- wimp_icon_state ic;
+ static wimp_icon_state ic;
os_error *error;
char *itext;
@@ -238,12 +244,11 @@
warn_user("WimpError", error->errmess);
return NULL;
}
- itext = (ic.icon.flags & wimp_ICON_INDIRECTED) ?
- ic.icon.data.indirected_text.text
- :
- ic.icon.data.text;
+ itext = (ic.icon.flags & wimp_ICON_INDIRECTED)
+ ? ic.icon.data.indirected_text.text : ic.icon.data.text;
/* Guarantee NUL termination. */
itext[ro_gui_strlen(itext)] = '\0';
+
return itext;
}
13 years, 8 months
r7644 jmb - /trunk/netsurf/riscos/url_complete.c
by netsurf@semichrome.net
Author: jmb
Date: Fri May 29 19:23:07 2009
New Revision: 7644
URL: http://source.netsurf-browser.org?rev=7644&view=rev
Log:
Simplify code
Modified:
trunk/netsurf/riscos/url_complete.c
Modified: trunk/netsurf/riscos/url_complete.c
URL: http://source.netsurf-browser.org/trunk/netsurf/riscos/url_complete.c?rev...
==============================================================================
--- trunk/netsurf/riscos/url_complete.c (original)
+++ trunk/netsurf/riscos/url_complete.c Fri May 29 19:23:07 2009
@@ -689,10 +689,9 @@
g->toolbar->toolbar_handle,
ICON_TOOLBAR_URL);
free(url_complete_original_url);
- url_complete_original_url = malloc(strlen(url) + 1);
+ url_complete_original_url = strdup(url));
if (!url_complete_original_url)
return false;
- strcpy(url_complete_original_url, url);
}
old_selection = url_complete_matches_selection;
url_complete_matches_selection = selection;
13 years, 8 months
r7643 jmb - /trunk/netsurf/riscos/menus.c
by netsurf@semichrome.net
Author: jmb
Date: Fri May 29 18:43:53 2009
New Revision: 7643
URL: http://source.netsurf-browser.org?rev=7643&view=rev
Log:
A bunch of tidying. Also squash NULL-pointer dereferences.
Modified:
trunk/netsurf/riscos/menus.c
Modified: trunk/netsurf/riscos/menus.c
URL: http://source.netsurf-browser.org/trunk/netsurf/riscos/menus.c?rev=7643&r...
==============================================================================
--- trunk/netsurf/riscos/menus.c (original)
+++ trunk/netsurf/riscos/menus.c Fri May 29 18:43:53 2009
@@ -662,12 +662,12 @@
int previous_menu_icon = current_menu_icon;
char *url;
-
/* if we are using gui_multitask then menu selection events
* may be delivered after the menu has been closed. As such,
* we simply ignore these events. */
if (!current_menu)
return
+
assert(current_menu_window);
/* get the menu entry and associated action */
@@ -677,7 +677,6 @@
entries[selection->items[i]];
action = ro_gui_menu_find_action(current_menu, menu_entry);
-
/* perform menu action */
if (action != NO_ACTION)
ro_gui_menu_handle_action(current_menu_window, action, false);
@@ -686,18 +685,21 @@
if (current_menu == url_suggest_menu) {
g = ro_gui_toolbar_lookup(current_menu_window);
if (g) {
- url = url_suggest_menu->entries[selection->items[0]].data.indirected_text.text;
+ url = url_suggest_menu->entries[selection->items[0]].
+ data.indirected_text.text;
gui_window_set_url(g, url);
browser_window_go(g->bw, url, 0, true);
global_history_add_recent(url);
}
- } else if ((current_menu == gui_form_select_menu) &&
- (selection->items[0] >= 0)) {
+ } else if (current_menu == gui_form_select_menu) {
g = ro_gui_window_lookup(current_menu_window);
assert(g);
- browser_window_form_select(g->bw,
- gui_form_select_control,
- selection->items[0]);
+
+ if (selection->items[0] >= 0) {
+ browser_window_form_select(g->bw,
+ gui_form_select_control,
+ selection->items[0]);
+ }
}
/* allow automatic menus to have their data updated */
@@ -719,7 +721,7 @@
return;
}
- /* re-prepare all the visible enties */
+ /* re-prepare all the visible entries */
i = 0;
menu = current_menu;
do {
@@ -738,11 +740,13 @@
break;
}
} while (j != -1);
- if (current_menu == gui_form_select_menu)
- gui_create_form_select_menu(g->bw,
- gui_form_select_control);
- else
+
+ if (current_menu == gui_form_select_menu) {
+ assert(g); /* Keep scan-build happy */
+ gui_create_form_select_menu(g->bw, gui_form_select_control);
+ } else
ro_gui_menu_create(current_menu, 0, 0, current_menu_window);
+
current_menu_icon = previous_menu_icon;
}
@@ -1108,8 +1112,10 @@
int entry;
definition = calloc(sizeof(struct menu_definition), 1);
- if (!definition)
+ if (!definition) {
die("No memory to create menu definition.");
+ return NULL; /* For the benefit of scan-build */
+ }
/* link in the menu to our list */
definition->next = ro_gui_menu_definitions;
@@ -2230,7 +2236,6 @@
ro_gui_set_icon_shaded_state(
t->toolbar_handle,
ICON_TOOLBAR_UP, !result);
- result = true;
break;
case BROWSER_NAVIGATE_RELOAD:
case BROWSER_NAVIGATE_RELOAD_ALL:
@@ -2338,17 +2343,21 @@
case TREE_COLLAPSE_ALL:
case TREE_COLLAPSE_FOLDERS:
case TREE_COLLAPSE_LINKS:
- if ((tree) && (tree->root))
+ if ((tree) && (tree->root)) {
ro_gui_menu_set_entry_shaded(current_menu,
action, !tree->root->child);
- if ((t) && (!t->editor) &&
- (t->type != THEME_BROWSER_TOOLBAR)) {
- ro_gui_set_icon_shaded_state(
- t->toolbar_handle,
- ICON_TOOLBAR_EXPAND, !tree->root->child);
- ro_gui_set_icon_shaded_state(
- t->toolbar_handle,
- ICON_TOOLBAR_OPEN, !tree->root->child);
+
+ if ((t) && (!t->editor) && (t->type !=
+ THEME_BROWSER_TOOLBAR)) {
+ ro_gui_set_icon_shaded_state(
+ t->toolbar_handle,
+ ICON_TOOLBAR_EXPAND,
+ !tree->root->child);
+ ro_gui_set_icon_shaded_state(
+ t->toolbar_handle,
+ ICON_TOOLBAR_OPEN,
+ !tree->root->child);
+ }
}
break;
case TREE_SELECTION:
13 years, 8 months
r7642 jmb - /trunk/netsurf/riscos/window.c
by netsurf@semichrome.net
Author: jmb
Date: Fri May 29 18:25:38 2009
New Revision: 7642
URL: http://source.netsurf-browser.org?rev=7642&view=rev
Log:
Actually catch error and deal with it
Modified:
trunk/netsurf/riscos/window.c
Modified: trunk/netsurf/riscos/window.c
URL: http://source.netsurf-browser.org/trunk/netsurf/riscos/window.c?rev=7642&...
==============================================================================
--- trunk/netsurf/riscos/window.c (original)
+++ trunk/netsurf/riscos/window.c Fri May 29 18:25:38 2009
@@ -401,6 +401,11 @@
<< wimp_CHILD_XORIGIN_SHIFT |
wimp_CHILD_LINKS_PARENT_WORK_AREA
<< wimp_CHILD_YORIGIN_SHIFT);
+ if (error) {
+ LOG(("xwimp_open_window_nested: 0x%x: %s",
+ error->errnum, error->errmess));
+ warn_user("WimpError", error->errmess);
+ }
}
ro_gui_window_open(PTR_WIMP_OPEN(&state));
13 years, 8 months
r7641 jmb - /trunk/netsurf/riscos/url_complete.c
by netsurf@semichrome.net
Author: jmb
Date: Fri May 29 18:23:02 2009
New Revision: 7641
URL: http://source.netsurf-browser.org?rev=7641&view=rev
Log:
Ensure we don't read beyond the end of the array of available matches. Set any remaining saved pointers to NULL.
Modified:
trunk/netsurf/riscos/url_complete.c
Modified: trunk/netsurf/riscos/url_complete.c
URL: http://source.netsurf-browser.org/trunk/netsurf/riscos/url_complete.c?rev...
==============================================================================
--- trunk/netsurf/riscos/url_complete.c (original)
+++ trunk/netsurf/riscos/url_complete.c Fri May 29 18:23:02 2009
@@ -146,10 +146,16 @@
lines = MAXIMUM_VISIBLE_LINES;
if (lines > url_complete_matches_available)
lines = url_complete_matches_available;
- if (url_complete_matches)
- for (i = 0; i < MAXIMUM_VISIBLE_LINES; i++)
- url_complete_redraw[i] =
+ if (url_complete_matches) {
+ for (i = 0; i < MAXIMUM_VISIBLE_LINES; i++) {
+ if (i < lines) {
+ url_complete_redraw[i] =
url_complete_matches[i];
+ } else {
+ url_complete_redraw[i] = NULL;
+ }
+ }
+ }
/* our selection gets wiped */
error = xwimp_force_redraw(dialog_url_complete,
13 years, 8 months
r7638 jmb - /trunk/netsurf/riscos/textselection.c
by netsurf@semichrome.net
Author: jmb
Date: Fri May 29 18:12:18 2009
New Revision: 7638
URL: http://source.netsurf-browser.org?rev=7638&view=rev
Log:
Tidy up somewhat. Lose redundant assignment.
Modified:
trunk/netsurf/riscos/textselection.c
Modified: trunk/netsurf/riscos/textselection.c
URL: http://source.netsurf-browser.org/trunk/netsurf/riscos/textselection.c?re...
==============================================================================
--- trunk/netsurf/riscos/textselection.c (original)
+++ trunk/netsurf/riscos/textselection.c Fri May 29 18:12:18 2009
@@ -521,7 +521,6 @@
{
wimp_full_message_dragging *drag = (wimp_full_message_dragging*)message;
struct box *textarea = NULL;
- struct box *text_box = NULL;
struct browser_window *bw;
struct content *content;
int gadget_box_x = 0;
@@ -531,12 +530,12 @@
int box_x = 0;
int box_y = 0;
-/* with autoscrolling, we will probably need to remember the gui_window and
- override the drag->w window handle which could be any window on the desktop */
+ /* with autoscrolling, we will probably need to remember the
+ * gui_window and override the drag->w window handle which
+ * could be any window on the desktop */
g = ro_gui_window_lookup(drag->w);
if ((drag->flags & wimp_DRAGGING_TERMINATE_DRAG) || !g) {
-
if (drag_claimed) {
/* make sure that we erase the ghost caret */
caret_remove(&ghost_caret);
@@ -551,36 +550,27 @@
bw = g->bw;
content = bw->current_content;
- if (content && content->type == CONTENT_HTML &&
- content->data.html.layout) {
-
+ if (content && content->type == CONTENT_HTML &&
+ content->data.html.layout) {
struct box *box = content->data.html.layout;
- while ((box = box_at_point(box, pos.x, pos.y, &box_x, &box_y, &content))) {
- if (box->style &&
- box->style->visibility == CSS_VISIBILITY_HIDDEN)
+ while ((box = box_at_point(box, pos.x, pos.y,
+ &box_x, &box_y, &content))) {
+ if (box->style && box->style->visibility ==
+ CSS_VISIBILITY_HIDDEN)
continue;
- if (box->gadget) {
- switch (box->gadget->type) {
-
- case GADGET_TEXTAREA:
- textarea = box;
- gadget_box_x = box_x;
- gadget_box_y = box_y;
- case GADGET_TEXTBOX:
- case GADGET_PASSWORD:
- text_box = box;
- break;
-
- default: /* appease compiler */
- break;
- }
+ if (box->gadget &&
+ box->gadget->type == GADGET_TEXTAREA) {
+ textarea = box;
+ gadget_box_x = box_x;
+ gadget_box_y = box_y;
}
}
}
if (textarea) {
+ struct box *text_box = NULL;
int pixel_offset;
int char_offset;
@@ -591,12 +581,14 @@
gui_window_set_pointer(g, GUI_POINTER_CARET);
text_box = textarea_get_position(textarea, pos.x - gadget_box_x,
- pos.y - gadget_box_y, &char_offset, &pixel_offset);
-
- caret_set_position(&ghost_caret, bw, text_box, char_offset, pixel_offset);
+ pos.y - gadget_box_y,
+ &char_offset, &pixel_offset);
+
+ caret_set_position(&ghost_caret, bw, text_box,
+ char_offset, pixel_offset);
+
drag_claimed = true;
- }
- else {
+ } else {
if (drag_claimed) {
/* make sure that we erase the ghost caret */
caret_remove(&ghost_caret);
@@ -608,15 +600,17 @@
wimp_full_message_drag_claim claim;
os_error *error;
- claim.size = offsetof(wimp_full_message_drag_claim, file_types) + 8;
+ claim.size =
+ offsetof(wimp_full_message_drag_claim, file_types) + 8;
claim.your_ref = drag->my_ref;
claim.action = message_DRAG_CLAIM;
- claim.flags = wimp_DRAG_CLAIM_POINTER_CHANGED | wimp_DRAG_CLAIM_SUPPRESS_DRAGBOX;
+ claim.flags = wimp_DRAG_CLAIM_POINTER_CHANGED |
+ wimp_DRAG_CLAIM_SUPPRESS_DRAGBOX;
claim.file_types[0] = osfile_TYPE_TEXT;
claim.file_types[1] = ~0;
- error = xwimp_send_message(wimp_USER_MESSAGE, (wimp_message*)&claim,
- drag->sender);
+ error = xwimp_send_message(wimp_USER_MESSAGE,
+ (wimp_message *) &claim, drag->sender);
if (error) {
LOG(("xwimp_send_message: 0x%x: %s",
error->errnum, error->errmess));
13 years, 8 months