1 | |
2 | |
3 | |
4 | |
5 | |
6 | |
7 | |
8 | |
9 | #ifndef _GNU_SOURCE |
10 | #define _GNU_SOURCE |
11 | #endif |
12 | |
13 | #include <stdio.h> |
14 | #include <stdlib.h> |
15 | #include <string.h> |
16 | #include <fnmatch.h> |
17 | |
18 | #include "pool.h" |
19 | #include "poolid.h" |
20 | #include "poolvendor.h" |
21 | #include "util.h" |
22 | |
23 | |
24 | |
25 | |
26 | |
27 | |
28 | |
29 | |
30 | |
31 | |
32 | |
33 | |
34 | |
35 | |
36 | |
37 | |
38 | |
39 | |
40 | |
41 | Id pool_vendor2mask(Pool *pool, Id vendor) |
42 | { |
43 | const char *vstr; |
44 | int i; |
45 | Id mask, m; |
46 | const char **v, *vs; |
47 | |
48 | if (vendor == 0 || !pool->vendorclasses) |
| 1 | Assuming 'vendor' is not equal to 0 | |
|
| 2 | | Assuming the condition is false | |
|
| |
49 | return 0; |
50 | for (i = 0; i < pool->vendormap.count; i += 2) |
| 4 | | Assuming the condition is false | |
|
| 5 | | Loop condition is false. Execution continues on line 53 | |
|
51 | if (pool->vendormap.elements[i] == vendor) |
52 | return pool->vendormap.elements[i + 1]; |
53 | vstr = pool_id2str(pool, vendor); |
54 | m = 1; |
55 | mask = 0; |
56 | for (v = pool->vendorclasses; ; v++) |
| 6 | | Loop condition is true. Entering loop body | |
|
57 | { |
58 | vs = *v; |
| |
59 | if (vs == 0) |
| 8 | | Assuming 'vs' is equal to null | |
|
| |
60 | { |
61 | v++; |
62 | if (*v == 0) |
| 10 | | Assuming the condition is false | |
|
| |
63 | break; |
64 | if (m == (1 << 31)) |
| |
65 | break; |
66 | m <<= 1; |
67 | } |
68 | if (fnmatch(*vs == '!' ? vs + 1 : vs, vstr, FNM_CASEFOLD(1 << 4)) == 0) |
| 13 | | Dereference of null pointer (loaded from variable 'vs') |
|
69 | { |
70 | if (*vs != '!') |
71 | mask |= m; |
72 | while (v[1]) |
73 | v++; |
74 | } |
75 | } |
76 | queue_push(&pool->vendormap, vendor); |
77 | queue_push(&pool->vendormap, mask); |
78 | return mask; |
79 | } |
80 | |
81 | void |
82 | pool_setvendorclasses(Pool *pool, const char **vendorclasses) |
83 | { |
84 | int i; |
85 | const char **v; |
86 | |
87 | if (pool->vendorclasses) |
88 | { |
89 | for (v = pool->vendorclasses; v[0] || v[1]; v++) |
90 | solv_free((void *)*v); |
91 | pool->vendorclasses = solv_free((void *)pool->vendorclasses); |
92 | } |
93 | if (!vendorclasses || !vendorclasses[0]) |
94 | return; |
95 | for (v = vendorclasses; v[0] || v[1]; v++) |
96 | ; |
97 | pool->vendorclasses = solv_calloc(v - vendorclasses + 2, sizeof(const char *)); |
98 | for (v = vendorclasses, i = 0; v[0] || v[1]; v++, i++) |
99 | pool->vendorclasses[i] = *v ? solv_strdup(*v) : 0; |
100 | pool->vendorclasses[i++] = 0; |
101 | pool->vendorclasses[i] = 0; |
102 | queue_empty(&pool->vendormap); |
103 | } |
104 | |
105 | void |
106 | pool_addvendorclass(Pool *pool, const char **vendorclass) |
107 | { |
108 | int i, j; |
109 | |
110 | if (!vendorclass || !vendorclass[0]) |
111 | return; |
112 | for (j = 1; vendorclass[j]; j++) |
113 | ; |
114 | i = 0; |
115 | if (pool->vendorclasses) |
116 | { |
117 | for (i = 0; pool->vendorclasses[i] || pool->vendorclasses[i + 1]; i++) |
118 | ; |
119 | if (i) |
120 | i++; |
121 | } |
122 | pool->vendorclasses = solv_realloc2((void *)pool->vendorclasses, i + j + 2, sizeof(const char *)); |
123 | for (j = 0; vendorclass[j]; j++) |
124 | pool->vendorclasses[i++] = solv_strdup(vendorclass[j]); |
125 | pool->vendorclasses[i++] = 0; |
126 | pool->vendorclasses[i] = 0; |
127 | queue_empty(&pool->vendormap); |
128 | } |