From: Noel Power Date: Fri, 24 May 2019 14:08:58 +0000 (+0000) Subject: lib/util: clang: Fix dereference of a null pointer warning X-Git-Tag: ldb-2.0.5~409 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=e104c01846f6b8bcfb4a3efb269b8b357d17eea6;p=thirdparty%2Fsamba.git lib/util: clang: Fix dereference of a null pointer warning Fixes: lib/util/rbtree.c:170:8: warning: Access to field 'rb_parent_color' results in a dereference of a null pointer (loaded from variable 'other') <--[clang] We could avoid accessing the NULL pointer but previously the code would have crashed here. Given this is a rbtree probably better to preserve the fatal nature of encountering a NULL pointer here while satisfying the static checker. Signed-off-by: Noel Power Reviewed-by: Gary Lockyer gary@catalyst.net.nz --- diff --git a/lib/util/rbtree.c b/lib/util/rbtree.c index b7add66234f..aa663f49f02 100644 --- a/lib/util/rbtree.c +++ b/lib/util/rbtree.c @@ -22,6 +22,7 @@ #include "replace.h" #include "rbtree.h" +#include "fault.h" #define RB_RED 0 #define RB_BLACK 1 @@ -167,6 +168,12 @@ static void __rb_erase_color(struct rb_node *node, struct rb_node *parent, if (parent->rb_left == node) { other = parent->rb_right; + if (other == NULL) { + /* we should never get here */ + smb_panic("corrupted rb tree"); + /* satisfy static checkers */ + return; + } if (rb_is_red(other)) { rb_set_black(other);