From cc43f73bbbdfd1cb6d7129c82e2d221181a3cac3 Mon Sep 17 00:00:00 2001
From: Cyrille Bagard <nocbos@gmail.com>
Date: Sun, 8 Oct 2023 10:49:59 +0200
Subject: Handle anonymous item in Kaitai definitions.

---
 plugins/kaitai/parsers/attribute.c        |  5 +++--
 plugins/kaitai/python/parsers/attribute.c |  9 +++++++--
 plugins/kaitai/record.c                   | 14 +++++++++-----
 3 files changed, 19 insertions(+), 9 deletions(-)

diff --git a/plugins/kaitai/parsers/attribute.c b/plugins/kaitai/parsers/attribute.c
index 3eb406a..58d8dd1 100644
--- a/plugins/kaitai/parsers/attribute.c
+++ b/plugins/kaitai/parsers/attribute.c
@@ -243,7 +243,7 @@ GKaitaiAttribute *g_kaitai_attribute_new(GYamlNode *parent)
 
     result = g_object_new(G_TYPE_KAITAI_ATTRIBUTE, NULL);
 
-    if (!g_kaitai_attribute_create(result, parent, true))
+    if (!g_kaitai_attribute_create(result, parent, false /* TODO : REMME ? */))
         g_clear_object(&result);
 
     return result;
@@ -1018,7 +1018,8 @@ static GKaitaiAttribute *g_kaitai_attribute_dup_for(const GKaitaiAttribute *attr
      * Les travaux de copie ne portent ainsi que sur le présent attribut.
      */
 
-    result->raw_id = strdup(attrib->raw_id);
+    if (attrib->raw_id != NULL)
+        result->raw_id = strdup(attrib->raw_id);
 
     if (attrib->orig_id != NULL)
         result->orig_id = strdup(attrib->orig_id);
diff --git a/plugins/kaitai/python/parsers/attribute.c b/plugins/kaitai/python/parsers/attribute.c
index 638e23e..c2f3db6 100644
--- a/plugins/kaitai/python/parsers/attribute.c
+++ b/plugins/kaitai/python/parsers/attribute.c
@@ -149,9 +149,14 @@ static PyObject *py_kaitai_attribute_get_raw_id(PyObject *self, void *closure)
     attrib = G_KAITAI_ATTRIBUTE(pygobject_get(self));
 
     value = g_kaitai_attribute_get_raw_id(attrib);
-    assert(value != NULL);
 
-    result = PyUnicode_FromString(value);
+    if (value == NULL)
+    {
+        result = Py_None;
+        Py_INCREF(result);
+    }
+    else
+        result = PyUnicode_FromString(value);
 
     return result;
 
diff --git a/plugins/kaitai/record.c b/plugins/kaitai/record.c
index 5717b17..db573ed 100644
--- a/plugins/kaitai/record.c
+++ b/plugins/kaitai/record.c
@@ -331,12 +331,16 @@ static GMatchRecord *_g_match_record_find_by_name(GMatchRecord *record, const ch
     {
         label = g_kaitai_attribute_get_label(G_KAITAI_ATTRIBUTE(record->creator));
 
-        label_len = strlen(label);
-
-        if (label_len == len && strncmp(label, name, len) == 0)
+        if (label != NULL)
         {
-            result = record;
-            g_object_ref(G_OBJECT(result));
+            label_len = strlen(label);
+
+            if (label_len == len && strncmp(label, name, len) == 0)
+            {
+                result = record;
+                g_object_ref(G_OBJECT(result));
+            }
+
         }
 
     }
-- 
cgit v0.11.2-87-g4458