Fixes after check the Coverity

This commit is contained in:
lexborisov 2016-12-14 22:09:21 +03:00
parent 32f5e84dec
commit 4ef1e93f07
40 changed files with 178 additions and 174 deletions

View File

@ -3,19 +3,4 @@ compiler:
- clang
- gcc
install: false
env:
global:
- secure: "gNSRCjo+hi14yLpCDEmwZfzy0DFoOR+9BmkdpJhTK8NjUvIy+RmFtXgT98QHgh+fow8v/YXl8hSnyDT2+oSmsKN9P113ssgYihwoB4IuIBLSIrAf9KPfhIh6LZC23lKltQUrP9yPo3jzdD1dte1xv2tKRImDZ1Cze987EjDBbSwuVP/Gj3JlWMAafEPrh48jCM/O4DXR4podcd1biXbyX8+lbYJSFVaIq0SuagzK5Kjv8nDAFYlNk27RdhQGemmZOsM5xQM4PpgKpcQVHh0YuObCryf/O+orCDh7dOu9QlbMijabYxz/Jx7fZ1mLQGm7Kj6ETdCcf80MrrDechjJgh7uyFE/+VPDfkdaSCm1vMJCNBRgFSM0bxXqtLAyNs9TNOIJ3TUv3M4eN98Feh7I3ip9eTU/0R36HKU7sk+yotmOuAMDaMikbTQ2UuHekKev3TD0dA5O6xatyDF3jCnTJ+8aYQ096A79ZSabWUiLe6IyV/NauqSfY+mOz2NA+TxqzW92HqStdvmeOuSqCGdkGi3o2z77jEez795l2bqnIziuZhojfxjtvc/ryaZaBMYWqjSlOzRcix/SwIt8ccDCXJ4F/aNi16mYuDdL5c2mQaxtZ5Xz1IZduU87f6pWHdhLPoRMqpd/XChJVwKSFxbKmRWynUfHTcwJePSSyn5GRNA="
addons:
coverity_scan:
project:
name: "lexborisov/Modest"
description: "Build submitted via Travis CI"
notification_email: lex.borisov@gmail.com
build_command_prepend: ""
build_command: "make -j4"
branch_pattern: coverity_scan
script: make -j4

Binary file not shown.

View File

@ -23,7 +23,7 @@ endif
MODEST_BUILD_WITHOUT_THREADS ?= NO
ifeq ($(MODEST_BUILD_WITHOUT_THREADS),YES)
$(info Build without POSIX Threads)
CFLAGS += -DMODEST_BUILD_WITHOUT_THREADS
CFLAGS += -DMODEST_BUILD_WITHOUT_THREADS -DMyHTML_BUILD_WITHOUT_THREADS
else
$(info Build with POSIX Threads)
CFLAGS += -pthread

View File

@ -9,7 +9,7 @@ Modest is a fast HTML Render implemented as a pure C99 library with no outside d
## Now
```text
The current version is 0.0.1 - devel
The current version is 0.0.4 - devel
```
## Features

View File

