diff --git a/src/include/binary_hist.h b/src/include/binary_hist.h index fc277ab64..0c10e85f1 100644 --- a/src/include/binary_hist.h +++ b/src/include/binary_hist.h @@ -42,6 +42,9 @@ binary_hist_init(struct binary_hist *bh, int start_bit, int num_buckets) static inline int binary_hist_size(const struct binary_hist *bh) { + if (!bh) + return -EINVAL; + return bh->bh_num_buckets; } diff --git a/test/raft-reference-client.c b/test/raft-reference-client.c index 4aeb2005f..9fc9a8142 100644 --- a/test/raft-reference-client.c +++ b/test/raft-reference-client.c @@ -1105,8 +1105,14 @@ raft_client_test_instance_hist_lreg_multi_facet_handler( struct raft_instance_hist_stats *rihs, struct lreg_value *lv) { - if (!lv || - lv->lrv_value_idx_in >= binary_hist_size(&rihs->rihs_bh)) + if (!lv || !rihs) + return -EINVAL; + + int hsz = binary_hist_size(&rihs->rihs_bh); + if (hsz < 0) + return hsz; + + if (lv->lrv_value_idx_in >= (uint32_t)hsz) return -EINVAL; else if (op == LREG_NODE_CB_OP_WRITE_VAL)