summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJohn Mark Bell <jmb@netsurf-browser.org>2009-01-25 23:17:51 +0000
committerJohn Mark Bell <jmb@netsurf-browser.org>2009-01-25 23:17:51 +0000
commit0a33fa9dc390f0f124a1910d03af1c4dbc78e99c (patch)
tree10fb4bc43b3ac92d1f469cb52fa92d6fdb11add3 /src
parente89a3e9fdb2cf06c0873d89ee75b31c77574abec (diff)
downloadlibcss-0a33fa9dc390f0f124a1910d03af1c4dbc78e99c.tar.gz
libcss-0a33fa9dc390f0f124a1910d03af1c4dbc78e99c.tar.bz2
Assert preconditions, rather than returning runtime errors.
Squash leakage of selectors array in selector/page rules. svn path=/trunk/libcss/; revision=6274
Diffstat (limited to 'src')
-rw-r--r--src/stylesheet.c41
1 files changed, 22 insertions, 19 deletions
diff --git a/src/stylesheet.c b/src/stylesheet.c
index dfe949d..71aee9c 100644
--- a/src/stylesheet.c
+++ b/src/stylesheet.c
@@ -5,6 +5,7 @@
* Copyright 2008 John-Mark Bell <jmb@netsurf-browser.org>
*/
+#include <assert.h>
#include <string.h>
#include "stylesheet.h"
@@ -438,8 +439,7 @@ css_error css_stylesheet_selector_destroy(css_stylesheet *sheet,
return CSS_BADPARM;
/* Must not be attached to a rule */
- if (selector->rule != NULL)
- return CSS_INVALID;
+ assert(selector->rule == NULL);
/* Destroy combinator chain */
for (c = selector->combinator; c != NULL; c = d) {
@@ -570,8 +570,7 @@ css_error css_stylesheet_selector_combine(css_stylesheet *sheet,
return CSS_BADPARM;
/* Ensure that there is no existing combinator on B */
- if (b->combinator != NULL)
- return CSS_INVALID;
+ assert(b->combinator == NULL);
b->combinator = a;
b->data.comb = type;
@@ -648,8 +647,8 @@ css_error css_stylesheet_rule_destroy(css_stylesheet *sheet, css_rule *rule)
return CSS_BADPARM;
/* Must be detached from parent/siblings */
- if (rule->parent != NULL || rule->next != NULL || rule->prev != NULL)
- return CSS_INVALID;
+ assert(rule->parent == NULL && rule->next == NULL &&
+ rule->prev == NULL);
/* Destroy type-specific contents */
switch (rule->type) {
@@ -669,7 +668,11 @@ css_error css_stylesheet_rule_destroy(css_stylesheet *sheet, css_rule *rule)
css_stylesheet_selector_destroy(sheet, sel);
}
- css_stylesheet_style_destroy(sheet, s->style);
+ if (s->selectors != NULL)
+ sheet->alloc(s->selectors, 0, sheet->pw);
+
+ if (s->style != NULL)
+ css_stylesheet_style_destroy(sheet, s->style);
}
break;
case CSS_RULE_CHARSET:
@@ -702,7 +705,8 @@ css_error css_stylesheet_rule_destroy(css_stylesheet *sheet, css_rule *rule)
{
css_rule_font_face *font_face = (css_rule_font_face *) rule;
- css_stylesheet_style_destroy(sheet, font_face->style);
+ if (font_face->style != NULL)
+ css_stylesheet_style_destroy(sheet, font_face->style);
}
break;
case CSS_RULE_PAGE:
@@ -719,7 +723,11 @@ css_error css_stylesheet_rule_destroy(css_stylesheet *sheet, css_rule *rule)
css_stylesheet_selector_destroy(sheet, sel);
}
- css_stylesheet_style_destroy(sheet, page->style);
+ if (page->selectors != NULL)
+ sheet->alloc(page->selectors, 0, sheet->pw);
+
+ if (page->style != NULL)
+ css_stylesheet_style_destroy(sheet, page->style);
}
break;
}
@@ -748,8 +756,7 @@ css_error css_stylesheet_rule_add_selector(css_stylesheet *sheet,
return CSS_BADPARM;
/* Ensure rule is a CSS_RULE_SELECTOR */
- if (rule->type != CSS_RULE_SELECTOR)
- return CSS_INVALID;
+ assert(rule->type == CSS_RULE_SELECTOR);
sels = sheet->alloc(r->selectors,
(r->base.items + 1) * sizeof(css_selector *),
@@ -784,8 +791,7 @@ css_error css_stylesheet_rule_append_style(css_stylesheet *sheet,
if (sheet == NULL || rule == NULL || style == NULL)
return CSS_BADPARM;
- if (rule->type != CSS_RULE_SELECTOR && rule->type != CSS_RULE_PAGE)
- return CSS_INVALID;
+ assert(rule->type == CSS_RULE_SELECTOR || rule->type == CSS_RULE_PAGE);
if (rule->type == CSS_RULE_SELECTOR)
cur = ((css_rule_selector *) rule)->style;
@@ -842,8 +848,7 @@ css_error css_stylesheet_rule_set_charset(css_stylesheet *sheet,
return CSS_BADPARM;
/* Ensure rule is a CSS_RULE_CHARSET */
- if (rule->type != CSS_RULE_CHARSET)
- return CSS_INVALID;
+ assert(rule->type == CSS_RULE_CHARSET);
/* Set rule's encoding field */
r->encoding = charset;
@@ -868,8 +873,7 @@ css_error css_stylesheet_rule_set_import(css_stylesheet *sheet,
return CSS_BADPARM;
/* Ensure rule is a CSS_RULE_IMPORT */
- if (rule->type != CSS_RULE_IMPORT)
- return CSS_INVALID;
+ assert(rule->type == CSS_RULE_IMPORT);
/* Set the rule's sheet field */
r->sheet = import;
@@ -981,8 +985,7 @@ css_error _add_selectors(css_stylesheet *sheet, css_rule *rule)
return CSS_BADPARM;
/* Rule must not be in sheet */
- if (rule->parent != NULL)
- return CSS_INVALID;
+ assert(rule->parent == NULL);
switch (rule->type) {
case CSS_RULE_SELECTOR: