Always check the length before returning the head or tail
This commit is contained in:
parent
34f1a9e7b4
commit
80cd0e9ae5
1 changed files with 6 additions and 0 deletions
|
|
@ -292,12 +292,18 @@ static inline void **rz_pvector_data(RzPVector *vec) {
|
||||||
// returns the first element of the vector
|
// returns the first element of the vector
|
||||||
static inline void *rz_pvector_head(RzPVector *vec) {
|
static inline void *rz_pvector_head(RzPVector *vec) {
|
||||||
rz_return_val_if_fail(vec, NULL);
|
rz_return_val_if_fail(vec, NULL);
|
||||||
|
if (vec->v.len < 1) {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
return ((void **)vec->v.a)[0];
|
return ((void **)vec->v.a)[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
// returns the last element of the vector
|
// returns the last element of the vector
|
||||||
static inline void *rz_pvector_tail(RzPVector *vec) {
|
static inline void *rz_pvector_tail(RzPVector *vec) {
|
||||||
rz_return_val_if_fail(vec, NULL);
|
rz_return_val_if_fail(vec, NULL);
|
||||||
|
if (vec->v.len < 1) {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
return ((void **)vec->v.a)[vec->v.len - 1];
|
return ((void **)vec->v.a)[vec->v.len - 1];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue