From ea203a6dd8a241d33e4bd1a6b076006cac715776 Mon Sep 17 00:00:00 2001 From: John Mark Bell Date: Sun, 27 Jun 2010 10:50:14 +0000 Subject: Remove ownerNode and ownerRule fields from stylesheet objects. These prevent stylesheets being used in multiple contexts simultaneously. Their values can be inferred from the context in which the stylesheet is used. Replace use of ownerRule to backtrack in style selection with a (fixed-size) stack of rules to process. This prevents crashes when a sheet that was previously imported somewhere is reused as a top-level sheet. svn path=/trunk/libcss/; revision=10581 --- src/select/select.c | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) (limited to 'src/select/select.c') diff --git a/src/select/select.c b/src/select/select.c index b2820c8..411081e 100644 --- a/src/select/select.c +++ b/src/select/select.c @@ -496,6 +496,9 @@ css_error select_from_sheet(css_select_ctx *ctx, const css_stylesheet *sheet, { const css_stylesheet *s = sheet; const css_rule *rule = s->rule_list; + uint32_t sp = 0; +#define IMPORT_STACK_SIZE 256 + const css_rule *import_stack[IMPORT_STACK_SIZE]; do { /* Find first non-charset rule, if we're at the list head */ @@ -514,6 +517,10 @@ css_error select_from_sheet(css_select_ctx *ctx, const css_stylesheet *sheet, if (import->sheet != NULL && (import->media & state->media) != 0) { /* It's applicable, so process it */ + assert(sp < IMPORT_STACK_SIZE - 1); + + import_stack[sp++] = rule; + s = import->sheet; rule = s->rule_list; } else { @@ -537,9 +544,10 @@ css_error select_from_sheet(css_select_ctx *ctx, const css_stylesheet *sheet, return error; /* Find next sheet to process */ - if (s->ownerRule != NULL) { - rule = s->ownerRule->next; - s = s->ownerRule->parent; + if (sp > 0) { + sp--; + rule = import_stack[sp]->next; + s = import_stack[sp]->parent; } else { s = NULL; } -- cgit v1.2.3