summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn Mark Bell <jmb@netsurf-browser.org>2008-08-13 11:07:16 +0000
committerJohn Mark Bell <jmb@netsurf-browser.org>2008-08-13 11:07:16 +0000
commit1e55c5ba81e9a8883c41d0e991d245c5397c44b9 (patch)
tree2168987f417cb1b48963c524e0b2b044c62cfb08
parent704cd8b4f290c2afb0579b940773f1d73c0a2cc5 (diff)
downloadlibhubbub-1e55c5ba81e9a8883c41d0e991d245c5397c44b9.tar.gz
libhubbub-1e55c5ba81e9a8883c41d0e991d245c5397c44b9.tar.bz2
Sanity checking for string data
svn path=/trunk/hubbub/; revision=5080
-rw-r--r--src/tokeniser/tokeniser.c39
-rw-r--r--test/tree.c29
2 files changed, 68 insertions, 0 deletions
diff --git a/src/tokeniser/tokeniser.c b/src/tokeniser/tokeniser.c
index 9144c38..1188e2d 100644
--- a/src/tokeniser/tokeniser.c
+++ b/src/tokeniser/tokeniser.c
@@ -2969,6 +2969,45 @@ hubbub_error hubbub_tokeniser_emit_token(hubbub_tokeniser *tokeniser,
assert(tokeniser != NULL);
assert(token != NULL);
+#ifndef NDEBUG
+ /* Sanity checks */
+ switch (token->type) {
+ case HUBBUB_TOKEN_DOCTYPE:
+ assert(memchr(token->data.doctype.name.ptr, 0xff,
+ token->data.doctype.name.len) == NULL);
+ if (token->data.doctype.public_missing == false)
+ assert(memchr(token->data.doctype.public_id.ptr, 0xff,
+ token->data.doctype.public_id.len) == NULL);
+ if (token->data.doctype.system_missing == false)
+ assert(memchr(token->data.doctype.system_id.ptr, 0xff,
+ token->data.doctype.system_id.len) == NULL);
+ break;
+ case HUBBUB_TOKEN_START_TAG:
+ case HUBBUB_TOKEN_END_TAG:
+ assert(memchr(token->data.tag.name.ptr, 0xff,
+ token->data.tag.name.len) == NULL);
+ for (uint32_t i = 0; i < token->data.tag.n_attributes; i++) {
+ hubbub_attribute *attr = &token->data.tag.attributes[i];
+
+ assert(memchr(attr->name.ptr, 0xff, attr->name.len) ==
+ NULL);
+ assert(memchr(attr->value.ptr, 0xff, attr->value.len) ==
+ NULL);
+ }
+ break;
+ case HUBBUB_TOKEN_COMMENT:
+ assert(memchr(token->data.comment.ptr, 0xff,
+ token->data.comment.len) == NULL);
+ break;
+ case HUBBUB_TOKEN_CHARACTER:
+ assert(memchr(token->data.character.ptr, 0xff,
+ token->data.character.len) == NULL);
+ break;
+ case HUBBUB_TOKEN_EOF:
+ break;
+ }
+#endif
+
/* Emit the token */
if (tokeniser->token_handler) {
err = tokeniser->token_handler(token, tokeniser->token_pw);
diff --git a/test/tree.c b/test/tree.c
index 944d887..4e42afc 100644
--- a/test/tree.c
+++ b/test/tree.c
@@ -176,6 +176,8 @@ int create_comment(void *ctx, const hubbub_string *data, void **result)
printf("Creating (%" PRIuPTR ") [comment '%.*s']\n", ++node_counter,
(int) data->len, data->ptr);
+ assert(memchr(data->ptr, 0xff, data->len) == NULL);
+
GROW_REF
node_ref[node_counter] = 0;
@@ -191,6 +193,16 @@ int create_doctype(void *ctx, const hubbub_doctype *doctype, void **result)
printf("Creating (%" PRIuPTR ") [doctype '%.*s']\n", ++node_counter,
(int) doctype->name.len, doctype->name.ptr);
+ assert(memchr(doctype->name.ptr, 0xff, doctype->name.len) == NULL);
+ if (doctype->public_missing == false) {
+ assert(memchr(doctype->public_id.ptr, 0xff,
+ doctype->public_id.len) == NULL);
+ }
+ if (doctype->system_missing == false) {
+ assert(memchr(doctype->system_id.ptr, 0xff,
+ doctype->system_id.len) == NULL);
+ }
+
GROW_REF
node_ref[node_counter] = 0;
@@ -206,6 +218,14 @@ int create_element(void *ctx, const hubbub_tag *tag, void **result)
printf("Creating (%" PRIuPTR ") [element '%.*s']\n", ++node_counter,
(int) tag->name.len, tag->name.ptr);
+ assert(memchr(tag->name.ptr, 0xff, tag->name.len) == NULL);
+ for (uint32_t i = 0; i < tag->n_attributes; i++) {
+ hubbub_attribute *attr = &tag->attributes[i];
+
+ assert(memchr(attr->name.ptr, 0xff, attr->name.len) == NULL);
+ assert(memchr(attr->value.ptr, 0xff, attr->value.len) == NULL);
+ }
+
GROW_REF
node_ref[node_counter] = 0;
@@ -221,6 +241,8 @@ int create_text(void *ctx, const hubbub_string *data, void **result)
printf("Creating (%" PRIuPTR ") [text '%.*s']\n", ++node_counter,
(int) data->len, data->ptr);
+ assert(memchr(data->ptr, 0xff, data->len) == NULL);
+
GROW_REF
node_ref[node_counter] = 0;
@@ -349,6 +371,13 @@ int add_attributes(void *ctx, void *node,
printf("Adding attributes to %" PRIuPTR "\n", (uintptr_t) node);
+ for (uint32_t i = 0; i < n_attributes; i++) {
+ const hubbub_attribute *attr = &attributes[i];
+
+ assert(memchr(attr->name.ptr, 0xff, attr->name.len) == NULL);
+ assert(memchr(attr->value.ptr, 0xff, attr->value.len) == NULL);
+ }
+
return 0;
}