diff --git a/src/char_ref.c b/src/char_ref.c index e693e04..bb4a177 100644 --- a/src/char_ref.c +++ b/src/char_ref.c @@ -23037,7 +23037,7 @@ static bool consume_named_ref( if (cs >= 7623) { assert(output->first != kGumboNoChar); char last_char = *(te - 1); - int len = te - start; + int len = (int) (te - start); if (last_char == ';') { bool matched = utf8iterator_maybe_consume_match(input, start, len, true); assert(matched); diff --git a/src/error.c b/src/error.c index 6b884ca..12da28b 100644 --- a/src/error.c +++ b/src/error.c @@ -34,7 +34,7 @@ // written. static int print_message(GumboStringBuffer* output, const char* format, ...) { va_list args; - int remaining_capacity = output->capacity - output->length; + unsigned int remaining_capacity = (unsigned int) (output->capacity - output->length); va_start(args, format); int bytes_written = vsnprintf(output->data + output->length, remaining_capacity, format, args); @@ -61,9 +61,9 @@ static int print_message(GumboStringBuffer* output, const char* format, ...) { } #endif - if (bytes_written >= remaining_capacity) { + if (bytes_written >= (int) remaining_capacity) { gumbo_string_buffer_reserve(output->capacity + bytes_written, output); - remaining_capacity = output->capacity - output->length; + remaining_capacity = (unsigned int) (output->capacity - output->length); va_start(args, format); bytes_written = vsnprintf(output->data + output->length, remaining_capacity, format, args); @@ -79,7 +79,8 @@ static void print_tag_stack(const GumboParserError* error, GumboStringBuffer* ou if (i) { print_message(output, ", "); } - GumboTag tag = (GumboTag) error->tag_stack.data[i]; + // cast to uintptr_t first to prevent void ptr to enum cast warning + GumboTag tag = (GumboTag)( (uintptr_t) (error->tag_stack.data[i]) ); print_message(output, gumbo_normalized_tagname(tag)); } gumbo_string_buffer_append_codepoint('.', output); diff --git a/src/gumbo.h b/src/gumbo.h index a63bd91..b579c85 100644 --- a/src/gumbo.h +++ b/src/gumbo.h @@ -205,7 +205,7 @@ const char* gumbo_normalize_svg_tagname(const GumboStringPiece* tagname); * enum. The `tag` version expects `tagname` to be NULL-terminated */ GumboTag gumbo_tag_enum(const char* tagname); -GumboTag gumbo_tagn_enum(const char* tagname, int length); +GumboTag gumbo_tagn_enum(const char* tagname, unsigned int length); /** * Attribute namespaces. diff --git a/src/gumbo_edit.c b/src/gumbo_edit.c index 9bf369f..2d4dde0 100644 --- a/src/gumbo_edit.c +++ b/src/gumbo_edit.c @@ -167,7 +167,7 @@ void gumbo_insert_node(GumboNode* node, GumboNode* target_parent, int target_ind assert(0); } assert(index >= 0); - assert(index < children->length); + assert(index <= children->length); node->parent = parent; node->index_within_parent = index; gumbo_vector_insert_at((void*) node, index, children); diff --git a/src/parser.c b/src/parser.c index 2ea5d28..1b3d1ea 100644 --- a/src/parser.c +++ b/src/parser.c @@ -624,7 +624,8 @@ static GumboInsertionMode get_current_template_insertion_mode(const GumboParser* if (template_insertion_modes->length == 0) { return GUMBO_INSERTION_MODE_INITIAL; } - return (GumboInsertionMode) template_insertion_modes->data[(template_insertion_modes->length - 1)]; + // cast to a uintptr_t first to prevent void ptr to enum warning + return (GumboInsertionMode) ( (uintptr_t) (template_insertion_modes->data[(template_insertion_modes->length - 1)] ) ); } // http://www.whatwg.org/specs/web-apps/current-work/multipage/tree-construction.html#mathml-text-integration-point diff --git a/src/tag.c b/src/tag.c index 3a5dd2e..2da56ed 100644 --- a/src/tag.c +++ b/src/tag.c @@ -87,9 +87,9 @@ static int case_memcmp(const char* s1, const char* s2, unsigned int n) { return 0; } -GumboTag gumbo_tagn_enum(const char* tagname, int length) { +GumboTag gumbo_tagn_enum(const char* tagname, unsigned int length) { if (length) { - unsigned int key = tag_hash(tagname, length); + unsigned int key = tag_hash(tagname, length); if (key < TAG_MAP_SIZE) { GumboTag tag = kGumboTagMap[key]; if (length == kGumboTagSizes[(int) tag] && @@ -101,5 +101,5 @@ GumboTag gumbo_tagn_enum(const char* tagname, int length) { } GumboTag gumbo_tag_enum(const char* tagname) { - return gumbo_tagn_enum(tagname, strlen(tagname)); + return gumbo_tagn_enum(tagname, (unsigned int) strlen(tagname)); } diff --git a/src/tokenizer.c b/src/tokenizer.c index 385a34f..6b9f0bd 100644 --- a/src/tokenizer.c +++ b/src/tokenizer.c @@ -742,7 +742,7 @@ static void finish_tag_name(GumboParser* parser) { GumboTagState* tag_state = &tokenizer->_tag_state; tag_state->_tag = gumbo_tagn_enum( - tag_state->_buffer.data, tag_state->_buffer.length); + tag_state->_buffer.data, (unsigned int) (tag_state->_buffer.length)); reinitialize_tag_buffer(parser); } @@ -831,7 +831,7 @@ static bool is_appropriate_end_tag(GumboParser* parser) { assert(!tag_state->_is_start_tag); return tag_state->_last_start_tag != GUMBO_TAG_LAST && tag_state->_last_start_tag == - gumbo_tagn_enum(tag_state->_buffer.data, tag_state->_buffer.length); + gumbo_tagn_enum(tag_state->_buffer.data, (unsigned int) (tag_state->_buffer.length)); } void gumbo_tokenizer_state_init( diff --git a/src/vector.c b/src/vector.c index 9e3ae66..36178d6 100644 --- a/src/vector.c +++ b/src/vector.c @@ -29,7 +29,7 @@ const GumboVector kGumboEmptyVector = { NULL, 0, 0 }; void gumbo_vector_init(size_t initial_capacity, GumboVector* vector) { vector->length = 0; - vector->capacity = initial_capacity; + vector->capacity = (unsigned int) initial_capacity; vector->data = NULL; if (initial_capacity) vector->data = gumbo_malloc(sizeof(void*) * initial_capacity);