OpenCoverage

pqueue.c

Absolute File Name:/home/opencoverage/opencoverage/guest-scripts/openssl/src/ssl/pqueue.c
Source codeSwitch to Preprocessed file
LineSourceCount
1/*-
2 * Copyright 2005-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 "ssl_locl.h"-
11#include <openssl/bn.h>-
12-
13struct pqueue_st {-
14 pitem *items;-
15 int count;-
16};-
17-
18pitem *pitem_new(unsigned char *prio64be, void *data)-
19{-
20 pitem *item = OPENSSL_malloc(sizeof(*item));-
21-
22 if (item == NULL) {
item == ((void *)0)Description
TRUEnever evaluated
FALSEevaluated 2250 times by 1 test
Evaluated by:
  • libssl.so.1.1
0-2250
23 SSLerr(SSL_F_PITEM_NEW, ERR_R_MALLOC_FAILURE);-
24 return NULL;
never executed: return ((void *)0) ;
0
25 }-
26-
27 memcpy(item->priority, prio64be, sizeof(item->priority));-
28 item->data = data;-
29 item->next = NULL;-
30 return item;
executed 2250 times by 1 test: return item;
Executed by:
  • libssl.so.1.1
2250
31}-
32-
33void pitem_free(pitem *item)-
34{-
35 OPENSSL_free(item);-
36}
executed 2250 times by 1 test: end of block
Executed by:
  • libssl.so.1.1
2250
37-
38pqueue *pqueue_new(void)-
39{-
40 pqueue *pq = OPENSSL_zalloc(sizeof(*pq));-
41-
42 if (pq == NULL)
pq == ((void *)0)Description
TRUEnever evaluated
FALSEevaluated 1865 times by 1 test
Evaluated by:
  • libssl.so.1.1
0-1865
43 SSLerr(SSL_F_PQUEUE_NEW, ERR_R_MALLOC_FAILURE);
never executed: ERR_put_error(20,(625),((1|64)),__FILE__,43);
0
44-
45 return pq;
executed 1865 times by 1 test: return pq;
Executed by:
  • libssl.so.1.1
1865
46}-
47-
48void pqueue_free(pqueue *pq)-
49{-
50 OPENSSL_free(pq);-
51}
executed 1865 times by 1 test: end of block
Executed by:
  • libssl.so.1.1
1865
52-
53pitem *pqueue_insert(pqueue *pq, pitem *item)-
54{-
55 pitem *curr, *next;-
56-
57 if (pq->items == NULL) {
pq->items == ((void *)0)Description
TRUEevaluated 1068 times by 1 test
Evaluated by:
  • libssl.so.1.1
FALSEevaluated 1182 times by 1 test
Evaluated by:
  • libssl.so.1.1
1068-1182
58 pq->items = item;-
59 return item;
executed 1068 times by 1 test: return item;
Executed by:
  • libssl.so.1.1
1068
60 }-
61-
62 for (curr = NULL, next = pq->items;-
63 next != NULL; curr = next, next = next->next) {
next != ((void *)0)Description
TRUEevaluated 2020 times by 1 test
Evaluated by:
  • libssl.so.1.1
FALSEevaluated 1182 times by 1 test
Evaluated by:
  • libssl.so.1.1
1182-2020
64 /*-
65 * we can compare 64-bit value in big-endian encoding with memcmp:-)-
66 */-
67 int cmp = memcmp(next->priority, item->priority, 8);-
68 if (cmp > 0) { /* next > item */
cmp > 0Description
TRUEnever evaluated
FALSEevaluated 2020 times by 1 test
Evaluated by:
  • libssl.so.1.1
0-2020
69 item->next = next;-
70-
71 if (curr == NULL)
curr == ((void *)0)Description
TRUEnever evaluated
FALSEnever evaluated
0
72 pq->items = item;
never executed: pq->items = item;
0
73 else-
74 curr->next = item;
never executed: curr->next = item;
0
75-
76 return item;
never executed: return item;
0
77 }-
78-
79 else if (cmp == 0) /* duplicates not allowed */
cmp == 0Description
TRUEnever evaluated
FALSEevaluated 2020 times by 1 test
Evaluated by:
  • libssl.so.1.1
0-2020
80 return NULL;
never executed: return ((void *)0) ;
0
81 }
executed 2020 times by 1 test: end of block
Executed by:
  • libssl.so.1.1
2020
82-
83 item->next = NULL;-
84 curr->next = item;-
85-
86 return item;
executed 1182 times by 1 test: return item;
Executed by:
  • libssl.so.1.1