@ -18,6 +18,7 @@
0E0C91961DB1064E007A0501 /* serialization.c in Sources */ = {isa = PBXBuildFile; fileRef = 0E0C91941DB1064E007A0501 /* serialization.c */; };
0E0C91991DB107E7007A0501 /* property.c in Sources */ = {isa = PBXBuildFile; fileRef = 0E0C91971DB107E7007A0501 /* property.c */; };
0E0C919C1DB10866007A0501 /* raw_property.c in Sources */ = {isa = PBXBuildFile; fileRef = 0E0C919A1DB10866007A0501 /* raw_property.c */; };
0E0D5D011E003A5E00EBFDD6 /* avl_tree.c in Sources */ = {isa = PBXBuildFile; fileRef = 0E0D5CFF1E003A5E00EBFDD6 /* avl_tree.c */; };
0E4B525C1DC13BBB0095026A /* parser_text_decoration.c in Sources */ = {isa = PBXBuildFile; fileRef = 0E4B525A1DC13BBB0095026A /* parser_text_decoration.c */; };
0E5AA4BD1DA9689700FF5358 /* shared.c in Sources */ = {isa = PBXBuildFile; fileRef = 0E5AA4BB1DA9689700FF5358 /* shared.c */; };
0E5E2AAB1DC53CC1007836AB /* entry_destroy.c in Sources */ = {isa = PBXBuildFile; fileRef = 0E5E2AA91DC53CC1007836AB /* entry_destroy.c */; };
@ -161,6 +162,8 @@
0E0C91981DB107E7007A0501 /* property.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = property.h; path = ../../../source/modest/node/property.h; sourceTree = "<group>"; };
0E0C919A1DB10866007A0501 /* raw_property.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = raw_property.c; path = ../../../source/modest/node/raw_property.c; sourceTree = "<group>"; };
0E0C919B1DB10866007A0501 /* raw_property.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = raw_property.h; path = ../../../source/modest/node/raw_property.h; sourceTree = "<group>"; };
0E0D5CFF1E003A5E00EBFDD6 /* avl_tree.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = avl_tree.c; sourceTree = "<group>"; };
0E0D5D001E003A5E00EBFDD6 /* avl_tree.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = avl_tree.h; sourceTree = "<group>"; };
0E4B525A1DC13BBB0095026A /* parser_text_decoration.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = parser_text_decoration.c; sourceTree = "<group>"; };
0E5AA4BB1DA9689700FF5358 /* shared.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = shared.c; sourceTree = "<group>"; };
0E5AA4BC1DA9689700FF5358 /* shared.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = shared.h; sourceTree = "<group>"; };
@ -771,6 +774,8 @@
0E750FD71D9AF27F00337E9B /* utils */ = {
isa = PBXGroup;
children = (
0E0D5CFF1E003A5E00EBFDD6 /* avl_tree.c */,
0E0D5D001E003A5E00EBFDD6 /* avl_tree.h */,
0E750FD91D9AF27F00337E9B /* mchar_async.h */,
0E750FD81D9AF27F00337E9B /* mchar_async.c */,
0E750FDA1D9AF27F00337E9B /* mcobject.c */,
@ -928,6 +933,7 @@
0E818EF61DAE6F8F005B0C77 /* serialization.c in Sources */,
0E0239811D9FE8EC0084A81A /* type.c in Sources */,
0E750F811D9AF27200337E9B /* check.c in Sources */,
0E0D5D011E003A5E00EBFDD6 /* avl_tree.c in Sources */,
0E750EF91D9AF25300337E9B /* match.c in Sources */,
0E7F78351DD3E0D5003B6053 /* begin.c in Sources */,
0E750F9E1D9AF27200337E9B /* consume.c in Sources */,
@ -1031,7 +1037,7 @@
0E750EE71D9AF1D500337E9B /* Debug */ = {
isa = XCBuildConfiguration;
buildSettings = {
GCC_OPTIMIZATION_LEVEL = 2;
GCC_OPTIMIZATION_LEVEL = 0;
HEADER_SEARCH_PATHS = ../../source;
OTHER_CFLAGS = (
"-DMyHTML_WITH_PERF",

View File

@ -2,4 +2,22 @@
<Bucket
type = "1"
version = "2.0">
<Breakpoints>
<BreakpointProxy
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
<BreakpointContent
shouldBeEnabled = "Yes"
ignoreCount = "0"
continueAfterRunningActions = "No"
filePath = "Modest/main.c"
timestampString = "503430000.704645"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "258"
endingLineNumber = "258"
landmarkName = "main()"
landmarkType = "9">
</BreakpointContent>
</BreakpointProxy>
</Breakpoints>
</Bucket>

View File

@ -157,7 +157,7 @@ void print_tree_after_all(modest_t* modest, myhtml_tree_t* myhtml_tree, myhtml_t
if(m_node) {
printf("\tstyles: ");
modest_node_raw_serialization(mycss_entry, m_node, serialization_callback, NULL);
modest_node_raw_serialization(modest, m_node, serialization_callback, NULL);
printf("\n");
}
@ -206,15 +206,7 @@ int main(int argc, const char * argv[]) {
//char *css_f = "/new/C-git/bootstrap.css";
char *html = "<fff>sdsd<aaaa id=hash class=best><div a1><menu class=\"lalala\" id=\"menu-id\" b1><span span1><div a2></div></div><menu class=\"be\" id=\"menu\" b1><span span2></aaaa><a href=\"\" sec></a><div div1><div div2></div><div div3></div><div div4></div></div><p p1><p p2><p p3><p p4>";
char *css = "hr { \
color: gray; \
border-style: inset; \
border-width: 1px; \
margin-block-start: 0.5em; \
margin-inline-end: auto; \
margin-block-end: 0.5em; \
margin-inline-start: auto; \
}";
char *css = "div {color: yellowgreen}";
char *selector = "menu";
@ -247,7 +239,7 @@ int main(int argc, const char * argv[]) {
modest_finder_t* finder = modest_finder_create();
modest_finder_init(finder, myhtml_tree, stylesheet);
modest_finder_init(finder);
/* threads */
modest_finder_thread_t *finder_thread = modest_finder_thread_create();
@ -263,13 +255,6 @@ int main(int argc, const char * argv[]) {
//print_tree_after_all(modest, myhtml_tree, myhtml_tree->node_html, mycss_entry);
printf("\n\n------------\nInformation:\n");
printf("\tTicks/sec: %llu\n", (unsigned long long) myhtml_hperf_res(NULL));
myhtml_hperf_print("\tFound selectors", parse_start, parse_stop, stdout);

View File

@ -213,7 +213,7 @@ struct mycss_selectors {
struct mycss_selectors_entry {
mycss_selectors_type_t type;
int sub_type;
unsigned int sub_type;
mycss_selectors_flags_t flags;
mycss_namespace_entry_t* ns_entry;

View File

@ -45,8 +45,8 @@ extern "C" {
#define mctree_node_add(mctree) \
mctree->nodes_length++; \
if(mctree->nodes_length == mctree->nodes_size) { \
mctree->nodes_size += 4096; \
if(mctree->nodes_length >= mctree->nodes_size) { \
mctree->nodes_size = mctree->nodes_length + 4096; \
mctree->nodes = (mctree_node_t*)myhtml_realloc(mctree->nodes, \
sizeof(mctree_node_t) * mctree->nodes_size); \
} \

View File

@ -11,7 +11,7 @@ set(MODEST_PROJECT_SOURCE "${MODEST_PROJECT_DIR_ROOT}/source")
set(MODEST_VERSION_MAJOR 0)
set(MODEST_VERSION_MINOR 0)
set(MODEST_VERSION_PATCH 1)
set(MODEST_VERSION_PATCH 4)
set(MODEST_VERSION_STRING "${MODEST_VERSION_MAJOR}.${MODEST_VERSION_MINOR}.${MODEST_VERSION_PATCH}")
project(${MODEST_PROJECT_NAME})
@ -70,18 +70,22 @@ endif()
#########################
if(DEFINED MODEST_EXTERN_MALLOC)
add_definitions(-DMODEST_EXTERN_MALLOC=${MODEST_EXTERN_MALLOC})
add_definitions(-DMyHTML_EXTERN_MALLOC=${MODEST_EXTERN_MALLOC})
endif()
if(DEFINED MODEST_EXTERN_REALLOC)
add_definitions(-DMODEST_EXTERN_REALLOC=${MODEST_EXTERN_REALLOC})
add_definitions(-DMyHTML_EXTERN_REALLOC=${MODEST_EXTERN_REALLOC})
endif()
if(DEFINED MODEST_EXTERN_CALLOC)
add_definitions(-DMODEST_EXTERN_CALLOC=${MODEST_EXTERN_CALLOC})
add_definitions(-DMyHTML_EXTERN_CALLOC=${MODEST_EXTERN_CALLOC})
endif()
if(DEFINED MODEST_EXTERN_FREE)
add_definitions(-DMODEST_EXTERN_FREE=${MODEST_EXTERN_FREE})
add_definitions(-DMyHTML_EXTERN_FREE=${MODEST_EXTERN_FREE})
endif()
################
@ -126,6 +130,7 @@ endif()
if(MODEST_BUILD_WITHOUT_THREADS STREQUAL "YES")
message(STATUS "Build without POSIX Threads")
add_definitions(-DMODEST_BUILD_WITHOUT_THREADS)
add_definitions(-DMyHTML_BUILD_WITHOUT_THREADS)
else()
message(STATUS "Build with POSIX Threads")
endif()

View File

@ -569,7 +569,7 @@ bool modest_finder_selector_sub_type_pseudo_class_empty(modest_finder_t* finder,
bool modest_finder_selector_sub_type_pseudo_class_enabled(modest_finder_t* finder, myhtml_tree_node_t* base_node, mycss_selectors_entry_t* selector, mycss_selectors_specificity_t* spec)
{
return ~modest_finder_selector_sub_type_pseudo_class_disabled(finder, base_node, selector, spec);
return !modest_finder_selector_sub_type_pseudo_class_disabled(finder, base_node, selector, spec);
}
bool modest_finder_selector_sub_type_pseudo_class_first_child(modest_finder_t* finder, myhtml_tree_node_t* base_node, mycss_selectors_entry_t* selector, mycss_selectors_specificity_t* spec)
@ -692,7 +692,7 @@ bool modest_finder_selector_sub_type_pseudo_class_optional(modest_finder_t* find
base_node->tag_id == MyHTML_TAG_TEXTAREA)
{
if(base_node->token)
return ~modest_finder_match_attribute_only_key(base_node->token->attr_first, "required", 8);
return !modest_finder_match_attribute_only_key(base_node->token->attr_first, "required", 8);
else
return true;
}
@ -738,7 +738,7 @@ bool modest_finder_selector_sub_type_pseudo_class_read_write(modest_finder_t* fi
if(modest_finder_match_attribute_only_key(base_node->token->attr_first, "readonly", 8))
return false;
return ~modest_finder_selector_sub_type_pseudo_class_disabled(finder, base_node, selector, spec);
return !modest_finder_selector_sub_type_pseudo_class_disabled(finder, base_node, selector, spec);
}
return false;

View File

@ -227,6 +227,7 @@ modest_finder_thread_context_t * modest_finder_thread_create_context(modest_find
mcobject_async_node_delete(finder_thread->entry_obj, ctx[i].entry_node_id);
}
myhtml_free(ctx);
return NULL;
}
}
@ -246,6 +247,7 @@ modest_finder_thread_context_t * modest_finder_thread_create_context(modest_find
mcobject_async_node_delete(finder_thread->declaration_obj, ctx[i].declaration_node_id);
}
myhtml_free(ctx);
return NULL;
}
}

View File

@ -57,7 +57,6 @@ void modest_style_map_collate_declaration_padding(modest_t* modest, myhtml_tree_
return;
mycss_values_shorthand_four_t *val_four = (mycss_values_shorthand_four_t*)decl->value;
mycss_declaration_t* declaration = modest->mycss_entry->declaration;
if(val_four->two == NULL) {
modest_style_map_collate_declaration_for_all(modest, node, val_four->one, MyCSS_PROPERTY_TYPE_PADDING_TOP, spec);
@ -92,7 +91,6 @@ void modest_style_map_collate_declaration_margin(modest_t* modest, myhtml_tree_n
return;
mycss_values_shorthand_four_t *val_four = (mycss_values_shorthand_four_t*)decl->value;
mycss_declaration_t* declaration = modest->mycss_entry->declaration;
if(val_four->two == NULL) {
modest_style_map_collate_declaration_for_all(modest, node, val_four->one, MyCSS_PROPERTY_TYPE_MARGIN_LEFT, spec);
@ -127,7 +125,6 @@ void modest_style_map_collate_declaration_border_width(modest_t* modest, myhtml_
return;
mycss_values_shorthand_four_t *val_four = (mycss_values_shorthand_four_t*)decl->value;
mycss_declaration_t* declaration = modest->mycss_entry->declaration;
if(val_four->two == NULL) {
modest_style_map_collate_declaration_for_all(modest, node, val_four->one, MyCSS_PROPERTY_TYPE_BORDER_TOP_WIDTH, spec);

View File

@ -37,7 +37,7 @@ size_t mycss_convert_data_to_double(const char *data, size_t size, double *retur
*return_num = 0.0f;
switch (data[offset]) {
case '-': is_negative = true;
case '-': is_negative = true; /* fall through */
case '+': offset++;
}
@ -108,7 +108,7 @@ size_t mycss_convert_data_to_double(const char *data, size_t size, double *retur
{
++offset;
if(offset >= size || ((data[offset] != '-' || data[offset] != '+') &&
if(offset >= size || ((data[offset] != '-' || data[offset] != '+') ||
(data[offset] < '0' || data[offset] > '9'))) {
offset--;
}
@ -117,7 +117,7 @@ size_t mycss_convert_data_to_double(const char *data, size_t size, double *retur
is_negative = false;
switch(data[offset]) {
case '-': is_negative = true;
case '-': is_negative = true; /* fall through */
case '+': offset++;
}

View File

@ -142,6 +142,7 @@ mycss_declaration_entry_t * mycss_declaration_parse(mycss_declaration_t* declara
if(out_status)
*out_status = status;
entry->token_ready_callback = tmp_token_ready_callback;
return NULL;
}

View File

@ -335,9 +335,7 @@ bool mycss_declaration_serialization_font(mycss_entry_t* entry, mycss_declaratio
}
if(font->family) {
if(set_ws == false)
set_ws = true;
else
if(set_ws == true)
callback(" ", 1, context);
mycss_declaration_serialization_font_family(entry, font->family, callback, context);
@ -381,7 +379,7 @@ bool mycss_declaration_serialization_border_radius(mycss_entry_t* entry, mycss_d
}
if(value->four && ((mycss_values_shorthand_two_type_t*)(value->four->value))->one) {
if(o_e) callback(" ", 1, context); else o_e = true;
if(o_e) callback(" ", 1, context);
short_two_type = value->four->value;
mycss_property_serialization_value(short_two_type->type_one, short_two_type->one, callback, context);
@ -399,7 +397,9 @@ bool mycss_declaration_serialization_border_radius(mycss_entry_t* entry, mycss_d
if(value->two && ((mycss_values_shorthand_two_type_t*)(value->two->value))->two) {
if(o_e == false) callback(" / ", 3, context);
if(o_e) callback(" ", 1, context); else o_e = true;
else callback(" ", 1, context);
o_e = true;
short_two_type = value->two->value;
mycss_property_serialization_value(short_two_type->type_two, short_two_type->two, callback, context);
@ -407,7 +407,9 @@ bool mycss_declaration_serialization_border_radius(mycss_entry_t* entry, mycss_d
if(value->three && ((mycss_values_shorthand_two_type_t*)(value->three->value))->two) {
if(o_e == false) callback(" / ", 3, context);
if(o_e) callback(" ", 1, context); else o_e = true;
else callback(" ", 1, context);
o_e = true;
short_two_type = value->three->value;
mycss_property_serialization_value(short_two_type->type_two, short_two_type->two, callback, context);
@ -415,7 +417,7 @@ bool mycss_declaration_serialization_border_radius(mycss_entry_t* entry, mycss_d
if(value->four && ((mycss_values_shorthand_two_type_t*)(value->four->value))->two) {
if(o_e == false) callback(" / ", 3, context);
if(o_e) callback(" ", 1, context); else o_e = true;
else callback(" ", 1, context);
short_two_type = value->four->value;
mycss_property_serialization_value(short_two_type->type_two, short_two_type->two, callback, context);
@ -599,7 +601,8 @@ bool mycss_declaration_serialization_background_position(mycss_entry_t* entry, m
}
if(position->four.type) {
if(o_e) callback(" ", 1, context); else o_e = true;
if(o_e) callback(" ", 1, context);
mycss_property_serialization_value(position->four.type, position->four.length, callback, context);
}

View File

@ -74,7 +74,7 @@ bool mycss_declaration_state_ident(mycss_entry_t* entry, mycss_token_t* token, b
bool mycss_declaration_state_colon_before_important(mycss_entry_t* entry, mycss_token_t* token, bool last_response)
{
if(token->type == MyCSS_TOKEN_TYPE_WHITESPACE)
return token;
return true;
else if(token->type == MyCSS_TOKEN_TYPE_SEMICOLON) {
entry->parser = mycss_declaration_state_data;
return true;

View File

@ -203,9 +203,6 @@ myhtml_encoding_t mycss_encoding_check_charset_rule(const char* css, size_t size
size_t begin = 10;
size_t length = begin;
if(begin >= size)
return MyHTML_ENCODING_UTF_8;
while(length < size) {
if(css[length] == '"')
{

View File

@ -113,8 +113,14 @@ void mycss_namespace_entry_append_to_current(mycss_namespace_t* ns, mycss_namesp
mycss_status_t mycss_namespace_stylesheet_init(mycss_namespace_stylesheet_t* ns_stylesheet, mycss_entry_t* entry)
{
ns_stylesheet->name_tree = mctree_create(14);
if(ns_stylesheet->name_tree == NULL)
return MyCSS_STATUS_ERROR_NAMESPACE_CREATE;
ns_stylesheet->ns_id_counter = 0;
ns_stylesheet->entry_default = mycss_namespace_entry_create(entry->ns);
if(ns_stylesheet->entry_default == NULL)
return MyCSS_STATUS_ERROR_NAMESPACE_ENTRIES_CREATE;
mycss_namespace_entry_clean(ns_stylesheet->entry_default);
mycss_namespace_entry_clean(&ns_stylesheet->entry_undef);
@ -132,9 +138,6 @@ mycss_status_t mycss_namespace_stylesheet_init(mycss_namespace_stylesheet_t* ns_
myhtml_string_append(ns_stylesheet->entry_any.name, "*", 1);
ns_stylesheet->entry_any.ns_id = MyHTML_NAMESPACE_ANY;
if(ns_stylesheet->entry_default == NULL)
return MyCSS_STATUS_ERROR_NAMESPACE_ENTRIES_CREATE;
mycss_namespace_stylesheet_init_default(ns_stylesheet, entry, NULL, 0, MyHTML_NAMESPACE_ANY);
return MyCSS_STATUS_OK;

View File

@ -72,6 +72,9 @@ void mycss_namespace_parser_end(mycss_entry_t* entry, mycss_token_t* token)
void mycss_namespace_parser_expectations_error(mycss_entry_t* entry, mycss_token_t* token)
{
if(entry->ns->entry_last == NULL)
return;
mycss_namespace_entry_t *ns_entry = entry->ns->entry_last;
mycss_namespace_entry_destroy(ns_entry, entry, false);
@ -83,10 +86,7 @@ void mycss_namespace_parser_expectations_error(mycss_entry_t* entry, mycss_token
entry->ns->entry_last = NULL;
}
if(ns_entry)
mcobject_free(entry->ns->mcobject_entries, ns_entry);
printf("Expectations error: Namespace!\n");
}

View File

@ -1106,14 +1106,10 @@ bool mycss_property_parser_border_color(mycss_entry_t* entry, mycss_token_t* tok
unsigned int value_type = 0;
if(mycss_property_shared_default(entry, token, &value_type, &str))
{
if(value == NULL) {
dec_entry->value_type = value_type;
return mycss_property_parser_destroy_string(&str, mycss_property_shared_switch_to_find_important(entry));
}
return mycss_property_parser_destroy_string(&str, mycss_property_shared_switch_to_parse_error(entry));
}
mycss_declaration_entry_t* shared_declr;
dec_entry->value = value = mycss_values_create(entry, sizeof(mycss_values_shorthand_four_t));

View File

@ -375,6 +375,7 @@ bool mycss_property_shared_text_decoration_line(mycss_entry_t* entry, mycss_toke
*value_type = text_dec_type;
return true;
}
/* fall through */
default:
*value_type = MyCSS_PROPERTY_VALUE_UNDEF;

View File

@ -137,11 +137,11 @@ bool mycss_selectors_function_parser_not_or_matches_or_current_parser(mycss_entr
selectors_list = mycss_selectors_parser_check_selector_list(selectors, selectors_list);
if(selectors_list == NULL) {
if(selectors->entry_last)
if(selectors->entry_last) {
selectors->entry_last->value = NULL;
selectors->entry_last->flags |= MyCSS_SELECTORS_FLAGS_SELECTOR_BAD;
}
}
else if((selectors_list->flags & MyCSS_SELECTORS_FLAGS_SELECTOR_BAD) && selectors->entry_last) {
selectors->entry_last->flags |= MyCSS_SELECTORS_FLAGS_SELECTOR_BAD;
}
@ -198,11 +198,11 @@ bool mycss_selectors_function_parser_has(mycss_entry_t* entry, mycss_token_t* to
selectors_list = mycss_selectors_parser_check_selector_list(selectors, selectors_list);
if(selectors_list == NULL) {
if(selectors->entry_last)
if(selectors->entry_last) {
selectors->entry_last->value = NULL;
selectors->entry_last->flags |= MyCSS_SELECTORS_FLAGS_SELECTOR_BAD;
}
}
else if((selectors_list->flags & MyCSS_SELECTORS_FLAGS_SELECTOR_BAD) && selectors->entry_last) {
selectors->entry_last->flags |= MyCSS_SELECTORS_FLAGS_SELECTOR_BAD;
}
@ -324,10 +324,9 @@ bool mycss_selectors_function_parser_nth_with_selectors_need_of_after(mycss_entr
if(selectors_list == NULL) {
if(selectors->entry_last) {
mycss_selector_value_an_plus_b(selectors->entry_last->value)->of = NULL;
}
selectors->entry_last->flags |= MyCSS_SELECTORS_FLAGS_SELECTOR_BAD;
}
}
else if((selectors_list->flags & MyCSS_SELECTORS_FLAGS_SELECTOR_BAD) && selectors->entry_last) {
selectors->entry_last->flags |= MyCSS_SELECTORS_FLAGS_SELECTOR_BAD;
}

View File

@ -213,7 +213,7 @@ struct mycss_selectors {
struct mycss_selectors_entry {
mycss_selectors_type_t type;
int sub_type;
unsigned int sub_type;
mycss_selectors_flags_t flags;
mycss_namespace_entry_t* ns_entry;

View File

@ -228,6 +228,10 @@ bool mycss_selectors_serialization_selector(mycss_selectors_t* selectors, mycss_
break;
}
case MyCSS_SELECTORS_SUB_TYPE_PSEUDO_CLASS_FUNCTION_UNKNOWN:
callback("^UST", 4, context);
break;
default:
break;
}
@ -263,9 +267,6 @@ bool mycss_selectors_serialization_selector(mycss_selectors_t* selectors, mycss_
}
};
if(selector->sub_type == MyCSS_SELECTORS_SUB_TYPE_UNKNOWN)
callback("^UST", 4, context);
if(selector->flags & MyCSS_SELECTORS_FLAGS_SELECTOR_BAD)
callback("^B", 2, context);

View File

@ -124,6 +124,9 @@ size_t mycss_tokenizer_state_set_current_buffer_for_continue(mycss_entry_t* entr
while(buffer && buffer->offset > position)
buffer = buffer->prev;
if(buffer == NULL)
return 0;
entry->current_buffer = buffer;
return (position - buffer->offset);

View File

@ -63,7 +63,7 @@ mycss_values_color_id_t mycss_values_color_id_by_name(const char *name, size_t l
const char * mycss_values_color_name_by_id(mycss_values_color_id_t color_id, size_t *length)
{
if(color_id > MyCSS_VALUES_COLOR_ID_LAST_ENTRY) {
if(color_id >= MyCSS_VALUES_COLOR_ID_LAST_ENTRY) {
if(length)
*length = 0;
@ -119,7 +119,7 @@ mycss_values_color_function_id_t mycss_values_color_function_id_by_name(const ch
const char * mycss_values_color_function_name_by_id(mycss_values_color_function_id_t color_function_id, size_t *length)
{
if(color_function_id > MyCSS_VALUES_COLOR_FUNCTION_ID_LAST_ENTRY) {
if(color_function_id >= MyCSS_VALUES_COLOR_FUNCTION_ID_LAST_ENTRY) {
if(length)
*length = 0;

View File

@ -284,6 +284,7 @@ bool mycss_values_color_parser_rgb_before_alpha_percentage(mycss_entry_t* entry,
entry->parser = mycss_values_color_parser_rgb_alpha_percentage;
return true;
}
/* fall through */
default:
mycss_values_color_parser_switch_parser(entry);
@ -432,6 +433,7 @@ bool mycss_values_color_parser_rgb_before_alpha_number(mycss_entry_t* entry, myc
entry->parser = mycss_values_color_parser_rgb_alpha_number;
return true;
}
/* fall through */
default:
mycss_values_color_parser_switch_parser(entry);
@ -640,6 +642,7 @@ bool mycss_values_color_parser_hsl_before_alpha(mycss_entry_t* entry, mycss_toke
entry->parser = mycss_values_color_parser_hsl_alpha;
return true;
}
/* fall through */
default:
mycss_values_color_parser_switch_parser(entry);
@ -911,6 +914,7 @@ bool mycss_values_color_parser_hwb_before_alpha(mycss_entry_t* entry, mycss_toke
entry->parser = mycss_values_color_parser_hwb_alpha;
return true;
}
/* fall through */
default:
mycss_values_color_parser_switch_parser(entry);
@ -1000,6 +1004,7 @@ bool mycss_values_color_parser_gray_before_alpha(mycss_entry_t* entry, mycss_tok
entry->parser = mycss_values_color_parser_gray_alpha;
return true;
}
/* fall through */
default:
mycss_values_color_parser_switch_parser(entry);

View File

@ -586,7 +586,7 @@ void mycss_values_serialization_border(mycss_values_border_t* border, mycss_call
}
if(border->color) {
if(o_e) callback(" ", 1, context); else o_e = true;
if(o_e) callback(" ", 1, context);
mycss_declaration_serialization_entry_only_value(NULL, border->color, callback, context);
}
}

View File

@ -232,7 +232,7 @@ myfont_status_t myfont_load_table_cmap(myfont_font_t *mf)
if(table_offset == 0)
return MyFONT_STATUS_OK;
if(mf->file_size < (table_offset + 4))
if((table_offset + 4) > mf->file_size)
return MyFONT_STATUS_ERROR_TABLE_UNEXPECTED_ENDING;
/* get current data */

View File

@ -66,14 +66,14 @@ myfont_status_t myfont_glyf_load_data(myfont_font_t *mf, myfont_table_glyph_t *g
{
memset(&glyph->head, 0, sizeof(myfont_table_glyf_head_t));
/* get current data */
uint8_t *data = &mf->file_data[offset];
// load head
offset += 10;
if(offset > mf->file_size)
return MyFONT_STATUS_ERROR_TABLE_UNEXPECTED_ENDING;
/* get current data */
uint8_t *data = &mf->file_data[offset];
glyph->head.numberOfContours = myfont_read_16(&data);
glyph->head.xMin = myfont_read_16(&data);
glyph->head.yMin = myfont_read_16(&data);

View File

@ -23,10 +23,11 @@
const char myfont_table_name[][5] = {
"cmap", "head", "hhea", "hmtx", "maxp", "name",
"OS/2", "post", "cvt" , "fpgm", "glyf", "loca",
"prep", "CFF ", "VORG", "EBDT", "EBLC", "EBSC",
"BASE", "GDEF", "GPOS", "GSUB", "JSTF", "DSIG",
"gasp", "hdmx", "kern", "LTSH", "PCLT", "VDMX",
"vhea", "vmtx"
"prep", "gasp", "CFF" , "VORG", "SVG" , "EBDT",
"EBLC", "EBSC", "CBDT", "CBLC", "BASE", "GDEF",
"GPOS", "GSUB", "JSTF", "MATH", "DSIG", "hdmx",
"kern", "LTSH", "PCLT", "VDMX", "vhea", "vmtx",
"COLR", "CPAL"
};
myfont_font_t * myfont_create(void)
@ -152,7 +153,7 @@ myfont_status_t myfont_load(myfont_font_t *mf, const char *filepath)
if(mf->file_size < 12)
return MyFONT_STATUS_ERROR_TABLE_UNEXPECTED_ENDING;
uint8_t *data = (uint8_t*)mf->file_data;
uint8_t *data = mf->file_data;
mf->header.version_major = myfont_read_u16(&data);
mf->header.version_minor = myfont_read_u16(&data);

View File

@ -398,7 +398,7 @@ unsigned long myhtml_encoding_index_gb18030_ranges_code_point(unsigned long poin
return 0xe7c7;
// step 3
unsigned long offset = sizeof(myhtml_encoding_map_gb18030_ranges) / sizeof(unsigned long);
unsigned long offset = sizeof(myhtml_encoding_map_gb18030_ranges) / (sizeof(unsigned long) * 2);
unsigned long code_point_offset = 0;
while (offset) {

View File

@ -1434,35 +1434,50 @@ void myhtml_queue_add(myhtml_tree_t *tree, size_t begin, myhtml_token_node_t* to
}
}
qnode->token = token;
#ifndef MyHTML_BUILD_WITHOUT_THREADS
if(tree->flags & MyHTML_TREE_FLAGS_SINGLE_MODE) {
if(qnode) {
qnode->token = token;
myhtml_parser_worker(0, qnode);
myhtml_parser_stream(0, qnode);
}
tree->current_qnode = mythread_queue_node_malloc_limit(tree->myhtml->thread, tree->queue, 4, NULL);
}
else {
if(qnode)
qnode->token = token;
tree->current_qnode = mythread_queue_node_malloc_round(tree->myhtml->thread, tree->queue_entry, NULL);
}
#else
f(qnode) {
qnode->token = token;
myhtml_parser_worker(0, qnode);
myhtml_parser_stream(0, qnode);
}
tree->current_qnode = mythread_queue_node_malloc_limit(tree->myhtml->thread, tree->queue, 4, NULL);
#endif /* MyHTML_BUILD_WITHOUT_THREADS */
if(tree->current_qnode == NULL) {
// TODO: add return status
return;
}
tree->current_qnode->tree = tree;
tree->current_qnode->prev = qnode;
if(qnode)
if(qnode && token)
myhtml_tokenizer_calc_current_namespace(tree, token);
// TODO: add check created node
myhtml_token_node_malloc(tree->token, tree->current_token_node, tree->token->mcasync_token_id);
tree->current_token_node->raw_begin = tree->current_token_node->element_begin = (tree->global_offset + begin);

View File

@ -71,14 +71,6 @@ myhtml_status_t myhtml_tree_init(myhtml_tree_t* tree, myhtml_t* myhtml)
if(mcstatus)
return MyHTML_STATUS_TREE_ERROR_MCOBJECT_INIT;
if(status) {
myhtml->parse_state_func = NULL;
myhtml->insertion_func = NULL;
myhtml->thread = NULL;
return status;
}
tree->mchar = mchar_async_create(128, (4096 * 5));
tree->active_formatting = myhtml_tree_active_formatting_init(tree);
tree->open_elements = myhtml_tree_open_elements_init(tree);
@ -880,7 +872,7 @@ void myhtml_tree_list_insert_by_index(myhtml_tree_list_t* list, myhtml_tree_node
myhtml_tree_node_t** node_list = list->list;
memmove(&node_list[(index + 1)], &node_list[index], sizeof(myhtml_tree_node_t**) * (list->length - index));
memmove(&node_list[(index + 1)], &node_list[index], sizeof(myhtml_tree_node_t*) * (list->length - index));
list->list[index] = node;
list->length++;
@ -961,7 +953,7 @@ void myhtml_tree_open_elements_remove(myhtml_tree_t* tree, myhtml_tree_node_t* n
if(list[el_idx] == node)
{
memmove(&list[el_idx], &list[el_idx + 1], sizeof(myhtml_tree_node_t**) * (tree->open_elements->length - el_idx));
memmove(&list[el_idx], &list[el_idx + 1], sizeof(myhtml_tree_node_t*) * (tree->open_elements->length - el_idx));
tree->open_elements->length--;
break;
@ -1451,7 +1443,7 @@ void myhtml_tree_active_formatting_remove(myhtml_tree_t* tree, myhtml_tree_node_
if(list[el_idx] == node)
{
memmove(&list[el_idx], &list[el_idx + 1], sizeof(myhtml_tree_node_t**) * (tree->active_formatting->length - el_idx));
memmove(&list[el_idx], &list[el_idx + 1], sizeof(myhtml_tree_node_t*) * (tree->active_formatting->length - el_idx));
tree->active_formatting->length--;
break;
@ -1469,7 +1461,7 @@ void myhtml_tree_active_formatting_remove_by_index(myhtml_tree_t* tree, size_t i
{
myhtml_tree_node_t** list = tree->active_formatting->list;
memmove(&list[idx], &list[idx + 1], sizeof(myhtml_tree_node_t**) * (tree->active_formatting->length - idx));
memmove(&list[idx], &list[idx + 1], sizeof(myhtml_tree_node_t*) * (tree->active_formatting->length - idx));
tree->active_formatting->length--;
#ifdef DEBUG_MODE

View File

@ -54,14 +54,8 @@ static const unsigned char myhtml_utils_chars_map[] = {
size_t myhtml_strncasecmp(const char* str1, const char* str2, size_t size)
{
if(str1 == NULL) {
if(str2 == NULL)
return 0;
return 1;
}
else if(str2 == NULL) {
if(str1 == NULL)
if(str1 == NULL || str2 == NULL) {
if(str1 == str2)
return 0;
return 1;
@ -86,14 +80,8 @@ size_t myhtml_strncasecmp(const char* str1, const char* str2, size_t size)
size_t myhtml_strcasecmp(const char* str1, const char* str2)
{
if(str1 == NULL) {
if(str2 == NULL)
return 0;
return 1;
}
else if(str2 == NULL) {
if(str1 == NULL)
if(str1 == NULL || str2 == NULL) {
if(str1 == str2)
return 0;
return 1;
@ -119,14 +107,8 @@ size_t myhtml_strcasecmp(const char* str1, const char* str2)
size_t myhtml_strncmp(const char* str1, const char* str2, size_t size)
{
if(str1 == NULL) {
if(str2 == NULL)
return 0;
return 1;
}
else if(str2 == NULL) {
if(str1 == NULL)
if(str1 == NULL || str2 == NULL) {
if(str1 == str2)
return 0;
return 1;
@ -151,14 +133,8 @@ size_t myhtml_strncmp(const char* str1, const char* str2, size_t size)
size_t myhtml_strcmp(const char* str1, const char* str2)
{
if(str1 == NULL) {
if(str2 == NULL)
return 0;
return 1;
}
else if(str2 == NULL) {
if(str1 == NULL)
if(str1 == NULL || str2 == NULL) {
if(str1 == str2)
return 0;
return 1;
@ -184,14 +160,8 @@ size_t myhtml_strcmp(const char* str1, const char* str2)
size_t myhtml_strcmp_ws(const char* str1, const char* str2)
{
if(str1 == NULL) {
if(str2 == NULL)
return 0;
return 1;
}
else if(str2 == NULL) {
if(str1 == NULL)
if(str1 == NULL || str2 == NULL) {
if(str1 == str2)
return 0;
return 1;

View File

@ -354,14 +354,21 @@ void mcobject_async_node_delete(mcobject_async_t *mcobj_async, size_t node_idx)
while (chunk)
{
if(mcobj_async->chunk_cache_length >= mcobj_async->chunk_cache_size) {
mcobj_async->chunk_cache_size <<= 1;
size_t new_size = mcobj_async->chunk_cache_size << 1;
mcobject_async_chunk_t **tmp = (mcobject_async_chunk_t**)myhtml_realloc(mcobj_async->chunk_cache,
sizeof(mcobject_async_chunk_t*) * mcobj_async->chunk_cache_size);
sizeof(mcobject_async_chunk_t*) * new_size);
if(tmp)
if(tmp) {
mcobj_async->chunk_cache_size = new_size;
mcobj_async->chunk_cache = tmp;
}
else {
// TODO: add return status
mcsync_unlock(mcobj_async->mcsync);
return;
}
}
mcobj_async->chunk_cache[ mcobj_async->chunk_cache_length ] = chunk;
mcobj_async->chunk_cache_length++;

View File

@ -45,8 +45,8 @@ extern "C" {
#define mctree_node_add(mctree) \
mctree->nodes_length++; \
if(mctree->nodes_length == mctree->nodes_size) { \
mctree->nodes_size += 4096; \
if(mctree->nodes_length >= mctree->nodes_size) { \
mctree->nodes_size = mctree->nodes_length + 4096; \
mctree->nodes = (mctree_node_t*)myhtml_realloc(mctree->nodes, \
sizeof(mctree_node_t) * mctree->nodes_size); \
} \

View File

@ -65,9 +65,22 @@ test_res_t test_load_file(const char* filename)
exit(EXIT_FAILURE);
}
fseek(fh, 0L, SEEK_END);
if(fseek(fh, 0L, SEEK_END) != 0) {
fprintf(stderr, "Can't set position (fseek) in file: %s\n", filename);
exit(EXIT_FAILURE);
}
long size = ftell(fh);
fseek(fh, 0L, SEEK_SET);
if(fseek(fh, 0L, SEEK_SET) != 0) {
fprintf(stderr, "Can't set position (fseek) in file: %s\n", filename);
exit(EXIT_FAILURE);
}
if(size <= 0) {
fprintf(stderr, "Can't get file size or file is empty: %s\n", filename);
exit(EXIT_FAILURE);
}
char *file_data = (char*)malloc(size + 1);
if(file_data == NULL) {
@ -83,10 +96,6 @@ test_res_t test_load_file(const char* filename)
fclose(fh);
if(size < 0) {
size = 0;
}
return (test_res_t){file_data, (size_t)size};
}
@ -221,7 +230,10 @@ test_stat_t test_read_dir(const char* dir_path, test_read_dir_callback_f callbac
{
sprintf(&path[path_len], "/%s", ent->d_name);
stat(path, &path_stat);
if(stat(path, &path_stat) != 0) {
fprintf(stderr, "Can't get status for file: %s\n", path);
exit(EXIT_FAILURE);
}
if(ent->d_name[0] == '.' || S_ISDIR(path_stat.st_mode))
continue;