From e240c200d53efc0885023077f8ee1087951478aa Mon Sep 17 00:00:00 2001 From: John Mark Bell Date: Sat, 28 Mar 2009 19:59:46 +0000 Subject: Avoid potentially unsafe writes through a const pointer. svn path=/trunk/netsurf/; revision=6974 --- riscos/hotlist.c | 44 +++++++++++++++++++++++++++++--------------- 1 file changed, 29 insertions(+), 15 deletions(-) (limited to 'riscos/hotlist.c') diff --git a/riscos/hotlist.c b/riscos/hotlist.c index 97f397979..db2b0d47d 100644 --- a/riscos/hotlist.c +++ b/riscos/hotlist.c @@ -20,6 +20,7 @@ * Hotlist (implementation). */ +#include #include #include #include @@ -292,41 +293,54 @@ bool ro_gui_hotlist_dialog_apply(wimp_w w) { struct node_element *element; struct node *node; + const char *icon; char *title; - char *icon; char *url = NULL; - url_func_result res = URL_FUNC_OK; + url_func_result res; const struct url_data *data; /* get our data */ if (w == dialog_entry) { - icon = strip(ro_gui_get_icon_string(w, ICON_ENTRY_URL)); - if (strlen(icon) == 0) { - warn_user("NoURLError", 0); + icon = ro_gui_get_icon_string(w, ICON_ENTRY_URL); + + res = url_normalize(icon, &url); + if (res != URL_FUNC_OK) { + warn_user(res == URL_FUNC_FAILED ? "NoURLError" + : "NoMemory", 0); return false; } - res = url_normalize(icon, &url); - title = strip(ro_gui_get_icon_string(w, ICON_ENTRY_NAME)); + + icon = ro_gui_get_icon_string(w, ICON_ENTRY_NAME); + while (isspace(*icon)) + icon++; + title = strdup(icon); + node = dialog_entry_node; } else { - title = strip(ro_gui_get_icon_string(w, ICON_FOLDER_NAME)); + icon = ro_gui_get_icon_string(w, ICON_FOLDER_NAME); + while (isspace(*icon)) + icon++; + title = strdup(icon); + node = dialog_folder_node; } - title = strdup(title); - /* check for failed functions or lack of text */ - if ((title == NULL) || (strlen(title) == 0) || (res != URL_FUNC_OK)) { + if (title != NULL) + strip(title); + + /* check for lack of text */ + if (title == NULL || title[0] == '\0') { free(url); free(title); node = NULL; - if ((title == NULL) || (res != URL_FUNC_OK)) + if (title == NULL) warn_user("NoMemory", 0); - else if (strlen(title) == 0) + else if (title[0] == '\0') warn_user("NoNameError", 0); return false; } - ro_gui_set_icon_string(w, - url ? ICON_ENTRY_NAME : ICON_FOLDER_NAME, title, true); + ro_gui_set_icon_string(w, url ? ICON_ENTRY_NAME : ICON_FOLDER_NAME, + title, false); /* update/insert our data */ if (!node) { -- cgit v1.2.3