Fix null pointer use when a content with no title is in the local history (history_update() was making title null).

svn path=/trunk/netsurf/; revision=3256
This commit is contained in:
James Bursa 2007-04-18 02:52:26 +00:00
parent c01d270250
commit 859ccf007b

View File

@ -34,9 +34,9 @@
#define BOTTOM_MARGIN 30 #define BOTTOM_MARGIN 30
struct history_page { struct history_page {
char *url; /**< Page URL. */ char *url; /**< Page URL, never 0. */
char *frag_id; /** Fragment identifier */ char *frag_id; /** Fragment identifier, or 0. */
char *title; /**< Page title. */ char *title; /**< Page title, never 0. */
}; };
/** A node in the history tree. */ /** A node in the history tree. */
@ -151,6 +151,9 @@ struct history_entry *history_clone_entry(struct history *history,
struct history_entry *prev = NULL; struct history_entry *prev = NULL;
struct history_entry *new_entry; struct history_entry *new_entry;
assert(entry->page.url);
assert(entry->page.title);
/* clone the entry */ /* clone the entry */
new_entry = malloc(sizeof *entry); new_entry = malloc(sizeof *entry);
if (!new_entry) if (!new_entry)
@ -160,8 +163,7 @@ struct history_entry *history_clone_entry(struct history *history,
if (entry->page.frag_id) if (entry->page.frag_id)
new_entry->page.frag_id = strdup(entry->page.frag_id); new_entry->page.frag_id = strdup(entry->page.frag_id);
new_entry->page.title = strdup(entry->page.title); new_entry->page.title = strdup(entry->page.title);
if (((entry->page.url) && (!new_entry->page.url)) || if (!new_entry->page.url || !new_entry->page.title ||
((entry->page.title) && (!new_entry->page.title)) ||
((entry->page.frag_id) && (!new_entry->page.frag_id))) { ((entry->page.frag_id) && (!new_entry->page.frag_id))) {
free(new_entry->page.url); free(new_entry->page.url);
free(new_entry->page.title); free(new_entry->page.title);
@ -219,19 +221,15 @@ void history_add(struct history *history, struct content *content,
/* allocate space */ /* allocate space */
entry = malloc(sizeof *entry); entry = malloc(sizeof *entry);
res = url_normalize(content->url, &url); res = url_normalize(content->url, &url);
if (res != URL_FUNC_OK) { if (res != URL_FUNC_OK) {
warn_user("NoMemory", 0); warn_user("NoMemory", 0);
return; return;
} }
// LOG(("%s => %s : %s", content->url, url, content->title));
// LOG(("%s", frag_id));
title = strdup(content->title ? content->title : url); title = strdup(content->title ? content->title : url);
// LOG(("after strdup"));
if (!entry || !url || !title) { if (!entry || !url || !title) {
warn_user("NoMemory", 0); warn_user("NoMemory", 0);
free(entry); free(entry);
@ -289,15 +287,34 @@ void history_add(struct history *history, struct content *content,
void history_update(struct history *history, struct content *content) void history_update(struct history *history, struct content *content)
{ {
char *title;
char *url;
url_func_result res;
if (!history || !history->current || !history->current->bitmap) if (!history || !history->current || !history->current->bitmap)
return; return;
if (history->current->page.title) assert(history->current->page.url);
free(history->current->page.title); assert(history->current->page.title);
if (content->title)
history->current->page.title = strdup(content->title); if (content->title) {
else title = strdup(content->title);
history->current->page.title = 0; if (!title) {
warn_user("NoMemory", 0);
return;
}
} else {
res = url_normalize(content->url, &url);
if (res != URL_FUNC_OK) {
warn_user("NoMemory", 0);
return;
}
title = url;
}
assert(title);
free(history->current->page.title);
history->current->page.title = title;
thumbnail_create(content, history->current->bitmap, 0); thumbnail_create(content, history->current->bitmap, 0);
} }
@ -576,7 +593,8 @@ bool history_redraw_entry(struct history *history,
return false; return false;
if (!nsfont_position_in_string(&css_base_style, entry->page.title, if (!nsfont_position_in_string(&css_base_style, entry->page.title,
strlen(entry->page.title), WIDTH, &char_offset, &actual_x)) strlen(entry->page.title), WIDTH,
&char_offset, &actual_x))
return false; return false;
if (!plot.text(entry->x, entry->y + HEIGHT + 12, &css_base_style, if (!plot.text(entry->x, entry->y + HEIGHT + 12, &css_base_style,
entry->page.title, char_offset, 0xffffff, c)) entry->page.title, char_offset, 0xffffff, c))