96 static int cx_kvl_insert_iter( |
96 static int cx_kvl_insert_iter( |
97 struct cx_iterator_s *iter, |
97 struct cx_iterator_s *iter, |
98 const void *elem, |
98 const void *elem, |
99 int prepend |
99 int prepend |
100 ) { |
100 ) { |
101 cx_kv_list *kv_list = (cx_kv_list*)iter->src_handle.m; |
101 cx_kv_list *kv_list = iter->src_handle.m; |
102 // TODO: trick the base method by adding the required space for the key to the elem_size |
102 // TODO: trick the base method by adding the required space for the key to the elem_size |
103 return kv_list->list_methods->insert_iter(iter, elem, prepend); |
103 return kv_list->list_methods->insert_iter(iter, elem, prepend); |
104 } |
104 } |
105 |
105 |
106 static size_t cx_kvl_remove( |
106 static size_t cx_kvl_remove( |
111 ) { |
111 ) { |
112 cx_kv_list *kv_list = (cx_kv_list*)list; |
112 cx_kv_list *kv_list = (cx_kv_list*)list; |
113 // TODO: always use the target buffer to get the element first, |
113 // TODO: always use the target buffer to get the element first, |
114 // then obtain the key, remove it from the map, |
114 // then obtain the key, remove it from the map, |
115 // and finally call any destructors manually |
115 // and finally call any destructors manually |
|
116 // TODO: map destructors are not called |
116 return kv_list->list_methods->remove(list, index, num, targetbuf); |
117 return kv_list->list_methods->remove(list, index, num, targetbuf); |
117 } |
118 } |
118 |
119 |
119 static void cx_kvl_clear(struct cx_list_s *list) { |
120 static void cx_kvl_clear(struct cx_list_s *list) { |
120 cx_kv_list *kv_list = (cx_kv_list*)list; |
121 cx_kv_list *kv_list = (cx_kv_list*)list; |
|
122 // FIXME: this is probably totally bugged, because |
|
123 // a) the map may have destructors which are invoked triggering UAF |
|
124 // b) the destructors registered with the map are not called for all list elements |
121 kv_list->list_methods->clear(list); |
125 kv_list->list_methods->clear(list); |
122 // also clear all lookup entries |
126 // also clear all lookup entries |
123 cxMapClear(&kv_list->map->map_base.base); |
127 cxMapClear(&kv_list->map->map_base.base); |
124 } |
128 } |
125 |
129 |
144 struct cx_list_s *list, |
148 struct cx_list_s *list, |
145 const void *elem, |
149 const void *elem, |
146 bool remove |
150 bool remove |
147 ) { |
151 ) { |
148 cx_kv_list *kv_list = (cx_kv_list*)list; |
152 cx_kv_list *kv_list = (cx_kv_list*)list; |
149 // TODO: implement removal of the key in the map |
153 // TODO: implement removal of the key in the map and calling the map destructors |
150 return kv_list->list_methods->find_remove(list, elem, remove); |
154 return kv_list->list_methods->find_remove(list, elem, remove); |
151 } |
155 } |
152 |
156 |
153 static void cx_kvl_sort(struct cx_list_s *list) { |
157 static void cx_kvl_sort(struct cx_list_s *list) { |
154 cx_kv_list *kv_list = (cx_kv_list*)list; |
158 cx_kv_list *kv_list = (cx_kv_list*)list; |