Always check the length of RzVector when accessing the tail elem

This commit is contained in:
wargio 2024-04-23 10:36:40 +08:00 committed by Giovanni
parent 80cd0e9ae5
commit e08ceb9bd7

View file

@ -113,6 +113,9 @@ static inline void *rz_vector_head(const RzVector *vec) {
// returns a pointer to the last element of the vector
static inline void *rz_vector_tail(RzVector *vec) {
rz_return_val_if_fail(vec, NULL);
if (vec->len < 1) {
return NULL;
}
return (char *)vec->a + vec->elem_size * (vec->len - 1);
}