OpenCoverage

stack.c

Absolute File Name:/home/opencoverage/opencoverage/guest-scripts/openssl/src/crypto/stack/stack.c
Source codeSwitch to Preprocessed file
LineSourceCount
1/*-
2 * Copyright 1995-2018 The OpenSSL Project Authors. All Rights Reserved.-
3 *-
4 * Licensed under the OpenSSL license (the "License"). You may not use-
5 * this file except in compliance with the License. You can obtain a copy-
6 * in the file LICENSE in the source distribution or at-
7 * https://www.openssl.org/source/license.html-
8 */-
9-
10#include <stdio.h>-
11#include "internal/cryptlib.h"-
12#include "internal/numbers.h"-
13#include <openssl/stack.h>-
14#include <openssl/objects.h>-
15#include <errno.h>-
16#include <openssl/e_os2.h> /* For ossl_inline */-
17-
18/*-
19 * The initial number of nodes in the array.-
20 */-
21static const int min_nodes = 4;-
22static const int max_nodes = SIZE_MAX / sizeof(void *) < INT_MAX-
23 ? (int)(SIZE_MAX / sizeof(void *))-
24 : INT_MAX;-
25-
26struct stack_st {-
27 int num;-
28 const void **data;-
29 int sorted;-
30 int num_alloc;-
31 OPENSSL_sk_compfunc comp;-
32};-
33-
34OPENSSL_sk_compfunc OPENSSL_sk_set_cmp_func(OPENSSL_STACK *sk, OPENSSL_sk_compfunc c)-
35{-
36 OPENSSL_sk_compfunc old = sk->comp;-
37-
38 if (sk->comp != c)
sk->comp != cDescription
TRUEevaluated 18503 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEnever evaluated
0-18503
39 sk->sorted = 0;
executed 18503 times by 1 test: sk->sorted = 0;
Executed by:
  • libcrypto.so.1.1
18503
40 sk->comp = c;-
41-
42 return old;
executed 18503 times by 1 test: return old;
Executed by:
  • libcrypto.so.1.1
18503
43}-
44-
45OPENSSL_STACK *OPENSSL_sk_dup(const OPENSSL_STACK *sk)-
46{-
47 OPENSSL_STACK *ret;-
48-
49 if ((ret = OPENSSL_malloc(sizeof(*ret))) == NULL) {
(ret = CRYPTO_...== ((void *)0)Description
TRUEnever evaluated
FALSEevaluated 32389 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-32389
50 CRYPTOerr(CRYPTO_F_OPENSSL_SK_DUP, ERR_R_MALLOC_FAILURE);-
51 return NULL;
never executed: return ((void *)0) ;
0
52 }-
53-
54 /* direct structure assignment */-
55 *ret = *sk;-
56-
57 if (sk->num == 0) {
sk->num == 0Description
TRUEevaluated 247 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 32142 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
247-32142
58 /* postpone |ret->data| allocation */-
59 ret->data = NULL;-
60 ret->num_alloc = 0;-
61 return ret;
executed 247 times by 1 test: return ret;
Executed by:
  • libcrypto.so.1.1
247
62 }-
63 /* duplicate |sk->data| content */-
64 if ((ret->data = OPENSSL_malloc(sizeof(*ret->data) * sk->num_alloc)) == NULL)
(ret->data = C...== ((void *)0)Description
TRUEnever evaluated
FALSEevaluated 32142 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-32142
65 goto err;
never executed: goto err;
0
66 memcpy(ret->data, sk->data, sizeof(void *) * sk->num);-
67 return ret;
executed 32142 times by 1 test: return ret;
Executed by:
  • libcrypto.so.1.1
32142
68 err:-
69 OPENSSL_sk_free(ret);-
70 return NULL;
never executed: return ((void *)0) ;
0
71}-
72-
73OPENSSL_STACK *OPENSSL_sk_deep_copy(const OPENSSL_STACK *sk,-
74 OPENSSL_sk_copyfunc copy_func,-
75 OPENSSL_sk_freefunc free_func)-
76{-
77 OPENSSL_STACK *ret;-
78 int i;-
79-
80 if ((ret = OPENSSL_malloc(sizeof(*ret))) == NULL) {
(ret = CRYPTO_...== ((void *)0)Description
TRUEnever evaluated
FALSEevaluated 50 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-50
81 CRYPTOerr(CRYPTO_F_OPENSSL_SK_DEEP_COPY, ERR_R_MALLOC_FAILURE);-
82 return NULL;
never executed: return ((void *)0) ;
0
83 }-
84-
85 /* direct structure assignment */-
86 *ret = *sk;-
87-
88 if (sk->num == 0) {
sk->num == 0Description
TRUEnever evaluated
FALSEevaluated 50 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-50
89 /* postpone |ret| data allocation */-
90 ret->data = NULL;-
91 ret->num_alloc = 0;-
92 return ret;
never executed: return ret;
0
93 }-
94-
95 ret->num_alloc = sk->num > min_nodes ? sk->num : min_nodes;
sk->num > min_nodesDescription
TRUEevaluated 1 time by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 49 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
1-49
96 ret->data = OPENSSL_zalloc(sizeof(*ret->data) * ret->num_alloc);-
97 if (ret->data == NULL) {
ret->data == ((void *)0)Description
TRUEnever evaluated
FALSEevaluated 50 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-50
98 OPENSSL_free(ret);-
99 return NULL;
never executed: return ((void *)0) ;
0
100 }-
101-
102 for (i = 0; i < ret->num; ++i) {
i < ret->numDescription
TRUEevaluated 59 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 50 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
50-59
103 if (sk->data[i] == NULL)
sk->data[i] == ((void *)0)Description
TRUEnever evaluated
FALSEevaluated 59 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-59
104 continue;
never executed: continue;
0
105 if ((ret->data[i] = copy_func(sk->data[i])) == NULL) {
(ret->data[i] ...== ((void *)0)Description
TRUEnever evaluated
FALSEevaluated 59 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-59
106 while (--i >= 0)
--i >= 0Description
TRUEnever evaluated
FALSEnever evaluated
0
107 if (ret->data[i] != NULL)
ret->data[i] != ((void *)0)Description
TRUEnever evaluated
FALSEnever evaluated
0
108 free_func((void *)ret->data[i]);
never executed: free_func((void *)ret->data[i]);
0
109 OPENSSL_sk_free(ret);-
110 return NULL;
never executed: return ((void *)0) ;
0
111 }-
112 }
executed 59 times by 1 test: end of block
Executed by:
  • libcrypto.so.1.1
59
113 return ret;
executed 50 times by 1 test: return ret;
Executed by:
  • libcrypto.so.1.1
50
114}-
115-
116OPENSSL_STACK *OPENSSL_sk_new_null(void)-
117{-
118 return OPENSSL_sk_new_reserve(NULL, 0);
executed 1046102 times by 1 test: return OPENSSL_sk_new_reserve( ((void *)0) , 0);
Executed by:
  • libcrypto.so.1.1
1046102
119}-
120-
121OPENSSL_STACK *OPENSSL_sk_new(OPENSSL_sk_compfunc c)-
122{-
123 return OPENSSL_sk_new_reserve(c, 0);
executed 12314 times by 1 test: return OPENSSL_sk_new_reserve(c, 0);
Executed by:
  • libcrypto.so.1.1
12314
124}-
125-
126/*-
127 * Calculate the array growth based on the target size.-
128 *-
129 * The growth fraction is a rational number and is defined by a numerator-
130 * and a denominator. According to Andrew Koenig in his paper "Why Are-
131 * Vectors Efficient?" from JOOP 11(5) 1998, this factor should be less-
132 * than the golden ratio (1.618...).-
133 *-
134 * We use 3/2 = 1.5 for simplicity of calculation and overflow checking.-
135 * Another option 8/5 = 1.6 allows for slightly faster growth, although safe-
136 * computation is more difficult.-
137 *-
138 * The limit to avoid overflow is spot on. The modulo three correction term-
139 * ensures that the limit is the largest number than can be expanded by the-
140 * growth factor without exceeding the hard limit.-
141 *-
142 * Do not call it with |current| lower than 2, or it will infinitely loop.-
143 */-
144static ossl_inline int compute_growth(int target, int current)-
145{-
146 const int limit = (max_nodes / 3) * 2 + (max_nodes % 3 ? 1 : 0);
max_nodes % 3Description
TRUEevaluated 228580 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEnever evaluated
0-228580
147-
148 while (current < target) {
current < targetDescription
TRUEevaluated 228580 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 228580 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
228580
149 /* Check to see if we're at the hard limit */-
150 if (current >= max_nodes)
current >= max_nodesDescription
TRUEnever evaluated
FALSEevaluated 228580 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-228580
151 return 0;
never executed: return 0;
0
152-
153 /* Expand the size by a factor of 3/2 if it is within range */-
154 current = current < limit ? current + current / 2 : max_nodes;
current < limitDescription
TRUEevaluated 228580 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEnever evaluated
0-228580
155 }
executed 228580 times by 1 test: end of block
Executed by:
  • libcrypto.so.1.1
228580
156 return current;
executed 228580 times by 1 test: return current;
Executed by:
  • libcrypto.so.1.1
228580
157}-
158-
159/* internal STACK storage allocation */-
160static int sk_reserve(OPENSSL_STACK *st, int n, int exact)-
161{-
162 const void **tmpdata;-
163 int num_alloc;-
164-
165 /* Check to see the reservation isn't exceeding the hard limit */-
166 if (n > max_nodes - st->num)
n > max_nodes - st->numDescription
TRUEnever evaluated
FALSEevaluated 3135864 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-3135864
167 return 0;
never executed: return 0;
0
168-
169 /* Figure out the new size */-
170 num_alloc = st->num + n;-
171 if (num_alloc < min_nodes)
num_alloc < min_nodesDescription
TRUEevaluated 814185 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 2321679 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
814185-2321679
172 num_alloc = min_nodes;
executed 814185 times by 1 test: num_alloc = min_nodes;
Executed by:
  • libcrypto.so.1.1
814185
173-
174 /* If |st->data| allocation was postponed */-
175 if (st->data == NULL) {
st->data == ((void *)0)Description
TRUEevaluated 544576 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 2591288 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
544576-2591288
176 /*-
177 * At this point, |st->num_alloc| and |st->num| are 0;-
178 * so |num_alloc| value is |n| or |min_nodes| if greater than |n|.-
179 */-
180 if ((st->data = OPENSSL_zalloc(sizeof(void *) * num_alloc)) == NULL) {
(st->data = CR...== ((void *)0)Description
TRUEnever evaluated
FALSEevaluated 544576 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-544576
181 CRYPTOerr(CRYPTO_F_SK_RESERVE, ERR_R_MALLOC_FAILURE);-
182 return 0;
never executed: return 0;
0
183 }-
184 st->num_alloc = num_alloc;-
185 return 1;
executed 544576 times by 1 test: return 1;
Executed by:
  • libcrypto.so.1.1
544576
186 }-
187-
188 if (!exact) {
!exactDescription
TRUEevaluated 2591288 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEnever evaluated
0-2591288
189 if (num_alloc <= st->num_alloc)
num_alloc <= st->num_allocDescription
TRUEevaluated 2362708 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 228580 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
228580-2362708
190 return 1;
executed 2362708 times by 1 test: return 1;
Executed by:
  • libcrypto.so.1.1
2362708
191 num_alloc = compute_growth(num_alloc, st->num_alloc);-
192 if (num_alloc == 0)
num_alloc == 0Description
TRUEnever evaluated
FALSEevaluated 228580 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-228580
193 return 0;
never executed: return 0;
0
194 } else if (num_alloc == st->num_alloc) {
executed 228580 times by 1 test: end of block
Executed by:
  • libcrypto.so.1.1
num_alloc == st->num_allocDescription
TRUEnever evaluated
FALSEnever evaluated
0-228580
195 return 1;
never executed: return 1;
0
196 }-
197-
198 tmpdata = OPENSSL_realloc((void *)st->data, sizeof(void *) * num_alloc);-
199 if (tmpdata == NULL)
tmpdata == ((void *)0)Description
TRUEnever evaluated
FALSEevaluated 228580 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-228580
200 return 0;
never executed: return 0;
0
201-
202 st->data = tmpdata;-
203 st->num_alloc = num_alloc;-
204 return 1;
executed 228580 times by 1 test: return 1;
Executed by:
  • libcrypto.so.1.1
228580
205}-
206-
207OPENSSL_STACK *OPENSSL_sk_new_reserve(OPENSSL_sk_compfunc c, int n)-
208{-
209 OPENSSL_STACK *st = OPENSSL_zalloc(sizeof(OPENSSL_STACK));-
210-
211 if (st == NULL)
st == ((void *)0)Description
TRUEnever evaluated
FALSEevaluated 1058471 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-1058471
212 return NULL;
never executed: return ((void *)0) ;
0
213-
214 st->comp = c;-
215-
216 if (n <= 0)
n <= 0Description
TRUEevaluated 1058447 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 24 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
24-1058447
217 return st;
executed 1058447 times by 1 test: return st;
Executed by:
  • libcrypto.so.1.1
1058447
218-
219 if (!sk_reserve(st, n, 1)) {
!sk_reserve(st, n, 1)Description
TRUEnever evaluated
FALSEevaluated 24 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-24
220 OPENSSL_sk_free(st);-
221 return NULL;
never executed: return ((void *)0) ;
0
222 }-
223-
224 return st;
executed 24 times by 1 test: return st;
Executed by:
  • libcrypto.so.1.1
24
225}-
226-
227int OPENSSL_sk_reserve(OPENSSL_STACK *st, int n)-
228{-
229 if (st == NULL)
st == ((void *)0)Description
TRUEnever evaluated
FALSEevaluated 6 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-6
230 return 0;
never executed: return 0;
0
231-
232 if (n < 0)
n < 0Description
TRUEnever evaluated
FALSEevaluated 6 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-6
233 return 1;
never executed: return 1;
0
234 return sk_reserve(st, n, 1);
executed 6 times by 1 test: return sk_reserve(st, n, 1);
Executed by:
  • libcrypto.so.1.1
6
235}-
236-
237int OPENSSL_sk_insert(OPENSSL_STACK *st, const void *data, int loc)-
238{-
239 if (st == NULL || st->num == max_nodes)
st == ((void *)0)Description
TRUEnever evaluated
FALSEevaluated 3135834 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
st->num == max_nodesDescription
TRUEnever evaluated
FALSEevaluated 3135834 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-3135834
240 return 0;
never executed: return 0;
0
241-
242 if (!sk_reserve(st, 1, 0))
!sk_reserve(st, 1, 0)Description
TRUEnever evaluated
FALSEevaluated 3135834 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-3135834
243 return 0;
never executed: return 0;
0
244-
245 if ((loc >= st->num) || (loc < 0)) {
(loc >= st->num)Description
TRUEevaluated 3134474 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 1360 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
(loc < 0)Description
TRUEevaluated 4 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 1356 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
4-3134474
246 st->data[st->num] = data;-
247 } else {
executed 3134478 times by 1 test: end of block
Executed by:
  • libcrypto.so.1.1
3134478
248 memmove(&st->data[loc + 1], &st->data[loc],-
249 sizeof(st->data[0]) * (st->num - loc));-
250 st->data[loc] = data;-
251 }
executed 1356 times by 1 test: end of block
Executed by:
  • libcrypto.so.1.1
1356
252 st->num++;-
253 st->sorted = 0;-
254 return st->num;
executed 3135834 times by 1 test: return st->num;
Executed by:
  • libcrypto.so.1.1
3135834
255}-
256-
257static ossl_inline void *internal_delete(OPENSSL_STACK *st, int loc)-
258{-
259 const void *ret = st->data[loc];-
260-
261 if (loc != st->num - 1)
loc != st->num - 1Description
TRUEevaluated 15089 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 12813 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
12813-15089
262 memmove(&st->data[loc], &st->data[loc + 1],
executed 15089 times by 1 test: memmove(&st->data[loc], &st->data[loc + 1], sizeof(st->data[0]) * (st->num - loc - 1));
Executed by:
  • libcrypto.so.1.1
15089
263 sizeof(st->data[0]) * (st->num - loc - 1));
executed 15089 times by 1 test: memmove(&st->data[loc], &st->data[loc + 1], sizeof(st->data[0]) * (st->num - loc - 1));
Executed by:
  • libcrypto.so.1.1
15089
264 st->num--;-
265-
266 return (void *)ret;
executed 27902 times by 1 test: return (void *)ret;
Executed by:
  • libcrypto.so.1.1
27902
267}-
268-
269void *OPENSSL_sk_delete_ptr(OPENSSL_STACK *st, const void *p)-
270{-
271 int i;-
272-
273 for (i = 0; i < st->num; i++)
i < st->numDescription
TRUEevaluated 67776 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 2936 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
2936-67776
274 if (st->data[i] == p)
st->data[i] == pDescription
TRUEevaluated 13274 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 54502 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
13274-54502
275 return internal_delete(st, i);
executed 13274 times by 1 test: return internal_delete(st, i);
Executed by:
  • libcrypto.so.1.1
13274
276 return NULL;
executed 2936 times by 1 test: return ((void *)0) ;
Executed by:
  • libcrypto.so.1.1
2936
277}-
278-
279void *OPENSSL_sk_delete(OPENSSL_STACK *st, int loc)-
280{-
281 if (st == NULL || loc < 0 || loc >= st->num)
st == ((void *)0)Description
TRUEnever evaluated
FALSEevaluated 11389 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
loc < 0Description
TRUEnever evaluated
FALSEevaluated 11389 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
loc >= st->numDescription
TRUEevaluated 4 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 11385 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-11389
282 return NULL;
executed 4 times by 1 test: return ((void *)0) ;
Executed by:
  • libcrypto.so.1.1
4
283-
284 return internal_delete(st, loc);
executed 11385 times by 1 test: return internal_delete(st, loc);
Executed by:
  • libcrypto.so.1.1
11385
285}-
286-
287static int internal_find(OPENSSL_STACK *st, const void *data,-
288 int ret_val_options)-
289{-
290 const void *r;-
291 int i;-
292-
293 if (st == NULL || st->num == 0)
st == ((void *)0)Description
TRUEnever evaluated
FALSEevaluated 19488 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
st->num == 0Description
TRUEevaluated 9790 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 9698 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-19488
294 return -1;
executed 9790 times by 1 test: return -1;
Executed by:
  • libcrypto.so.1.1
9790
295-
296 if (st->comp == NULL) {
st->comp == ((void *)0)Description
TRUEevaluated 4255 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 5443 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
4255-5443
297 for (i = 0; i < st->num; i++)
i < st->numDescription
TRUEevaluated 52586 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 1580 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
1580-52586
298 if (st->data[i] == data)
st->data[i] == dataDescription
TRUEevaluated 2675 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 49911 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
2675-49911
299 return i;
executed 2675 times by 1 test: return i;
Executed by:
  • libcrypto.so.1.1
2675
300 return -1;
executed 1580 times by 1 test: return -1;
Executed by:
  • libcrypto.so.1.1
1580
301 }-
302-
303 if (!st->sorted) {
!st->sortedDescription
TRUEevaluated 1086 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 4357 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
1086-4357
304 if (st->num > 1)
st->num > 1Description
TRUEevaluated 50 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 1036 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
50-1036
305 qsort(st->data, st->num, sizeof(void *), st->comp);
executed 50 times by 1 test: qsort(st->data, st->num, sizeof(void *), st->comp);
Executed by:
  • libcrypto.so.1.1
50
306 st->sorted = 1; /* empty or single-element stack is considered sorted */-
307 }
executed 1086 times by 1 test: end of block
Executed by:
  • libcrypto.so.1.1
1086
308 if (data == NULL)
data == ((void *)0)Description
TRUEnever evaluated
FALSEevaluated 5443 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-5443
309 return -1;
never executed: return -1;
0
310 r = OBJ_bsearch_ex_(&data, st->data, st->num, sizeof(void *), st->comp,-
311 ret_val_options);-
312-
313 return r == NULL ? -1 : (int)((const void **)r - st->data);
executed 5443 times by 1 test: return r == ((void *)0) ? -1 : (int)((const void **)r - st->data);
Executed by:
  • libcrypto.so.1.1
r == ((void *)0)Description
TRUEevaluated 101 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 5342 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
101-5443
314}-
315-
316int OPENSSL_sk_find(OPENSSL_STACK *st, const void *data)-
317{-
318 return internal_find(st, data, OBJ_BSEARCH_FIRST_VALUE_ON_MATCH);
executed 19424 times by 1 test: return internal_find(st, data, 0x02);
Executed by:
  • libcrypto.so.1.1
19424
319}-
320-
321int OPENSSL_sk_find_ex(OPENSSL_STACK *st, const void *data)-
322{-
323 return internal_find(st, data, OBJ_BSEARCH_VALUE_ON_NOMATCH);
executed 64 times by 1 test: return internal_find(st, data, 0x01);
Executed by:
  • libcrypto.so.1.1
64
324}-
325-
326int OPENSSL_sk_push(OPENSSL_STACK *st, const void *data)-
327{-
328 if (st == NULL)
st == ((void *)0)Description
TRUEnever evaluated
FALSEevaluated 3115079 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-3115079
329 return -1;
never executed: return -1;
0
330 return OPENSSL_sk_insert(st, data, st->num);
executed 3115079 times by 1 test: return OPENSSL_sk_insert(st, data, st->num);
Executed by:
  • libcrypto.so.1.1
3115079
331}-
332-
333int OPENSSL_sk_unshift(OPENSSL_STACK *st, const void *data)-
334{-
335 return OPENSSL_sk_insert(st, data, 0);
executed 24 times by 1 test: return OPENSSL_sk_insert(st, data, 0);
Executed by:
  • libcrypto.so.1.1
24
336}-
337-
338void *OPENSSL_sk_shift(OPENSSL_STACK *st)-
339{-
340 if (st == NULL || st->num == 0)
st == ((void *)0)Description
TRUEnever evaluated
FALSEevaluated 1704 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
st->num == 0Description
TRUEevaluated 27 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 1677 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-1704
341 return NULL;
executed 27 times by 1 test: return ((void *)0) ;
Executed by:
  • libcrypto.so.1.1
27
342 return internal_delete(st, 0);
executed 1677 times by 1 test: return internal_delete(st, 0);
Executed by:
  • libcrypto.so.1.1
1677
343}-
344-
345void *OPENSSL_sk_pop(OPENSSL_STACK *st)-
346{-
347 if (st == NULL || st->num == 0)
st == ((void *)0)Description
TRUEevaluated 1931 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 1583 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
st->num == 0Description
TRUEevaluated 17 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 1566 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
17-1931
348 return NULL;
executed 1948 times by 1 test: return ((void *)0) ;
Executed by:
  • libcrypto.so.1.1
1948
349 return internal_delete(st, st->num - 1);
executed 1566 times by 1 test: return internal_delete(st, st->num - 1);
Executed by:
  • libcrypto.so.1.1
1566
350}-
351-
352void OPENSSL_sk_zero(OPENSSL_STACK *st)-
353{-
354 if (st == NULL || st->num == 0)
st == ((void *)0)Description
TRUEnever evaluated
FALSEevaluated 4 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
st->num == 0Description
TRUEnever evaluated
FALSEevaluated 4 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-4
355 return;
never executed: return;
0
356 memset(st->data, 0, sizeof(*st->data) * st->num);-
357 st->num = 0;-
358}
executed 4 times by 1 test: end of block
Executed by:
  • libcrypto.so.1.1
4
359-
360void OPENSSL_sk_pop_free(OPENSSL_STACK *st, OPENSSL_sk_freefunc func)-
361{-
362 int i;-
363-
364 if (st == NULL)
st == ((void *)0)Description
TRUEevaluated 619635 times by 12 tests
Evaluated by:
  • asn1_internal_test
  • chacha_internal_test
  • ctype_internal_test
  • curve448_internal_test
  • libcrypto.so.1.1
  • modes_internal_test
  • poly1305_internal_test
  • rdrand_sanitytest
  • siphash_internal_test
  • sm2_internal_test
  • sm4_internal_test
  • x509_internal_test
FALSEevaluated 613487 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
613487-619635
365 return;
executed 619635 times by 12 tests: return;
Executed by:
  • asn1_internal_test
  • chacha_internal_test
  • ctype_internal_test
  • curve448_internal_test
  • libcrypto.so.1.1
  • modes_internal_test
  • poly1305_internal_test
  • rdrand_sanitytest
  • siphash_internal_test
  • sm2_internal_test
  • sm4_internal_test
  • x509_internal_test
619635
366 for (i = 0; i < st->num; i++)
i < st->numDescription
TRUEevaluated 534853 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 613487 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
534853-613487
367 if (st->data[i] != NULL)
st->data[i] != ((void *)0)Description
TRUEevaluated 529772 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 5081 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
5081-529772
368 func((char *)st->data[i]);
executed 529772 times by 1 test: func((char *)st->data[i]);
Executed by:
  • libcrypto.so.1.1
529772
369 OPENSSL_sk_free(st);-
370}
executed 613487 times by 1 test: end of block
Executed by:
  • libcrypto.so.1.1
613487
371-
372void OPENSSL_sk_free(OPENSSL_STACK *st)-
373{-
374 if (st == NULL)
st == ((void *)0)Description
TRUEevaluated 890422 times by 12 tests
Evaluated by:
  • asn1_internal_test
  • chacha_internal_test
  • ctype_internal_test
  • curve448_internal_test
  • libcrypto.so.1.1
  • modes_internal_test
  • poly1305_internal_test
  • rdrand_sanitytest
  • siphash_internal_test
  • sm2_internal_test
  • sm4_internal_test
  • x509_internal_test
FALSEevaluated 1090910 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
890422-1090910
375 return;
executed 890422 times by 12 tests: return;
Executed by:
  • asn1_internal_test
  • chacha_internal_test
  • ctype_internal_test
  • curve448_internal_test
  • libcrypto.so.1.1
  • modes_internal_test
  • poly1305_internal_test
  • rdrand_sanitytest
  • siphash_internal_test
  • sm2_internal_test
  • sm4_internal_test
  • x509_internal_test
890422
376 OPENSSL_free(st->data);-
377 OPENSSL_free(st);-
378}
executed 1090910 times by 1 test: end of block
Executed by:
  • libcrypto.so.1.1
1090910
379-
380int OPENSSL_sk_num(const OPENSSL_STACK *st)-
381{-
382 return st == NULL ? -1 : st->num;
executed 9183832 times by 12 tests: return st == ((void *)0) ? -1 : st->num;
Executed by:
  • asn1_internal_test
  • chacha_internal_test
  • ctype_internal_test
  • curve448_internal_test
  • libcrypto.so.1.1
  • modes_internal_test
  • poly1305_internal_test
  • rdrand_sanitytest
  • siphash_internal_test
  • sm2_internal_test
  • sm4_internal_test
  • x509_internal_test
st == ((void *)0)Description
TRUEevaluated 1292008 times by 12 tests
Evaluated by:
  • asn1_internal_test
  • chacha_internal_test
  • ctype_internal_test
  • curve448_internal_test
  • libcrypto.so.1.1
  • modes_internal_test
  • poly1305_internal_test
  • rdrand_sanitytest
  • siphash_internal_test
  • sm2_internal_test
  • sm4_internal_test
  • x509_internal_test
FALSEevaluated 7891824 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
1292008-9183832
383}-
384-
385void *OPENSSL_sk_value(const OPENSSL_STACK *st, int i)-
386{-
387 if (st == NULL || i < 0 || i >= st->num)
st == ((void *)0)Description
TRUEnever evaluated
FALSEevaluated 7047030 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
i < 0Description
TRUEevaluated 3081 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 7043949 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
i >= st->numDescription
TRUEevaluated 2386 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 7041563 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-7047030
388 return NULL;
executed 5467 times by 1 test: return ((void *)0) ;
Executed by:
  • libcrypto.so.1.1
5467
389 return (void *)st->data[i];
executed 7041563 times by 1 test: return (void *)st->data[i];
Executed by:
  • libcrypto.so.1.1
7041563
390}-
391-
392void *OPENSSL_sk_set(OPENSSL_STACK *st, int i, const void *data)-
393{-
394 if (st == NULL || i < 0 || i >= st->num)
st == ((void *)0)Description
TRUEnever evaluated
FALSEevaluated 108271 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
i < 0Description
TRUEnever evaluated
FALSEevaluated 108271 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
i >= st->numDescription
TRUEnever evaluated
FALSEevaluated 108271 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-108271
395 return NULL;
never executed: return ((void *)0) ;
0
396 st->data[i] = data;-
397 st->sorted = 0;-
398 return (void *)st->data[i];
executed 108271 times by 1 test: return (void *)st->data[i];
Executed by:
  • libcrypto.so.1.1
108271
399}-
400-
401void OPENSSL_sk_sort(OPENSSL_STACK *st)-
402{-
403 if (st != NULL && !st->sorted && st->comp != NULL) {
st != ((void *)0)Description
TRUEevaluated 15736 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEnever evaluated
!st->sortedDescription
TRUEevaluated 15736 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEnever evaluated
st->comp != ((void *)0)Description
TRUEevaluated 15736 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEnever evaluated
0-15736
404 if (st->num > 1)
st->num > 1Description
TRUEevaluated 15419 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 317 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
317-15419
405 qsort(st->data, st->num, sizeof(void *), st->comp);
executed 15419 times by 1 test: qsort(st->data, st->num, sizeof(void *), st->comp);
Executed by:
  • libcrypto.so.1.1
15419
406 st->sorted = 1; /* empty or single-element stack is considered sorted */-
407 }
executed 15736 times by 1 test: end of block
Executed by:
  • libcrypto.so.1.1
15736
408}
executed 15736 times by 1 test: end of block
Executed by:
  • libcrypto.so.1.1
15736
409-
410int OPENSSL_sk_is_sorted(const OPENSSL_STACK *st)-
411{-
412 return st == NULL ? 1 : st->sorted;
executed 9 times by 1 test: return st == ((void *)0) ? 1 : st->sorted;
Executed by:
  • libcrypto.so.1.1
st == ((void *)0)Description
TRUEnever evaluated
FALSEevaluated 9 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-9
413}-
Source codeSwitch to Preprocessed file

Generated by Squish Coco 4.2.2