From d0f2fc6c1cce9a9ec19dda0b2e41d192ac48d435 Mon Sep 17 00:00:00 2001 From: NishiOwO Date: Mon, 2 Mar 2026 03:53:10 +0900 Subject: [PATCH] fix some bug --- include/xemil.h | 2 ++ src/core.c | 8 ++++++-- src/util.c | 8 ++++++++ 3 files changed, 16 insertions(+), 2 deletions(-) diff --git a/include/xemil.h b/include/xemil.h index 80755ba..33961aa 100644 --- a/include/xemil.h +++ b/include/xemil.h @@ -81,6 +81,8 @@ XLDECL xemil_t* xl_open_file(const char* filename); /* util.c */ XLDECL char* xl_util_trim(const char* str); +XLDECL char* xl_util_strdup(const char* str); + /* unicode.c */ XLDECL int xl_unicode_count(unsigned char c); diff --git a/src/core.c b/src/core.c index 04a3c69..bb066f6 100644 --- a/src/core.c +++ b/src/core.c @@ -293,6 +293,8 @@ int xl_parse(xemil_t* handle) { n->text = str; if(strlen(n->text) == 0) { + xl_node_t* o = n; + free(n->text); n->text = NULL; @@ -300,9 +302,9 @@ int xl_parse(xemil_t* handle) { if(n->next != NULL) n->next->prev = n->prev; n = n->next; - if(n != NULL) free(n->prev); + free(o); - if(n->prev == NULL) n->parent->first_child = n; + if(n != NULL && n->prev == NULL && n->parent != NULL) n->parent->first_child = n; continue; } @@ -480,6 +482,8 @@ int xl_parse(xemil_t* handle) { if(last->type == XL_NODE_TEXT){ old = last->text; + }else{ + last = NULL; } } }else{ diff --git a/src/util.c b/src/util.c index 6434a72..59e2b9a 100644 --- a/src/util.c +++ b/src/util.c @@ -74,3 +74,11 @@ char* xl_util_trim(const char* str) { return s; } + +char* xl_util_strdup(const char* str){ + char* s = malloc(strlen(str) + 1); + + strcpy(s, str); + + return s; +}