From cab0b3fbd5d1ddb0f8334a5b4cf9f687a18f618c Mon Sep 17 00:00:00 2001 From: Kalle Olavi Niemitalo Date: Sat, 26 Jan 2008 17:09:21 +0200 Subject: [PATCH] const in CSS --- src/document/css/css.c | 2 +- src/document/css/scanner.c | 4 ++-- src/document/css/stylesheet.c | 4 ++-- src/document/css/stylesheet.h | 6 +++--- src/document/css/value.c | 2 +- src/document/html/internal.h | 2 +- src/document/html/parser.c | 7 +++++-- 7 files changed, 15 insertions(+), 12 deletions(-) diff --git a/src/document/css/css.c b/src/document/css/css.c index bbf803828..c1a4a7d75 100644 --- a/src/document/css/css.c +++ b/src/document/css/css.c @@ -79,7 +79,7 @@ import_css(struct css_stylesheet *css, struct uri *uri) static void import_css_file(struct css_stylesheet *css, struct uri *base_uri, - unsigned char *url, int urllen) + const unsigned char *url, int urllen) { struct string string, filename; diff --git a/src/document/css/scanner.c b/src/document/css/scanner.c index cb927a2f1..361b1a411 100644 --- a/src/document/css/scanner.c +++ b/src/document/css/scanner.c @@ -158,7 +158,7 @@ scan_css_token(struct scanner *scanner, struct scanner_token *token) type = CSS_TOKEN_NUMBER; } else { - unsigned char *ident = string; + const unsigned char *ident = string; scan_css(scanner, string, CSS_CHAR_IDENT); type = map_scanner_string(scanner, ident, string, @@ -251,7 +251,7 @@ scan_css_token(struct scanner *scanner, struct scanner_token *token) } else if (first_char == '@') { /* Compose token containing @ */ if (is_css_ident_start(*string)) { - unsigned char *ident = string; + const unsigned char *ident = string; /* Scan both ident start and ident */ scan_css(scanner, string, CSS_CHAR_IDENT); diff --git a/src/document/css/stylesheet.c b/src/document/css/stylesheet.c index dd2498fe7..c089e3581 100644 --- a/src/document/css/stylesheet.c +++ b/src/document/css/stylesheet.c @@ -49,7 +49,7 @@ find_css_selector(LIST_OF(struct css_selector) *sels, struct css_selector * init_css_selector(LIST_OF(struct css_selector) *sels, enum css_selector_type type, - unsigned char *name, int namelen) + const unsigned char *name, int namelen) { struct css_selector *selector; @@ -84,7 +84,7 @@ struct css_selector * get_css_selector(LIST_OF(struct css_selector) *sels, enum css_selector_type type, enum css_selector_relation rel, - unsigned char *name, int namelen) + const unsigned char *name, int namelen) { struct css_selector *selector = NULL; diff --git a/src/document/css/stylesheet.h b/src/document/css/stylesheet.h index 670af934b..d1b95c04b 100644 --- a/src/document/css/stylesheet.h +++ b/src/document/css/stylesheet.h @@ -74,7 +74,7 @@ struct css_selector { struct css_stylesheet; typedef void (*css_stylesheet_importer_T)(struct css_stylesheet *, struct uri *, - unsigned char *url, int urllen); + const unsigned char *url, int urllen); /** The struct css_stylesheet describes all the useful data that was extracted * from the CSS source. Currently we don't cache anything but the default user @@ -117,7 +117,7 @@ void done_css_stylesheet(struct css_stylesheet *css); struct css_selector *get_css_selector(LIST_OF(struct css_selector) *selector_list, enum css_selector_type type, enum css_selector_relation rel, - unsigned char *name, int namelen); + const unsigned char *name, int namelen); #define get_css_base_selector(stylesheet, type, rel, name, namelen) \ get_css_selector((stylesheet) ? &(stylesheet)->selectors : NULL, \ @@ -137,7 +137,7 @@ struct css_selector *find_css_selector(LIST_OF(struct css_selector) *selector_li * function from your POV. */ struct css_selector *init_css_selector(LIST_OF(struct css_selector) *selector_list, enum css_selector_type type, - unsigned char *name, int namelen); + const unsigned char *name, int namelen); /** Add all properties from the list to the given @a selector. */ void add_selector_properties(struct css_selector *selector, diff --git a/src/document/css/value.c b/src/document/css/value.c index f59965f96..41d6a7b8d 100644 --- a/src/document/css/value.c +++ b/src/document/css/value.c @@ -41,7 +41,7 @@ css_parse_color_value(struct css_property_info *propinfo, /* The first two args are terminated by ',' and the * last one by ')'. */ unsigned char paskynator = shift ? ',' : ')'; - unsigned char *nstring = token->string; + const unsigned char *nstring = token->string; int part; /* Are the current and next token valid? */ diff --git a/src/document/html/internal.h b/src/document/html/internal.h index c656660fe..ff2224e2b 100644 --- a/src/document/html/internal.h +++ b/src/document/html/internal.h @@ -143,6 +143,6 @@ unsigned char *get_target(struct document_options *options, unsigned char *a); void import_css_stylesheet(struct css_stylesheet *css, struct uri *base_uri, - unsigned char *url, int len); + const unsigned char *unterminated_url, int len); #endif diff --git a/src/document/html/parser.c b/src/document/html/parser.c index 35b9b5d5d..8db8e5772 100644 --- a/src/document/html/parser.c +++ b/src/document/html/parser.c @@ -182,9 +182,10 @@ add_fragment_identifier(struct html_context *html_context, #ifdef CONFIG_CSS void import_css_stylesheet(struct css_stylesheet *css, struct uri *base_uri, - unsigned char *url, int len) + const unsigned char *unterminated_url, int len) { struct html_context *html_context = css->import_data; + unsigned char *url; unsigned char *import_url; struct uri *uri; @@ -195,7 +196,9 @@ import_css_stylesheet(struct css_stylesheet *css, struct uri *base_uri, || !html_context->options->css_import) return; - url = memacpy(url, len); + /* unterminated_url might not end with '\0', but join_urls + * requires that, so make a copy. */ + url = memacpy(unterminated_url, len); if (!url) return; /* HTML urls should already be fine but we can.t detect them. */