int OPENSSL_sk_reserve(OPENSSL_STACK *st, int n)
{
+ if (st == NULL)
+ return 0;
+
if (n < 0)
return 1;
return sk_reserve(st, n, 1);
int OPENSSL_sk_insert(OPENSSL_STACK *st, const void *data, int loc)
{
- if (st->num == max_nodes)
+ if (st == NULL || st->num == max_nodes)
return 0;
if (!sk_reserve(st, 1, 0))
void *OPENSSL_sk_delete(OPENSSL_STACK *st, int loc)
{
- if (loc < 0 || loc >= st->num)
+ if (st == NULL || loc < 0 || loc >= st->num)
return NULL;
return internal_delete(st, loc);
const void *r;
int i;
- if (st->num == 0)
+ if (st == NULL || st->num == 0)
return -1;
if (st->comp == NULL) {
int OPENSSL_sk_push(OPENSSL_STACK *st, const void *data)
{
+ if (st == NULL)
+ return -1;
return OPENSSL_sk_insert(st, data, st->num);
}
void OPENSSL_sk_zero(OPENSSL_STACK *st)
{
- if (st->num == 0)
+ if (st == NULL || st->num == 0)
return;
memset(st->data, 0, sizeof(*st->data) * st->num);
st->num = 0;
void *OPENSSL_sk_value(const OPENSSL_STACK *st, int i)
{
- if (i < 0 || i >= st->num)
+ if (st == NULL || i < 0 || i >= st->num)
return NULL;
return (void *)st->data[i];
}
void *OPENSSL_sk_set(OPENSSL_STACK *st, int i, const void *data)
{
- if (i < 0 || i >= st->num)
+ if (st == NULL || i < 0 || i >= st->num)
return NULL;
st->data[i] = data;
st->sorted = 0;
void OPENSSL_sk_sort(OPENSSL_STACK *st)
{
- if (!st->sorted && st->comp != NULL) {
+ if (st != NULL && !st->sorted && st->comp != NULL) {
if (st->num > 1)
qsort(st->data, st->num, sizeof(void *), st->comp);
st->sorted = 1; /* empty or single-element stack is considered sorted */
int OPENSSL_sk_is_sorted(const OPENSSL_STACK *st)
{
- return st->sorted;
+ return st == NULL ? 1 : st->sorted;
}