Coverage Report

Created: 2025-11-16 06:40

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/openssl32/ssl/pqueue.c
Line
Count
Source
1
/*
2
 * Copyright 2005-2020 The OpenSSL Project Authors. All Rights Reserved.
3
 *
4
 * Licensed under the Apache License 2.0 (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_local.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
100k
{
20
100k
    pitem *item = OPENSSL_malloc(sizeof(*item));
21
22
100k
    if (item == NULL)
23
0
        return NULL;
24
25
100k
    memcpy(item->priority, prio64be, sizeof(item->priority));
26
100k
    item->data = data;
27
100k
    item->next = NULL;
28
100k
    return item;
29
100k
}
30
31
void pitem_free(pitem *item)
32
100k
{
33
100k
    OPENSSL_free(item);
34
100k
}
35
36
pqueue *pqueue_new(void)
37
538k
{
38
538k
    pqueue *pq = OPENSSL_zalloc(sizeof(*pq));
39
40
538k
    return pq;
41
538k
}
42
43
void pqueue_free(pqueue *pq)
44
538k
{
45
538k
    OPENSSL_free(pq);
46
538k
}
47
48
pitem *pqueue_insert(pqueue *pq, pitem *item)
49
100k
{
50
100k
    pitem *curr, *next;
51
52
100k
    if (pq->items == NULL) {
53
46.3k
        pq->items = item;
54
46.3k
        return item;
55
46.3k
    }
56
57
53.9k
    for (curr = NULL, next = pq->items;
58
173k
         next != NULL; curr = next, next = next->next) {
59
        /*
60
         * we can compare 64-bit value in big-endian encoding with memcmp:-)
61
         */
62
141k
        int cmp = memcmp(next->priority, item->priority, 8);
63
141k
        if (cmp > 0) {          /* next > item */
64
6.43k
            item->next = next;
65
66
6.43k
            if (curr == NULL)
67
3.07k
                pq->items = item;
68
3.36k
            else
69
3.36k
                curr->next = item;
70
71
6.43k
            return item;
72
6.43k
        }
73
74
135k
        else if (cmp == 0)      /* duplicates not allowed */
75
15.9k
            return NULL;
76
141k
    }
77
78
31.6k
    item->next = NULL;
79
31.6k
    curr->next = item;
80
81
31.6k
    return item;
82
53.9k
}
83
84
pitem *pqueue_peek(pqueue *pq)
85
255k
{
86
255k
    return pq->items;
87
255k
}
88
89
pitem *pqueue_pop(pqueue *pq)
90
18.7M
{
91
18.7M
    pitem *item = pq->items;
92
93
18.7M
    if (pq->items != NULL)
94
84.3k
        pq->items = pq->items->next;
95
96
18.7M
    return item;
97
18.7M
}
98
99
pitem *pqueue_find(pqueue *pq, unsigned char *prio64be)
100
73.2k
{
101
73.2k
    pitem *next;
102
73.2k
    pitem *found = NULL;
103
104
73.2k
    if (pq->items == NULL)
105
28.6k
        return NULL;
106
107
89.6k
    for (next = pq->items; next->next != NULL; next = next->next) {
108
49.7k
        if (memcmp(next->priority, prio64be, 8) == 0) {
109
4.65k
            found = next;
110
4.65k
            break;
111
4.65k
        }
112
49.7k
    }
113
114
    /* check the one last node */
115
44.5k
    if (memcmp(next->priority, prio64be, 8) == 0)
116
29.6k
        found = next;
117
118
44.5k
    if (!found)
119
14.8k
        return NULL;
120
121
29.6k
    return found;
122
44.5k
}
123
124
pitem *pqueue_iterator(pqueue *pq)
125
148k
{
126
148k
    return pqueue_peek(pq);
127
148k
}
128
129
pitem *pqueue_next(piterator *item)
130
150k
{
131
150k
    pitem *ret;
132
133
150k
    if (item == NULL || *item == NULL)
134
92.1k
        return NULL;
135
136
    /* *item != NULL */
137
58.7k
    ret = *item;
138
58.7k
    *item = (*item)->next;
139
140
58.7k
    return ret;
141
150k
}
142
143
size_t pqueue_size(pqueue *pq)
144
21.7k
{
145
21.7k
    pitem *item = pq->items;
146
21.7k
    size_t count = 0;
147
148
226k
    while (item != NULL) {
149
204k
        count++;
150
204k
        item = item->next;
151
204k
    }
152
21.7k
    return count;
153
21.7k
}