diff options
author | dec05eba <dec05eba@protonmail.com> | 2021-07-03 18:19:05 +0200 |
---|---|---|
committer | dec05eba <dec05eba@protonmail.com> | 2021-07-03 18:19:05 +0200 |
commit | c545ae2d90170de11806393acda197a0ca43f488 (patch) | |
tree | b3d11734e7cc7cb2c7f111a126ad52906e88d7d7 | |
parent | 8f41cc827b3c4096da4cd770175f43a085231bbf (diff) |
Fix string_append incorrect allocation size
-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; } |