nasa / bplib

Apache License 2.0
27 stars 13 forks source link

Scan-build reports null pointer dereference in rb_tree #17

Closed jpswinski closed 5 years ago

jpswinski commented 5 years ago

$ scan-build make COMPILER=clang TOOLCHAIN=llvm

jpswinski commented 5 years ago

Ran on dd1463a701ed55c210153cd53e7e91e76e56eae3

jpswinski commented 5 years ago

Analysis of try_insert_rebalance function in rb_tree.c shows that the calls in question by scan-build (the rotate_right and rotate_left at the bottom of the function) are safe to make since logic that precedes them guarantees that the N,P,G relationship is in essence a straight line which means that the left node for rotating right and the right node for rotating left is always P which is not null.

An assert was added to both functions to pass the scan-build.

87a65ba7cbc8566155fce40bc7b7effc327fee82