Skip to content

Commit

Permalink
Squashed 'gumbo_subtree/' changes from 11bff0a..433cfc1
Browse files Browse the repository at this point in the history
433cfc1 fix up last Windows compiler warning
8c1b204 clean up Windows compiler warnings
85503eb remove void ptr to enum cast warnings
14ef08b fix incorrect assert

git-subtree-dir: gumbo_subtree
git-subtree-split: 433cfc10071ab149526cd9024c5bf3bf183fa5d2
  • Loading branch information
dougmassay committed Mar 25, 2023
1 parent 9225cb5 commit 5fb28bf
Show file tree
Hide file tree
Showing 8 changed files with 16 additions and 14 deletions.
2 changes: 1 addition & 1 deletion src/char_ref.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
9 changes: 5 additions & 4 deletions src/error.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion src/gumbo.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion src/gumbo_edit.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
3 changes: 2 additions & 1 deletion src/parser.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions src/tag.c
Original file line number Diff line number Diff line change
Expand Up @@ -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] &&
Expand All @@ -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));
}
4 changes: 2 additions & 2 deletions src/tokenizer.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down Expand Up @@ -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(
Expand Down
2 changes: 1 addition & 1 deletion src/vector.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 5fb28bf

Please sign in to comment.