@@ -70,14 +70,18 @@ Element *create_int_element(int key) {
7070 * cleanup the given element
7171 */
7272void delete_element (Element * element ) {
73+ // cleanup v_new
7374 v_free (element -> key );
74- tmp_free (element -> key ); // cleanup v_new
75+ tmp_free (element -> key );
7576
77+ // cleanup v_new
7678 if (element -> value ) {
7779 v_free (element -> value );
78- tmp_free (element -> value ); // cleanup v_new
80+ tmp_free (element -> value );
7981 }
80- tmp_free (element ); // cleanup create_element()
82+
83+ // cleanup create_element()
84+ tmp_free (element );
8185}
8286
8387/**
@@ -107,7 +111,7 @@ int hash_compare(const var_p_t var_a, const var_p_t var_b) {
107111 * Return true if the structure is empty
108112 */
109113int hash_is_empty (const var_p_t var_p ) {
110- return (var_p -> v .hash == 0 );
114+ return (var_p -> v .hash == NULL );
111115}
112116
113117/**
@@ -155,7 +159,7 @@ void hash_elem_cb(const void *nodep, VISIT value, int level) {
155159var_p_t hash_elem (const var_p_t var_p , int index ) {
156160 cb .count = 0 ;
157161 cb .index = index ;
158- cb .var = 0 ;
162+ cb .var = NULL ;
159163 if (var_p -> type == V_HASH ) {
160164 twalk (var_p -> v .hash , hash_elem_cb );
161165 }
@@ -211,7 +215,7 @@ void hash_insert_key(var_p_t base, var_p_t var_key, var_p_t *result) {
211215 * if they don't already exist.
212216 */
213217var_p_t hash_resolve_fields (const var_p_t base ) {
214- var_p_t field = 0 ;
218+ var_p_t field = NULL ;
215219 if (code_peek () == kwTYPE_UDS_EL ) {
216220 code_skipnext ();
217221 if (code_peek () != kwTYPE_STR ) {
@@ -265,7 +269,7 @@ void hash_get_value(var_p_t base, var_p_t var_key, var_p_t *result) {
265269 Element * key = create_int_element (i );
266270 key -> value = v_new ();
267271 v_set (key -> value , element );
268- tsearch (key , & base -> v .hash , cmp_fn );
272+ tsearch (key , & ( base -> v .hash ) , cmp_fn );
269273 }
270274
271275 // free the clone
@@ -296,23 +300,25 @@ void hash_set_cb(const void *nodep, VISIT value, int level) {
296300 Element * key = create_element (element -> key );
297301 key -> value = v_new ();
298302 v_set (key -> value , element -> value );
299- tsearch (key , & cb .hash , cmp_fn );
303+ tsearch (key , & ( cb .hash ) , cmp_fn );
300304 }
301305}
302306
303307/**
304- * Reference values from one structure to another
308+ * copy values from one structure to another
305309 */
306310void hash_set (var_p_t dest , const var_p_t src ) {
307- v_free (dest );
308- cb .hash = 0 ;
311+ if (dest != src ) {
312+ v_free (dest );
313+ cb .hash = NULL ;
309314
310- if (src -> type == V_HASH ) {
311- twalk (src -> v .hash , hash_set_cb );
312- }
315+ if (src -> type == V_HASH ) {
316+ twalk (src -> v .hash , hash_set_cb );
317+ }
313318
314- dest -> type = V_HASH ;
315- dest -> v .hash = cb .hash ;
319+ dest -> type = V_HASH ;
320+ dest -> v .hash = cb .hash ;
321+ }
316322}
317323
318324/**
0 commit comments