Skip to content

Commit 40a388d

Browse files
committed
Fix Coverity issues in RAVL tree
Fix Coverity issues in RAVL tree: - 468502 Dereference after null check - 462949 Overflowed return value Signed-off-by: Lukasz Dorau <lukasz.dorau@intel.com>
1 parent e09715a commit 40a388d

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

src/ravl/ravl.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,10 @@ static int ravl_node_rank(struct ravl_node *n) {
253253
*/
254254
static int ravl_node_rank_difference_parent(struct ravl_node *p,
255255
struct ravl_node *n) {
256-
return ravl_node_rank(p) - ravl_node_rank(n);
256+
int rv = ravl_node_rank(p) - ravl_node_rank(n);
257+
// assert to check integer overflow
258+
assert(rv < ravl_node_rank(p));
259+
return rv;
257260
}
258261

259262
/*
@@ -330,6 +333,7 @@ static void ravl_balance(struct ravl *ravl, struct ravl_node *n) {
330333
ravl_rotate(ravl, z);
331334
ravl_node_promote(z);
332335
ravl_node_demote(n);
336+
assert(y != NULL);
333337
ravl_node_demote(y);
334338
}
335339
}

0 commit comments

Comments
 (0)