From: Andy Polyakov Date: Sun, 5 Aug 2018 14:56:54 +0000 (+0200) Subject: stack/stack.c: omit redundant NULL checks. X-Git-Tag: OpenSSL_1_1_1-pre9~51 X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=8839324;p=oweals%2Fopenssl.git stack/stack.c: omit redundant NULL checks. Checks are left in OPENSSL_sk_shift, OPENSSL_sk_pop and OPENSSL_sk_num. This is because these are used as "opportunistic" readers, pulling whatever datai, if any, set by somebody else. All calls that add data don't check for stack being NULL, because caller should have checked if stack was actually created. Reviewed-by: Rich Salz (Merged from https://github.com/openssl/openssl/pull/6860) --- diff --git a/crypto/stack/stack.c b/crypto/stack/stack.c index 975515db59..bb3a0a7dfc 100644 --- a/crypto/stack/stack.c +++ b/crypto/stack/stack.c @@ -226,9 +226,6 @@ OPENSSL_STACK *OPENSSL_sk_new_reserve(OPENSSL_sk_compfunc c, int n) 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); @@ -236,7 +233,7 @@ int OPENSSL_sk_reserve(OPENSSL_STACK *st, int n) int OPENSSL_sk_insert(OPENSSL_STACK *st, const void *data, int loc) { - if (st == NULL || st->num == max_nodes) + if (st->num == max_nodes) return 0; if (!sk_reserve(st, 1, 0)) @@ -278,7 +275,7 @@ void *OPENSSL_sk_delete_ptr(OPENSSL_STACK *st, const void *p) void *OPENSSL_sk_delete(OPENSSL_STACK *st, int loc) { - if (st == NULL || loc < 0 || loc >= st->num) + if (loc < 0 || loc >= st->num) return NULL; return internal_delete(st, loc); @@ -290,7 +287,7 @@ static int internal_find(OPENSSL_STACK *st, const void *data, const void *r; int i; - if (st == NULL || st->num == 0) + if (st->num == 0) return -1; if (st->comp == NULL) { @@ -325,8 +322,6 @@ int OPENSSL_sk_find_ex(OPENSSL_STACK *st, const void *data) int OPENSSL_sk_push(OPENSSL_STACK *st, const void *data) { - if (st == NULL) - return -1; return OPENSSL_sk_insert(st, data, st->num); } @@ -351,7 +346,7 @@ void *OPENSSL_sk_pop(OPENSSL_STACK *st) void OPENSSL_sk_zero(OPENSSL_STACK *st) { - if (st == NULL || st->num == 0) + if (st->num == 0) return; memset(st->data, 0, sizeof(*st->data) * st->num); st->num = 0; @@ -384,14 +379,14 @@ int OPENSSL_sk_num(const OPENSSL_STACK *st) void *OPENSSL_sk_value(const OPENSSL_STACK *st, int i) { - if (st == NULL || i < 0 || i >= st->num) + if (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 (st == NULL || i < 0 || i >= st->num) + if (i < 0 || i >= st->num) return NULL; st->data[i] = data; st->sorted = 0; @@ -400,7 +395,7 @@ void *OPENSSL_sk_set(OPENSSL_STACK *st, int i, const void *data) void OPENSSL_sk_sort(OPENSSL_STACK *st) { - if (st != NULL && !st->sorted && st->comp != NULL) { + if (!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 */ @@ -409,5 +404,5 @@ void OPENSSL_sk_sort(OPENSSL_STACK *st) int OPENSSL_sk_is_sorted(const OPENSSL_STACK *st) { - return st == NULL ? 1 : st->sorted; + return st->sorted; }