Commit b7f8804c72da18956d8a38b86251edb0f4977705

Thomas de Grivel 2023-02-11T12:24:26

make test ok

diff --git a/libc3/buf_parse.c b/libc3/buf_parse.c
index 80d5a97..218d687 100644
--- a/libc3/buf_parse.c
+++ b/libc3/buf_parse.c
@@ -488,9 +488,8 @@ sw buf_parse_fn_algo (s_buf *buf, s_list **dest)
     if (! r)
       break;
     result += r;
-    *t = list_new(NULL);
+    *t = list_new();
     (*t)->tag = tag;
-    tag_init_list(&(*t)->next, NULL);
     t = &(*t)->next.data.list;
     if ((r = buf_ignore_spaces(buf)) < 0)
       goto restore;
@@ -539,7 +538,7 @@ sw buf_parse_fn_pattern (s_buf *buf, s_list **dest)
     if ((r = buf_parse_tag(buf, &tag)) <= 0)
       goto restore;
     result += r;
-    *t = list_new(NULL);
+    *t = list_new();
     (*t)->tag = tag;
     t = &(*t)->next.data.list;
     if ((r = buf_ignore_spaces(buf)) < 0)
diff --git a/libc3/list.c b/libc3/list.c
index 460daef..a5edd3f 100644
--- a/libc3/list.c
+++ b/libc3/list.c
@@ -38,7 +38,8 @@ void list_clean (s_list *list)
 {
   if (list) {
     tag_clean(&list->tag);
-    tag_clean(&list->next);
+    if (list->next.type.type != TAG_LIST)
+      tag_clean(&list->next);
   }
 }
 
diff --git a/test/buf_parse_test.c b/test/buf_parse_test.c
index 22b5932..3fa8a01 100644
--- a/test/buf_parse_test.c
+++ b/test/buf_parse_test.c
@@ -22,6 +22,7 @@
 #include "../libc3/list.h"
 #include "../libc3/str.h"
 #include "../libc3/integer.h"
+#include "../libc3/tag.h"
 #include "../libc3/tuple.h"
 #include "test.h"
 
@@ -560,6 +561,18 @@
     buf_clean(&buf);                                                   \
   } while (0)
 
+#define BUF_PARSE_TEST_TAG(test)                                       \
+  do {                                                                 \
+    s_buf buf;                                                         \
+    s_tag dest;                                                        \
+    bzero(&dest, sizeof(dest));                                        \
+    test_context("buf_parse_tag(" # test ")");                         \
+    buf_init_1(&buf, (test));                                          \
+    TEST_EQ(buf_parse_tag(&buf, &dest), strlen(test));                 \
+    buf_clean(&buf);                                                   \
+    tag_clean(&dest);                                                  \
+  } while (0)
+
 #define BUF_PARSE_TEST_TUPLE(test)                                     \
   do {                                                                 \
     s_buf buf;                                                         \
@@ -593,6 +606,7 @@ void buf_parse_test_str ();
 void buf_parse_test_str_character ();
 void buf_parse_test_str_u8 ();
 void buf_parse_test_sym ();
+void buf_parse_test_tag ();
 void buf_parse_test_tuple ();
 
 void buf_parse_test ()
@@ -618,6 +632,7 @@ void buf_parse_test ()
   buf_parse_test_sym();
   buf_parse_test_ident();
   buf_parse_test_list();
+  buf_parse_test_tag();
   buf_parse_test_tuple();
 }
 
@@ -1128,6 +1143,13 @@ void buf_parse_test_sym ()
   BUF_PARSE_TEST_SYM(":az09AZ", "az09AZ");
 }
 
+void buf_parse_test_tag ()
+{
+  BUF_PARSE_TEST_TAG("x");
+  BUF_PARSE_TEST_TAG("_x");
+  BUF_PARSE_TEST_TAG("[x | _y]");
+}
+
 void buf_parse_test_tuple ()
 {
   BUF_PARSE_TEST_TUPLE("{a, b}");