clang -cc1 -cc1 -triple amd64-unknown-openbsd7.0 -analyze -disable-free -disable-llvm-verifier -discard-value-names -main-file-name operator.c -analyzer-store=region -analyzer-opt-analyze-nested-blocks -analyzer-checker=core -analyzer-checker=apiModeling -analyzer-checker=unix -analyzer-checker=deadcode -analyzer-checker=security.insecureAPI.UncheckedReturn -analyzer-checker=security.insecureAPI.getpw -analyzer-checker=security.insecureAPI.gets -analyzer-checker=security.insecureAPI.mktemp -analyzer-checker=security.insecureAPI.mkstemp -analyzer-checker=security.insecureAPI.vfork -analyzer-checker=nullability.NullPassedToNonnull -analyzer-checker=nullability.NullReturnedFromNonnull -analyzer-output plist -w -setup-static-analyzer -mrelocation-model pic -pic-level 1 -pic-is-pie -mframe-pointer=all -relaxed-aliasing -fno-rounding-math -mconstructor-aliases -munwind-tables -target-cpu x86-64 -target-feature +retpoline-indirect-calls -target-feature +retpoline-indirect-branches -tune-cpu generic -debugger-tuning=gdb -fcoverage-compilation-dir=/usr/src/usr.bin/find/obj -resource-dir /usr/local/lib/clang/13.0.0 -internal-isystem /usr/local/lib/clang/13.0.0/include -internal-externc-isystem /usr/include -O2 -fdebug-compilation-dir=/usr/src/usr.bin/find/obj -ferror-limit 19 -fwrapv -D_RET_PROTECTOR -ret-protector -fgnuc-version=4.2.1 -vectorize-loops -vectorize-slp -fno-builtin-malloc -fno-builtin-calloc -fno-builtin-realloc -fno-builtin-valloc -fno-builtin-free -fno-builtin-strdup -fno-builtin-strndup -analyzer-output=html -faddrsig -D__GCC_HAVE_DWARF2_CFI_ASM=1 -o /home/ben/Projects/vmm/scan-build/2022-01-12-194120-40624-1 -x c /usr/src/usr.bin/find/operator.c
| 1 | |
| 2 | |
| 3 | |
| 4 | |
| 5 | |
| 6 | |
| 7 | |
| 8 | |
| 9 | |
| 10 | |
| 11 | |
| 12 | |
| 13 | |
| 14 | |
| 15 | |
| 16 | |
| 17 | |
| 18 | |
| 19 | |
| 20 | |
| 21 | |
| 22 | |
| 23 | |
| 24 | |
| 25 | |
| 26 | |
| 27 | |
| 28 | |
| 29 | |
| 30 | |
| 31 | |
| 32 | |
| 33 | |
| 34 | |
| 35 | #include <sys/types.h> |
| 36 | #include <sys/stat.h> |
| 37 | |
| 38 | #include <err.h> |
| 39 | #include <fts.h> |
| 40 | #include <stdio.h> |
| 41 | |
| 42 | #include "find.h" |
| 43 | #include "extern.h" |
| 44 | |
| 45 | |
| 46 | |
| 47 | |
| 48 | |
| 49 | static PLAN * |
| 50 | yanknode(PLAN **planp) |
| 51 | { |
| 52 | PLAN *node; |
| 53 | |
| 54 | if ((node = (*planp)) == NULL) |
| 55 | return (NULL); |
| 56 | (*planp) = (*planp)->next; |
| 57 | node->next = NULL; |
| 58 | return (node); |
| 59 | } |
| 60 | |
| 61 | |
| 62 | |
| 63 | |
| 64 | |
| 65 | |
| 66 | |
| 67 | static PLAN * |
| 68 | yankexpr(PLAN **planp) |
| 69 | { |
| 70 | PLAN *next; |
| 71 | PLAN *node; |
| 72 | PLAN *tail; |
| 73 | PLAN *subplan; |
| 74 | extern int f_expr(PLAN *, FTSENT *); |
| 75 | |
| 76 | |
| 77 | if ((node = yanknode(planp)) == NULL) |
| 78 | return (NULL); |
| 79 | |
| 80 | |
| 81 | |
| 82 | |
| 83 | |
| 84 | |
| 85 | |
| 86 | if (node->type == N_OPENPAREN) |
| 87 | for (tail = subplan = NULL;;) { |
| 88 | if ((next = yankexpr(planp)) == NULL) |
| 89 | errx(1, "(: missing closing ')'"); |
| 90 | |
| 91 | |
| 92 | |
| 93 | |
| 94 | |
| 95 | |
| 96 | |
| 97 | if (next->type == N_CLOSEPAREN) { |
| 98 | if (subplan == NULL) |
| 99 | errx(1, "(): empty inner expression"); |
| 100 | node->p_data[0] = subplan; |
| 101 | node->type = N_EXPR; |
| 102 | node->eval = f_expr; |
| 103 | break; |
| 104 | } else { |
| 105 | if (subplan == NULL) |
| 106 | tail = subplan = next; |
| 107 | else { |
| 108 | tail->next = next; |
| 109 | tail = next; |
| 110 | } |
| 111 | tail->next = NULL; |
| 112 | } |
| 113 | } |
| 114 | return (node); |
| 115 | } |
| 116 | |
| 117 | |
| 118 | |
| 119 | |
| 120 | |
| 121 | PLAN * |
| 122 | paren_squish(PLAN *plan) |
| 123 | { |
| 124 | PLAN *expr; |
| 125 | PLAN *tail; |
| 126 | PLAN *result; |
| 127 | |
| 128 | result = tail = NULL; |
| 129 | |
| 130 | |
| 131 | |
| 132 | |
| 133 | |
| 134 | while ((expr = yankexpr(&plan)) != NULL) { |
| 135 | |
| 136 | |
| 137 | |
| 138 | |
| 139 | if (expr->type == N_CLOSEPAREN) |
| 140 | errx(1, "): no beginning '('"); |
| 141 | |
| 142 | |
| 143 | if (result == NULL) |
| 144 | tail = result = expr; |
| 145 | else { |
| 146 | tail->next = expr; |
| 147 | tail = expr; |
| 148 | } |
| 149 | tail->next = NULL; |
| 150 | } |
| 151 | return (result); |
| 152 | } |
| 153 | |
| 154 | |
| 155 | |
| 156 | |
| 157 | |
| 158 | PLAN * |
| 159 | not_squish(PLAN *plan) |
| 160 | { |
| 161 | PLAN *next; |
| 162 | PLAN *node; |
| 163 | PLAN *tail; |
| 164 | PLAN *result; |
| 165 | |
| 166 | tail = result = next = NULL; |
| 167 | |
| 168 | while ((next = yanknode(&plan)) != NULL) { |
| 1 | Loop condition is true. Entering loop body | |
|
| 5 | | Loop condition is true. Entering loop body | |
|
| 9 | | Loop condition is true. Entering loop body | |
|
| 13 | | Loop condition is true. Entering loop body | |
|
| 169 | |
| 170 | |
| 171 | |
| 172 | |
| 173 | if (next->type == N_EXPR) |
| 2 | | Assuming field 'type' is equal to N_EXPR | |
|
| |
| 6 | | Assuming field 'type' is equal to N_EXPR | |
|
| |
| 10 | | Assuming field 'type' is equal to N_EXPR | |
|
| |
| 14 | | Assuming field 'type' is not equal to N_EXPR | |
|
| |
| 174 | next->p_data[0] = not_squish(next->p_data[0]); |
| |
| |
| |
| 175 | |
| 176 | |
| 177 | |
| 178 | |
| 179 | |
| 180 | |
| 181 | if (next->type == N_NOT) { |
| 16 | | Assuming field 'type' is equal to N_NOT | |
|
| |
| 182 | int notlevel = 1; |
| 183 | |
| 184 | node = yanknode(&plan); |
| 185 | while (node != NULL && node->type == N_NOT) { |
| 18 | | Assuming field 'type' is equal to N_NOT | |
|
| 19 | | Loop condition is true. Entering loop body | |
|
| 20 | | Assuming field 'type' is not equal to N_NOT | |
|
| 21 | | Loop condition is false. Execution continues on line 189 | |
|
| 186 | ++notlevel; |
| 187 | node = yanknode(&plan); |
| 188 | } |
| 189 | if (node == NULL) |
| |
| 190 | errx(1, "!: no following expression"); |
| 191 | if (node->type == N_OR) |
| 23 | | Assuming field 'type' is not equal to N_OR | |
|
| |
| 192 | errx(1, "!: nothing between ! and -o"); |
| 193 | if (node->type == N_EXPR) |
| 25 | | Assuming field 'type' is equal to N_EXPR | |
|
| |
| 194 | node = not_squish(node); |
| 195 | if (notlevel % 2 != 1) |
| |
| 196 | next = node; |
| 197 | else |
| 198 | next->p_data[0] = node; |
| 199 | } |
| 200 | |
| 201 | |
| 202 | if (result == NULL) |
| |
| 203 | tail = result = next; |
| 29 | | Null pointer value stored to 'tail' | |
|
| 204 | else { |
| 205 | tail->next = next; |
| 206 | tail = next; |
| 207 | } |
| 208 | tail->next = NULL; |
| 30 | | Access to field 'next' results in a dereference of a null pointer (loaded from variable 'tail') |
|
| 209 | } |
| 210 | return (result); |
| 211 | } |
| 212 | |
| 213 | |
| 214 | |
| 215 | |
| 216 | |
| 217 | PLAN * |
| 218 | or_squish(PLAN *plan) |
| 219 | { |
| 220 | PLAN *next; |
| 221 | PLAN *tail; |
| 222 | PLAN *result; |
| 223 | |
| 224 | tail = result = next = NULL; |
| 225 | |
| 226 | while ((next = yanknode(&plan)) != NULL) { |
| 227 | |
| 228 | |
| 229 | |
| 230 | |
| 231 | if (next->type == N_EXPR) |
| 232 | next->p_data[0] = or_squish(next->p_data[0]); |
| 233 | |
| 234 | |
| 235 | if (next->type == N_NOT) |
| 236 | next->p_data[0] = or_squish(next->p_data[0]); |
| 237 | |
| 238 | |
| 239 | |
| 240 | |
| 241 | |
| 242 | |
| 243 | if (next->type == N_OR) { |
| 244 | if (result == NULL) |
| 245 | errx(1, "-o: no expression before -o"); |
| 246 | next->p_data[0] = result; |
| 247 | next->p_data[1] = or_squish(plan); |
| 248 | if (next->p_data[1] == NULL) |
| 249 | errx(1, "-o: no expression after -o"); |
| 250 | return (next); |
| 251 | } |
| 252 | |
| 253 | |
| 254 | if (result == NULL) |
| 255 | tail = result = next; |
| 256 | else { |
| 257 | tail->next = next; |
| 258 | tail = next; |
| 259 | } |
| 260 | tail->next = NULL; |
| 261 | } |
| 262 | return (result); |
| 263 | } |