Skip to content

Commit

Permalink
Always check the length before returning the head or tail
Browse files Browse the repository at this point in the history
  • Loading branch information
wargio committed Apr 23, 2024
1 parent 34f1a9e commit b2a4f6c
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions librz/include/rz_vector.h
Original file line number Diff line number Diff line change
Expand Up @@ -292,12 +292,18 @@ static inline void **rz_pvector_data(RzPVector *vec) {
// returns the first element of the vector
static inline void *rz_pvector_head(RzPVector *vec) {
rz_return_val_if_fail(vec, NULL);
if (vec->v.len < 1) {
return NULL;
}
return ((void **)vec->v.a)[0];
}

// returns the last element of the vector
static inline void *rz_pvector_tail(RzPVector *vec) {
rz_return_val_if_fail(vec, NULL);
if (vec->v.len < 1) {
return NULL;
}
return ((void **)vec->v.a)[vec->v.len - 1];
}

Expand Down

0 comments on commit b2a4f6c

Please sign in to comment.