1182
87}-
88-
89pitem *pqueue_peek(pqueue *pq)-
90{-
91 return pq->items;
executed 9007 times by 1 test: return pq->items;
Executed by:
  • libssl.so.1.1
9007
92}-
93-
94pitem *pqueue_pop(pqueue *pq)-
95{-
96 pitem *item = pq->items;-
97-
98 if (pq->items != NULL)
pq->items != ((void *)0)Description
TRUEevaluated 2250 times by 1 test
Evaluated by:
  • libssl.so.1.1
FALSEevaluated 17772 times by 1 test
Evaluated by:
  • libssl.so.1.1
2250-17772
99 pq->items = pq->items->next;
executed 2250 times by 1 test: pq->items = pq->items->next;
Executed by:
  • libssl.so.1.1
2250
100-
101 return item;
executed 20022 times by 1 test: return item;
Executed by:
  • libssl.so.1.1
20022
102}-
103-
104pitem *pqueue_find(pqueue *pq, unsigned char *prio64be)-
105{-
106 pitem *next;-
107 pitem *found = NULL;-
108-
109 if (pq->items == NULL)
pq->items == ((void *)0)Description
TRUEevaluated 417 times by 1 test
Evaluated by:
  • libssl.so.1.1
FALSEevaluated 1122 times by 1 test
Evaluated by:
  • libssl.so.1.1
417-1122
110 return NULL;
executed 417 times by 1 test: return ((void *)0) ;
Executed by:
  • libssl.so.1.1
417
111-
112 for (next = pq->items; next->next != NULL; next = next->next) {
next->next != ((void *)0)Description
TRUEevaluated 277 times by 1 test
Evaluated by:
  • libssl.so.1.1
FALSEevaluated 1029 times by 1 test
Evaluated by:
  • libssl.so.1.1
277-1029
113 if (memcmp(next->priority, prio64be, 8) == 0) {
memcmp(next->p...o64be, 8) == 0Description
TRUEevaluated 93 times by 1 test
Evaluated by:
  • libssl.so.1.1
FALSEevaluated 184 times by 1 test
Evaluated by:
  • libssl.so.1.1
93-184
114 found = next;-
115 break;
executed 93 times by 1 test: break;
Executed by:
  • libssl.so.1.1
93
116 }-
117 }
executed 184 times by 1 test: end of block
Executed by:
  • libssl.so.1.1
184
118-
119 /* check the one last node */-
120 if (memcmp(next->priority, prio64be, 8) == 0)
memcmp(next->p...o64be, 8) == 0Description
TRUEevaluated 1078 times by 1 test
Evaluated by:
  • libssl.so.1.1
FALSEevaluated 44 times by 1 test
Evaluated by:
  • libssl.so.1.1
44-1078
121 found = next;
executed 1078 times by 1 test: found = next;
Executed by:
  • libssl.so.1.1
1078
122-
123 if (!found)
!foundDescription
TRUEevaluated 44 times by 1 test
Evaluated by:
  • libssl.so.1.1
FALSEevaluated 1078 times by 1 test
Evaluated by:
  • libssl.so.1.1
44-1078
124 return NULL;
executed 44 times by 1 test: return ((void *)0) ;
Executed by:
  • libssl.so.1.1
44
125-
126 return found;
executed 1078 times by 1 test: return found;
Executed by:
  • libssl.so.1.1
1078
127}-
128-
129pitem *pqueue_iterator(pqueue *pq)-
130{-
131 return pqueue_peek(pq);
executed 51 times by 1 test: return pqueue_peek(pq);
Executed by:
  • libssl.so.1.1
51
132}-
133-
134pitem *pqueue_next(piterator *item)-
135{-
136 pitem *ret;-
137-
138 if (item == NULL || *item == NULL)
item == ((void *)0)Description
TRUEnever evaluated
FALSEevaluated 173 times by 1 test
Evaluated by:
  • libssl.so.1.1
*item == ((void *)0)Description
TRUEevaluated 51 times by 1 test
Evaluated by:
  • libssl.so.1.1
FALSEevaluated 122 times by 1 test
Evaluated by:
  • libssl.so.1.1
0-173
139 return NULL;
executed 51 times by 1 test: return ((void *)0) ;
Executed by:
  • libssl.so.1.1
51
140-
141 /* *item != NULL */-
142 ret = *item;-
143 *item = (*item)->next;-
144-
145 return ret;
executed 122 times by 1 test: return ret;
Executed by:
  • libssl.so.1.1
122
146}-
147-
148size_t pqueue_size(pqueue *pq)-
149{-
150 pitem *item = pq->items;-
151 size_t count = 0;-
152-
153 while (item != NULL) {
item != ((void *)0)Description
TRUEnever evaluated
FALSEevaluated 16 times by 1 test
Evaluated by:
  • libssl.so.1.1
0-16
154 count++;-
155 item = item->next;-
156 }
never executed: end of block
0
157 return count;
executed 16 times by 1 test: return count;
Executed by:
  • libssl.so.1.1
16
158}-
Source codeSwitch to Preprocessed file

Generated by Squish Coco 4.2.2