src/kv_list.c

changeset 1370
607f822c79fe
parent 1369
a9989e16f7df
child 1371
37dcaeebe5ca
--- a/src/kv_list.c	Thu Sep 11 19:59:49 2025 +0200
+++ b/src/kv_list.c	Thu Sep 11 20:09:33 2025 +0200
@@ -238,16 +238,19 @@
     kv_list->list.base.collection.sorted = false;
     // TODO: use the same trick as above to increase the element size temporarily to add the key to the data
     void *node_data = kv_list->list_methods->insert_element(
-        &kv_list->list.base, kv_list->list.base.collection.size, value);
+        &kv_list->list.base, kv_list->list.base.collection.size,
+        kv_list->list.base.collection.store_pointer ? &value : value);
     if (node_data == NULL) return NULL; // LCOV_EXCL_LINE
     // then insert the key into the map, referring to the node data
-    // TODO: check if we still get a correct pointer when the list is storing pointers
     return kv_list->map_methods->put(map, key, node_data);
 }
 
 void *cx_kvl_map_get(const CxMap *map, CxHashKey key) {
     cx_kv_list *kv_list = ((struct cx_kv_list_map_s*)map)->list;
-    return kv_list->map_methods->get(map, key);
+    void *node_data = kv_list->map_methods->get(map, key);
+    if (node_data == NULL) return NULL; // LCOV_EXCL_LINE
+    // return the node data
+    return kv_list->list.base.collection.store_pointer ? *(void**)node_data : node_data;
 }
 
 int cx_kvl_map_remove(CxMap *map, CxHashKey key, void *targetbuf) {

mercurial