diff options
-rw-r--r-- | include/quickmedia/HtmlSearch.h | 2 | ||||
-rw-r--r-- | src/HtmlSearch.c | 7 |
2 files changed, 6 insertions, 3 deletions
diff --git a/include/quickmedia/HtmlSearch.h b/include/quickmedia/HtmlSearch.h index 1a7faca..af9bd7e 100644 --- a/include/quickmedia/HtmlSearch.h +++ b/include/quickmedia/HtmlSearch.h @@ -67,7 +67,7 @@ QuickMediaStringView quickmedia_html_node_get_text(QuickMediaMatchNode *self); /* @node is only valid within the callback function scope. Return 0 to continue */ typedef int (*QuickMediaHtmlSearchResultCallback)(QuickMediaMatchNode *node, void *userdata); -/* |html_source| should be in utf8 format and may contain utf8 BOM */ +/* |html_source| should be in utf8 format and may contain utf8 BOM. |html_source| has to be valid until |quickmedia_html_search_deinit| is called. */ int quickmedia_html_search_init(QuickMediaHtmlSearch *self, const char *html_source, size_t size); void quickmedia_html_search_deinit(QuickMediaHtmlSearch *self); diff --git a/src/HtmlSearch.c b/src/HtmlSearch.c index bc58881..d72055a 100644 --- a/src/HtmlSearch.c +++ b/src/HtmlSearch.c @@ -43,7 +43,10 @@ static int string_ensure_capacity(QuickMediaString *self, size_t new_capacity) { } static int string_append(QuickMediaString *self, const char *str, size_t size) { - int res = string_ensure_capacity(self, self->size + size); + if(size == 0) + return 0; + + int res = string_ensure_capacity(self, self->size + size + 1); if(res != 0) return res; @@ -445,7 +448,7 @@ static int merge_inner_text(QuickMediaHtmlNode *node, QuickMediaString *str) { const char *inner_text = node->name.data; size_t inner_text_size = node->name.size; strip(inner_text, inner_text_size, &inner_text, &inner_text_size, is_newline); - if(inner_text_size > 0) { + if(inner_text_size > 0) { /* ignore empty text, but add the original text */ if(string_append(str, node->name.data, node->name.size) != 0) return 1; } |