Skip to content

Commit e641047

Browse files
committed
Fix codeQL scan defects
1 parent 14ed769 commit e641047

File tree

2 files changed

+8
-7
lines changed

2 files changed

+8
-7
lines changed

src/map.c

+7-6
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020

2121
#include "map.h"
2222

23-
/* FIXME: Avoid relying on key_size and data_size */
23+
/* TODO: Avoid relying on key_size and data_size */
2424
struct map_head_t {
2525
map_node_t *root;
2626

@@ -110,7 +110,7 @@ static inline void rb_node_init(map_node_t *node)
110110
rb_node_set_right((r_node), (x_node)); \
111111
} while (0)
112112

113-
/* FIXME: embed cmp (00, 01, 11) into @node pointer as 'right_red' does */
113+
/* TODO: embed cmp (00, 01, 11) into @node pointer as 'right_red' does */
114114
typedef struct {
115115
map_node_t *node;
116116
map_cmp_t cmp;
@@ -131,7 +131,7 @@ static inline map_node_t *rb_search(map_t rb, const map_node_t *node)
131131
ret = rb_node_get_right(ret);
132132
break;
133133
default:
134-
//__UNREACHABLE;
134+
assert(0);
135135
break;
136136
}
137137
}
@@ -159,8 +159,7 @@ static void rb_insert(map_t rb, map_node_t *node)
159159
pathp[1].node = rb_node_get_right(pathp->node);
160160
break;
161161
default:
162-
assert(cmp != _CMP_EQUAL);
163-
//__UNREACHABLE;
162+
/* igore duplicate key */
164163
break;
165164
}
166165
}
@@ -230,7 +229,8 @@ static void rb_remove(map_t rb, map_node_t *node)
230229
* The path from root to seach target is recorded in pathp[i].
231230
*/
232231
path->node = rb->root;
233-
for (pathp = path; pathp->node; pathp++) {
232+
pathp = path;
233+
while (pathp->node) {
234234
map_cmp_t cmp = pathp->cmp = (rb->cmp)(node->data, pathp->node->data);
235235
if (cmp == _CMP_LESS) {
236236
pathp[1].node = rb_node_get_left(pathp->node);
@@ -247,6 +247,7 @@ static void rb_remove(map_t rb, map_node_t *node)
247247
break;
248248
}
249249
}
250+
pathp++;
250251
}
251252
assert(nodep && nodep->node == node);
252253

src/map.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ typedef struct map_node {
2222
struct map_node *left, *right_red; /* red-black tree */
2323
} map_node_t;
2424

25-
/* FIXME: Change to binary representation and utilize a pointer to the node
25+
/* TODO: Change to binary representation and utilize a pointer to the node
2626
* embedding comparator values similar to 'right_red'.
2727
* _CMP_EQUAL : 00
2828
* _CMP_GREATER : 01

0 commit comments

Comments
 (0)