clang -cc1 -cc1 -triple amd64-unknown-openbsd7.0 -analyze -disable-free -disable-llvm-verifier -discard-value-names -main-file-name prop.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/games/monop/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/games/monop/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/games/monop/prop.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 | #include <err.h> |
34 | #include <stdio.h> |
35 | #include <stdlib.h> |
36 | |
37 | #include "monop.ext" |
38 | |
39 | static int value(SQUARE *); |
40 | |
41 | |
42 | |
43 | |
44 | |
45 | void |
46 | buy(int plr, SQUARE *sqrp) |
47 | { |
48 | trading = FALSE; |
49 | sqrp->owner = plr; |
50 | add_list(plr, &(play[plr].own_list), cur_p->loc); |
51 | } |
52 | |
53 | |
54 | |
55 | void |
56 | add_list(int plr, OWN **head, int op_sqr) |
57 | { |
58 | int val; |
59 | OWN *tp, *last_tp; |
60 | OWN *op; |
61 | |
62 | if ((op = calloc(1, sizeof (OWN))) == NULL) |
63 | err(1, NULL); |
64 | op->sqr = &board[op_sqr]; |
65 | val = value(op->sqr); |
66 | last_tp = NULL; |
67 | for (tp = *head; tp && value(tp->sqr) < val; tp = tp->next) |
68 | if (val == value(tp->sqr)) { |
69 | free(op); |
70 | return; |
71 | } |
72 | else |
73 | last_tp = tp; |
74 | op->next = tp; |
75 | if (last_tp != NULL) |
76 | last_tp->next = op; |
77 | else |
78 | *head = op; |
79 | if (!trading) |
80 | set_ownlist(plr); |
81 | } |
82 | |
83 | |
84 | |
85 | void |
86 | del_list(int plr, OWN **head, shrt op_sqr) |
87 | { |
88 | OWN *op, *last_op; |
89 | |
90 | switch (board[(int)op_sqr].type) { |
| 1 | 'Default' branch taken. Execution continues on line 101 | |
|
91 | case PRPTY: |
92 | board[(int)op_sqr].desc->mon_desc->num_own--; |
93 | break; |
94 | case RR: |
95 | play[plr].num_rr--; |
96 | break; |
97 | case UTIL: |
98 | play[plr].num_util--; |
99 | break; |
100 | } |
101 | last_op = NULL; |
102 | for (op = *head; op; op = op->next) |
| 2 | | Loop condition is true. Entering loop body | |
|
| |
| 6 | | Assuming pointer value is null | |
|
| 7 | | Loop condition is false. Execution continues on line 107 | |
|
103 | if (op->sqr == &board[(int)op_sqr]) |
| 3 | | Assuming the condition is false | |
|
| |
104 | break; |
105 | else |
106 | last_op = op; |
107 | if (last_op == NULL) |
| |
108 | *head = op->next; |
109 | else { |
110 | last_op->next = op->next; |
| 9 | | Access to field 'next' results in a dereference of a null pointer (loaded from variable 'op') |
|
111 | free(op); |
112 | } |
113 | } |
114 | |
115 | |
116 | |
117 | |
118 | static int |
119 | value(SQUARE *sqp) |
120 | { |
121 | int sqr; |
122 | |
123 | sqr = sqnum(sqp); |
124 | switch (sqp->type) { |
125 | case SAFE: |
126 | return 0; |
127 | default: |
128 | return 1; |
129 | case UTIL: |
130 | if (sqr == 12) |
131 | return 2; |
132 | else |
133 | return 3; |
134 | case RR: |
135 | return 4 + sqr/10; |
136 | case PRPTY: |
137 | return 8 + (sqp->desc) - prop; |
138 | } |
139 | } |
140 | |
141 | |
142 | |
143 | void |
144 | bid(void) |
145 | { |
146 | static bool in[MAX_PL]; |
147 | int i, num_in, cur_max; |
148 | char buf[257]; |
149 | int cur_bid; |
150 | |
151 | printf("\nSo it goes up for auction. Type your bid after your name\n"); |
152 | for (i = 0; i < num_play; i++) |
153 | in[i] = TRUE; |
154 | i = -1; |
155 | cur_max = 0; |
156 | num_in = num_play; |
157 | while (num_in > 1 || (cur_max == 0 && num_in > 0)) { |
158 | i = (i + 1) % num_play; |
159 | if (in[i]) { |
160 | do { |
161 | (void)snprintf(buf, sizeof(buf), "%s: ", name_list[i]); |
162 | cur_bid = get_int(buf); |
163 | if (cur_bid == 0) { |
164 | in[i] = FALSE; |
165 | if (--num_in == 0) |
166 | break; |
167 | } else if (cur_bid <= cur_max) { |
168 | printf("You must bid higher than %d to stay in\n", cur_max); |
169 | printf("(bid of 0 drops you out)\n"); |
170 | } else if (cur_bid > play[i].money) { |
171 | printf("You can't bid more than your cash ($%d)\n", |
172 | play[i].money); |
173 | cur_bid = -1; |
174 | } |
175 | } while (cur_bid != 0 && cur_bid <= cur_max); |
176 | cur_max = (cur_bid ? cur_bid : cur_max); |
177 | } |
178 | } |
179 | if (cur_max != 0) { |
180 | while (!in[i]) |
181 | i = (i + 1) % num_play; |
182 | printf("It goes to %s (%d) for $%d\n",play[i].name,i+1,cur_max); |
183 | buy(i, &board[(int)cur_p->loc]); |
184 | play[i].money -= cur_max; |
185 | } |
186 | else |
187 | printf("Nobody seems to want it, so we'll leave it for later\n"); |
188 | } |
189 | |
190 | |
191 | |
192 | |
193 | int |
194 | prop_worth(PLAY *plp) |
195 | { |
196 | OWN *op; |
197 | int worth; |
198 | |
199 | worth = 0; |
200 | for (op = plp->own_list; op; op = op->next) { |
201 | if (op->sqr->type == PRPTY && op->sqr->desc->monop) |
202 | worth += op->sqr->desc->mon_desc->h_cost * 50 * |
203 | op->sqr->desc->houses; |
204 | worth += op->sqr->cost; |
205 | } |
206 | return worth; |
207 | } |