1. malloc(0) depends on libary's behavior:
https://pubs.opengroup.org/onlinepubs/
009695399/functions/malloc.html
2. There's below frame path which call malloc(0)
# build_simple_crush_map
# |--> crush.add_bucket(0, 0, CRUSH_HASH_DEFAULT, root_type, 0, NULL, NULL, &rootid);
# |--> crush_bucket *b = crush_make_bucket(crush, alg, hash, type, size, items, weights);
# |--> crush_make_straw2_bucket(map, hash, type, size, items, weights);
# |--> bucket->h.items = malloc(sizeof(__s32)*size);
# |--> ceph_assert(b);
If the library return NULL(malloc(0)), ceph_assert(b) will trigger abort
Signed-off-by: Changcheng Liu <changcheng.liu@aliyun.com>
bucket->h.weight = size * item_weight;
bucket->item_weight = item_weight;
+
+ if (size == 0) {
+ return bucket;
+ }
bucket->h.items = malloc(sizeof(__s32)*size);
if (!bucket->h.items)
bucket->h.type = type;
bucket->h.size = size;
+ if (size == 0) {
+ return bucket;
+ }
+
bucket->h.items = malloc(sizeof(__s32)*size);
if (!bucket->h.items)
goto err;
bucket->h.type = type;
bucket->h.size = size;
+ if (size == 0) {
+ return bucket;
+ }
+
bucket->h.items = malloc(sizeof(__s32)*size);
if (!bucket->h.items)
goto err;