From 77a96712244ad4a8b4bde235aa051372a64a8789 Mon Sep 17 00:00:00 2001 From: John Mark Bell Date: Wed, 8 Dec 2004 23:16:53 +0000 Subject: [project @ 2004-12-08 23:16:53 by jmb] Squash bug which caused assertion failure Add more asserts, for my own sanity svn path=/import/netsurf/; revision=1393 --- desktop/imagemap.c | 27 ++++++++++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-) diff --git a/desktop/imagemap.c b/desktop/imagemap.c index 17eff7461..08afc87c3 100644 --- a/desktop/imagemap.c +++ b/desktop/imagemap.c @@ -130,6 +130,7 @@ void imagemap_destroy(struct content *c) { unsigned int i; + assert(c != NULL); assert(c->type == CONTENT_HTML); /* no imagemaps -> return */ @@ -161,6 +162,7 @@ void imagemap_dump(struct content *c) int j; + assert(c != NULL); assert(c->type == CONTENT_HTML); if (c->data.html.imagemaps == 0) return; @@ -221,6 +223,9 @@ bool imagemap_extract(xmlNode *node, struct content *c) struct mapentry *entry = 0; char *name; + assert(node != NULL); + assert(c != NULL); + if (node->type == XML_ELEMENT_NODE) { if (strcmp(node->name, "map") == 0) { if ((name = (char*)xmlGetProp(node, (const xmlChar*)"name")) == NULL) @@ -229,9 +234,16 @@ bool imagemap_extract(xmlNode *node, struct content *c) xmlFree(name); return false; } - if (!imagemap_add(c, name, entry)) { - xmlFree(name); - return false; + /* imagemap_extract_map may not extract anything, + * so entry can still be NULL here. This isn't an + * error as it just means that we've encountered + * an incorrectly defined ... block + */ + if (entry) { + if (!imagemap_add(c, name, entry)) { + xmlFree(name); + return false; + } } xmlFree(name); return true; @@ -262,6 +274,9 @@ bool imagemap_extract_map(xmlNode *node, struct content *c, xmlNode *this_node; + assert(c != NULL); + assert(entry != NULL); + if (node->type == XML_ELEMENT_NODE) { /** \todo ignore elements if there are other * block-level elements present in map @@ -505,6 +520,8 @@ void imagemap_freelist(struct mapentry *list) { struct mapentry *entry, *prev; + assert(list != NULL); + entry = list; while (entry != 0) { @@ -538,6 +555,7 @@ char *imagemap_get(struct content *c, const char *key, unsigned long x, struct mapentry *entry; unsigned long cx, cy; + assert(c != NULL); assert(c->type == CONTENT_HTML); if (key == NULL) return NULL; if (c->data.html.imagemaps == NULL) return NULL; @@ -622,6 +640,9 @@ int imagemap_point_in_poly(int num, float *xpt, float *ypt, unsigned long x, uns int i, j, c=0; + assert(xpt != NULL); + assert(ypt != NULL); + for (i = 0, j = num-1; i < num; j = i++) { if ((((ypt[i]+y <= click_y) && (click_y < ypt[j]+y)) || ((ypt[j]+y <= click_y) && (click_y < ypt[i]+y))) && -- cgit v1.2.3