mirror of
https://github.com/isar/libmdbx.git
synced 2025-01-02 00:04:12 +08:00
mdbx: minor fix/workaround to avoid UBSAN traps for memcpy(ptr, nullptr, 0).
This commit is contained in:
parent
8c29c3711d
commit
f11607dfa6
@ -12756,14 +12756,16 @@ static int __must_check_result mdbx_node_add_leaf(MDBX_cursor *mc,
|
|||||||
memcpy(nodedata, data->iov_base, sizeof(pgno_t));
|
memcpy(nodedata, data->iov_base, sizeof(pgno_t));
|
||||||
else if (unlikely(flags & MDBX_RESERVE))
|
else if (unlikely(flags & MDBX_RESERVE))
|
||||||
data->iov_base = nodedata;
|
data->iov_base = nodedata;
|
||||||
else if (likely(nodedata != data->iov_base))
|
else if (likely(nodedata != data->iov_base &&
|
||||||
|
data->iov_len /* to avoid UBSAN traps*/ != 0))
|
||||||
memcpy(nodedata, data->iov_base, data->iov_len);
|
memcpy(nodedata, data->iov_base, data->iov_len);
|
||||||
} else {
|
} else {
|
||||||
poke_pgno(nodedata, largepage->mp_pgno);
|
poke_pgno(nodedata, largepage->mp_pgno);
|
||||||
nodedata = page_data(largepage);
|
nodedata = page_data(largepage);
|
||||||
if (unlikely(flags & MDBX_RESERVE))
|
if (unlikely(flags & MDBX_RESERVE))
|
||||||
data->iov_base = nodedata;
|
data->iov_base = nodedata;
|
||||||
else if (likely(nodedata != data->iov_base))
|
else if (likely(nodedata != data->iov_base &&
|
||||||
|
data->iov_len /* to avoid UBSAN traps*/ != 0))
|
||||||
memcpy(nodedata, data->iov_base, data->iov_len);
|
memcpy(nodedata, data->iov_base, data->iov_len);
|
||||||
}
|
}
|
||||||
return MDBX_SUCCESS;
|
return MDBX_SUCCESS;
|
||||||
@ -13245,7 +13247,8 @@ static int mdbx_update_key(MDBX_cursor *mc, const MDBX_val *key) {
|
|||||||
/* But even if no shift was needed, update ksize */
|
/* But even if no shift was needed, update ksize */
|
||||||
node_set_ks(node, key->iov_len);
|
node_set_ks(node, key->iov_len);
|
||||||
|
|
||||||
memcpy(node_key(node), key->iov_base, key->iov_len);
|
if (likely(key->iov_len /* to avoid UBSAN traps*/ != 0))
|
||||||
|
memcpy(node_key(node), key->iov_base, key->iov_len);
|
||||||
return MDBX_SUCCESS;
|
return MDBX_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user