From a0c056ef6137086f24465db64dd7c5460804ac6f Mon Sep 17 00:00:00 2001 From: Nishi Date: Thu, 16 Apr 2026 14:36:28 +0900 Subject: [PATCH] safer --- example.c | 4 ++-- include/xemil.h | 2 +- src/core.c | 32 ++++++++++++++++---------------- 3 files changed, 19 insertions(+), 19 deletions(-) diff --git a/example.c b/example.c index 35f4209..0e04130 100644 --- a/example.c +++ b/example.c @@ -50,9 +50,9 @@ int main(int argc, char** argv) { for(i = 1; i < argc; i++) { xemil_t* h = xl_open_file(argv[i]); - h->param.new_text = 1; - h->param.do_xinclude = 1; if(h != NULL) { + h->param.new_text = 1; + h->param.do_xinclude = 1; printf("%s:\n", argv[i]); if(xl_parse(h)) { xl_node_t** r; diff --git a/include/xemil.h b/include/xemil.h index 039d7bd..270749c 100644 --- a/include/xemil.h +++ b/include/xemil.h @@ -148,7 +148,7 @@ XLDECL int xl_parse(xemil_t* handle); XLDECL void xl_close(xemil_t* handle); XLDECL char* xl_get_attribute(xl_node_t* node, const char* key); XLDECL void xl_free(xl_node_t* node); -XLDECL void xl_replace(xl_node_t* node, xl_node_t* new); +XLDECL void xl_replace(xl_node_t* node, xl_node_t* new_node); XLDECL xl_node_t** xl_get_nodes(xl_node_t* node, const char* name); /* NULL-terminated */ XLDECL xl_node_t** xl_get_path(xl_node_t* node, const char* path); /* NULL-terminated */ diff --git a/src/core.c b/src/core.c index f57a0f9..f824e6c 100644 --- a/src/core.c +++ b/src/core.c @@ -630,19 +630,19 @@ void xl_free(xl_node_t* node) { recursive_free(node); } -void xl_replace(xl_node_t* node, xl_node_t* new) { +void xl_replace(xl_node_t* node, xl_node_t* new_node) { xl_node_t* parent = node->parent; xl_node_t* child; - if(new->parent != NULL&& new->parent->first_child == new) { - new->parent->first_child = new->next; - if(new->next->prev != NULL) new->next->prev = NULL; + if(new_node->parent != NULL&& new_node->parent->first_child == new_node) { + new_node->parent->first_child = new_node->next; + if(new_node->next->prev != NULL) new_node->next->prev = NULL; } - if(new->parent != NULL) { - child = new->parent->first_child; + if(new_node->parent != NULL) { + child = new_node->parent->first_child; while(child != NULL) { - if(child == new) { + if(child == new_node) { if(child->prev != NULL) child->prev->next = child->next; if(child->next != NULL) child->next->prev = child->prev; } @@ -653,23 +653,23 @@ void xl_replace(xl_node_t* node, xl_node_t* new) { child = parent->first_child; if(child != NULL && child == node) { - parent->first_child = new; + parent->first_child = new_node; - new->parent = parent; - new->prev = NULL; - new->next = child->next; + new_node->parent = parent; + new_node->prev = NULL; + new_node->next = child->next; child = child->next; } while(child != NULL) { if(child == node) { - new->parent = parent; - new->next = child->next; - new->prev = child->prev; + new_node->parent = parent; + new_node->next = child->next; + new_node->prev = child->prev; - if(child->prev != NULL) child->prev->next = new; - if(child->next != NULL) child->next->prev = new; + if(child->prev != NULL) child->prev->next = new_node; + if(child->next != NULL) child->next->prev = new_node; } child = child->next;