Avoid potentially unsafe writes through a const pointer.

svn path=/trunk/netsurf/; revision=6974
This commit is contained in:
John Mark Bell 2009-03-28 19:59:46 +00:00
parent ce10998776
commit e240c200d5
2 changed files with 30 additions and 16 deletions

View File

@ -20,6 +20,7 @@
* Hotlist (implementation).
*/
#include <ctype.h>
#include <string.h>
#include <stdbool.h>
#include <stdio.h>
@ -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) {

View File

@ -242,7 +242,7 @@ const char *ro_gui_get_icon_string(wimp_w w, wimp_i i)
ic.icon.data.indirected_text.text
:
ic.icon.data.text;
/* Garantee NUL termination. */
/* Guarantee NUL termination. */
itext[ro_gui_strlen(itext)] = '\0';
return itext;
}