Absolute File Name: | /home/opencoverage/opencoverage/guest-scripts/openssl/src/ssl/pqueue.c |
Source code | Switch to Preprocessed file |
Line | Source | Count | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
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 | - | |||||||||||||
13 | struct pqueue_st { | - | ||||||||||||
14 | pitem *items; | - | ||||||||||||
15 | int count; | - | ||||||||||||
16 | }; | - | ||||||||||||
17 | - | |||||||||||||
18 | pitem *pitem_new(unsigned char *prio64be, void *data) | - | ||||||||||||
19 | { | - | ||||||||||||
20 | pitem *item = OPENSSL_malloc(sizeof(*item)); | - | ||||||||||||
21 | - | |||||||||||||
22 | if (item == NULL) {
| 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:
| 2250 | ||||||||||||
31 | } | - | ||||||||||||
32 | - | |||||||||||||
33 | void pitem_free(pitem *item) | - | ||||||||||||
34 | { | - | ||||||||||||
35 | OPENSSL_free(item); | - | ||||||||||||
36 | } executed 2250 times by 1 test: end of block Executed by:
| 2250 | ||||||||||||
37 | - | |||||||||||||
38 | pqueue *pqueue_new(void) | - | ||||||||||||
39 | { | - | ||||||||||||
40 | pqueue *pq = OPENSSL_zalloc(sizeof(*pq)); | - | ||||||||||||
41 | - | |||||||||||||
42 | if (pq == NULL)
| 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:
| 1865 | ||||||||||||
46 | } | - | ||||||||||||
47 | - | |||||||||||||
48 | void pqueue_free(pqueue *pq) | - | ||||||||||||
49 | { | - | ||||||||||||
50 | OPENSSL_free(pq); | - | ||||||||||||
51 | } executed 1865 times by 1 test: end of block Executed by:
| 1865 | ||||||||||||
52 | - | |||||||||||||
53 | pitem *pqueue_insert(pqueue *pq, pitem *item) | - | ||||||||||||
54 | { | - | ||||||||||||
55 | pitem *curr, *next; | - | ||||||||||||
56 | - | |||||||||||||
57 | if (pq->items == NULL) {
| 1068-1182 | ||||||||||||
58 | pq->items = item; | - | ||||||||||||
59 | return item; executed 1068 times by 1 test: return item; Executed by:
| 1068 | ||||||||||||
60 | } | - | ||||||||||||
61 | - | |||||||||||||
62 | for (curr = NULL, next = pq->items; | - | ||||||||||||
63 | next != NULL; curr = next, next = next->next) {
| 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 */
| 0-2020 | ||||||||||||
69 | item->next = next; | - | ||||||||||||
70 | - | |||||||||||||
71 | if (curr == NULL)
| 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 */
| 0-2020 | ||||||||||||
80 | return NULL; never executed: return ((void *)0) ; | 0 | ||||||||||||
81 | } executed 2020 times by 1 test: end of block Executed by:
| 2020 | ||||||||||||
82 | - | |||||||||||||
83 | item->next = NULL; | - | ||||||||||||
84 | curr->next = item; | - | ||||||||||||
85 | - | |||||||||||||
86 | return item; executed 1182 times by 1 test: return item; Executed by:
| 1182 | ||||||||||||
87 | } | - | ||||||||||||
88 | - | |||||||||||||
89 | pitem *pqueue_peek(pqueue *pq) | - | ||||||||||||
90 | { | - | ||||||||||||
91 | return pq->items; executed 9007 times by 1 test: return pq->items; Executed by:
| 9007 | ||||||||||||
92 | } | - | ||||||||||||
93 | - | |||||||||||||
94 | pitem *pqueue_pop(pqueue *pq) | - | ||||||||||||
95 | { | - | ||||||||||||
96 | pitem *item = pq->items; | - | ||||||||||||
97 | - | |||||||||||||
98 | if (pq->items != NULL)
| 2250-17772 | ||||||||||||
99 | pq->items = pq->items->next; executed 2250 times by 1 test: pq->items = pq->items->next; Executed by:
| 2250 | ||||||||||||
100 | - | |||||||||||||
101 | return item; executed 20022 times by 1 test: return item; Executed by:
| 20022 | ||||||||||||
102 | } | - | ||||||||||||
103 | - | |||||||||||||
104 | pitem *pqueue_find(pqueue *pq, unsigned char *prio64be) | - | ||||||||||||
105 | { | - | ||||||||||||
106 | pitem *next; | - | ||||||||||||
107 | pitem *found = NULL; | - | ||||||||||||
108 | - | |||||||||||||
109 | if (pq->items == NULL)
| 417-1122 | ||||||||||||
110 | return NULL; executed 417 times by 1 test: return ((void *)0) ; Executed by:
| 417 | ||||||||||||
111 | - | |||||||||||||
112 | for (next = pq->items; next->next != NULL; next = next->next) {
| 277-1029 | ||||||||||||
113 | if (memcmp(next->priority, prio64be, 8) == 0) {
| 93-184 | ||||||||||||
114 | found = next; | - | ||||||||||||
115 | break; executed 93 times by 1 test: break; Executed by:
| 93 | ||||||||||||
116 | } | - | ||||||||||||
117 | } executed 184 times by 1 test: end of block Executed by:
| 184 | ||||||||||||
118 | - | |||||||||||||
119 | /* check the one last node */ | - | ||||||||||||
120 | if (memcmp(next->priority, prio64be, 8) == 0)
| 44-1078 | ||||||||||||
121 | found = next; executed 1078 times by 1 test: found = next; Executed by:
| 1078 | ||||||||||||
122 | - | |||||||||||||
123 | if (!found)
| 44-1078 | ||||||||||||
124 | return NULL; executed 44 times by 1 test: return ((void *)0) ; Executed by:
| 44 | ||||||||||||
125 | - | |||||||||||||
126 | return found; executed 1078 times by 1 test: return found; Executed by:
| 1078 | ||||||||||||
127 | } | - | ||||||||||||
128 | - | |||||||||||||
129 | pitem *pqueue_iterator(pqueue *pq) | - | ||||||||||||
130 | { | - | ||||||||||||
131 | return pqueue_peek(pq); executed 51 times by 1 test: return pqueue_peek(pq); Executed by:
| 51 | ||||||||||||
132 | } | - | ||||||||||||
133 | - | |||||||||||||
134 | pitem *pqueue_next(piterator *item) | - | ||||||||||||
135 | { | - | ||||||||||||
136 | pitem *ret; | - | ||||||||||||
137 | - | |||||||||||||
138 | if (item == NULL || *item == NULL)
| 0-173 | ||||||||||||
139 | return NULL; executed 51 times by 1 test: return ((void *)0) ; Executed by:
| 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:
| 122 | ||||||||||||
146 | } | - | ||||||||||||
147 | - | |||||||||||||
148 | size_t pqueue_size(pqueue *pq) | - | ||||||||||||
149 | { | - | ||||||||||||
150 | pitem *item = pq->items; | - | ||||||||||||
151 | size_t count = 0; | - | ||||||||||||
152 | - | |||||||||||||
153 | while (item != NULL) {
| 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:
| 16 | ||||||||||||
158 | } | - | ||||||||||||
Source code | Switch to Preprocessed file |