Skip to content

Commit 2e013a0

Browse files
committed
COMMON code cleanup
1 parent 4248945 commit 2e013a0

File tree

2 files changed

+23
-17
lines changed

2 files changed

+23
-17
lines changed

src/common/scan.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1623,7 +1623,7 @@ char *comp_array_uds_field(char *p, bc_t *bc) {
16231623
char *p_begin = p;
16241624

16251625
while (1) {
1626-
if (*p == 0 || !isalnum(*p)) {
1626+
if (*p == 0 || (*p != '_' && !isalnum(*p))) {
16271627
int len = (p - p_begin);
16281628
if (len) {
16291629
bc_add_code(bc, kwTYPE_UDS_EL);

src/common/var_hash.c

Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -70,14 +70,18 @@ Element *create_int_element(int key) {
7070
* cleanup the given element
7171
*/
7272
void 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
*/
109113
int 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) {
155159
var_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
*/
213217
var_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
*/
306310
void 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

Comments
 (0)