Bug Summary

File:src/games/monop/misc.c
Warning:line 109, column 18
1st function call argument is an uninitialized value

Annotated Source Code

Press '?' to see keyboard shortcuts

clang -cc1 -cc1 -triple amd64-unknown-openbsd7.0 -analyze -disable-free -disable-llvm-verifier -discard-value-names -main-file-name misc.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/misc.c
1/* $OpenBSD: misc.c,v 1.14 2016/01/08 18:20:33 mestre Exp $ */
2/* $NetBSD: misc.c,v 1.4 1995/03/23 08:34:47 cgd Exp $ */
3
4/*
5 * Copyright (c) 1980, 1993
6 * The Regents of the University of California. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
16 * 3. Neither the name of the University nor the names of its contributors
17 * may be used to endorse or promote products derived from this software
18 * without specific prior written permission.
19 *
20 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
21 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
24 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30 * SUCH DAMAGE.
31 */
32
33#include <ctype.h>
34#include <stdio.h>
35#include <stdlib.h>
36
37#include "monop.ext"
38
39/*
40 * This routine executes a truncated set of commands until a
41 * "yes or "no" answer is gotten.
42 */
43int
44getyn(char *prompt)
45{
46 int com;
47
48 for (;;)
49 if ((com=getinp(prompt, ynlist)) < 2)
50 return com;
51 else
52 (*func[com-2])();
53}
54/*
55 * This routine tells the player if he's out of money.
56 */
57void
58notify(void)
59{
60 if (cur_p->money < 0)
61 printf("That leaves you $%d in debt\n", -cur_p->money);
62 else if (cur_p->money == 0)
63 printf("that leaves you broke\n");
64 else if (fixing && !told_em && cur_p->money > 0) {
65 printf("-- You are now Solvent ---\n");
66 told_em = TRUE(1);
67 }
68}
69/*
70 * This routine switches to the next player
71 */
72void
73next_play(void)
74{
75 player = (player + 1) % num_play;
76 cur_p = &play[player];
77 num_doub = 0;
78}
79/*
80 * This routine gets an integer from the keyboard after the
81 * given prompt.
82 */
83int
84get_int(char *prompt)
85{
86 int num, snum;
87 char *sp;
88 int c, i;
89 char buf[257];
90
91 for (;;) {
1
Loop condition is true. Entering loop body
92 printf("%s", prompt);
93 num = 0;
94 i = 1;
95 for (sp = buf; (c = getchar()(!__isthreaded ? (--((&__sF[0]))->_r < 0 ? __srget(
(&__sF[0])) : (int)(*((&__sF[0]))->_p++)) : (getc)
((&__sF[0])))
) != '\n';) {
2
Assuming '__isthreaded' is not equal to 0
3
'?' condition is false
4
Assuming the condition is true
5
Loop condition is true. Entering loop body
9
'?' condition is false
10
Assuming the condition is false
11
Loop condition is false. Execution continues on line 106
96 if (c == EOF(-1)) {
6
Assuming the condition is false
7
Taking false branch
97 printf("user closed input stream, quitting...\n");
98 exit(0);
99 }
100 *sp = c;
101 if (i < (int)sizeof(buf)) {
8
Taking true branch
102 i++;
103 sp++;
104 }
105 }
106 *sp = c;
107 if (sp
11.1
'sp' is not equal to 'buf'
== buf)
12
Taking false branch
108 continue;
109 for (sp = buf; isspace((unsigned char)*sp); sp++)
13
Loop condition is true. Entering loop body
14
Loop condition is true. Entering loop body
15
1st function call argument is an uninitialized value
110 ;
111 for (; isdigit((unsigned char)*sp); sp++) {
112 snum = num;
113 num = num * 10 + *sp - '0';
114 if (num < snum) {
115 printf("Number too large - ");
116 *(sp + 1) = 'X'; /* Force a break */
117 }
118 }
119 /* Be kind to trailing spaces */
120 for (; *sp == ' '; sp++)
121 ;
122 if (*sp == '\n')
123 return num;
124 else
125 printf("I can't understand that\n");
126 }
127}
128/*
129 * This routine sets the monopoly flag from the list given.
130 */
131void
132set_ownlist(int pl)
133{
134 int num; /* general counter */
135 MON *orig; /* remember starting monop ptr */
136 OWN *op; /* current owned prop */
137 OWN *orig_op; /* origianl prop before loop */
138
139 op = play[pl].own_list;
140#ifdef DEBUG
141 printf("op [%p] = play[pl [%d] ].own_list;\n", op, pl);
142#endif
143 while (op) {
144#ifdef DEBUG
145 printf("op->sqr->type = %d\n", op->sqr->type);
146#endif
147 switch (op->sqr->type) {
148 case UTIL2:
149#ifdef DEBUG
150 printf(" case UTIL:\n");
151#endif
152 for (num = 0; op && op->sqr->type == UTIL2; op = op->next)
153 num++;
154 play[pl].num_util = num;
155#ifdef DEBUG
156 printf("play[pl].num_util = num [%d];\n", num);
157#endif
158 break;
159 case RR1:
160#ifdef DEBUG
161 printf(" case RR:\n");
162#endif
163 for (num = 0; op && op->sqr->type == RR1; op = op->next) {
164#ifdef DEBUG
165 printf("iter: %d\n", num);
166 printf("op = %p, op->sqr = %p, op->sqr->type = %d\n", op, op->sqr, op->sqr->type);
167#endif
168 num++;
169 }
170 play[pl].num_rr = num;
171#ifdef DEBUG
172 printf("play[pl].num_rr = num [%d];\n", num);
173#endif
174 break;
175 case PRPTY0:
176#ifdef DEBUG
177 printf(" case PRPTY:\n");
178#endif
179 orig = op->sqr->desc->mon_desc;
180 orig_op = op;
181 num = 0;
182 while (op && op->sqr->desc->mon_desc == orig) {
183#ifdef DEBUG
184 printf("iter: %d\n", num);
185#endif
186 num++;
187#ifdef DEBUG
188 printf("op = op->next ");
189#endif
190 op = op->next;
191#ifdef DEBUG
192 printf("[%p];\n", op);
193#endif
194 }
195#ifdef DEBUG
196 printf("num = %d\n", num);
197#endif
198 if (orig == NULL((void *)0)) {
199 printf("panic: bad monopoly descriptor: orig = %p\n", orig);
200 printf("player # %d\n", pl+1);
201 printhold(pl);
202 printf("orig_op = %p\n", orig_op);
203 if (orig_op) {
204 printf("orig_op->sqr->type = %d (PRPTY)\n",
205 orig_op->sqr->type);
206 printf("orig_op->next = %p\n",
207 orig_op->next);
208 printf("orig_op->sqr->desc = %p\n",
209 orig_op->sqr->desc);
210 }
211 printf("op = %p\n", op);
212 if (op) {
213 printf("op->sqr->type = %d (PRPTY)\n",
214 op->sqr->type);
215 printf("op->next = %p\n", op->next);
216 printf("op->sqr->desc = %p\n",
217 op->sqr->desc);
218 }
219 printf("num = %d\n", num);
220 exit(1);
221 }
222#ifdef DEBUG
223 printf("orig->num_in = %d\n", orig->num_in);
224#endif
225 if (num == orig->num_in)
226 is_monop(orig, pl);
227 else
228 isnot_monop(orig);
229 break;
230 }
231 }
232}
233/*
234 * This routine sets things up as if it is a new monopoly
235 */
236void
237is_monop(MON *mp, int pl)
238{
239 int i;
240
241 mp->owner = pl;
242 mp->num_own = mp->num_in;
243 for (i = 0; i < mp->num_in; i++)
244 mp->sq[i]->desc->monop = TRUE(1);
245 mp->name = mp->mon_n;
246}
247/*
248 * This routine sets things up as if it is no longer a monopoly
249 */
250void
251isnot_monop(MON *mp)
252{
253 int i;
254
255 mp->owner = -1;
256 for (i = 0; i < mp->num_in; i++)
257 mp->sq[i]->desc->monop = FALSE(0);
258 mp->name = mp->not_m;
259}
260/*
261 * This routine gives a list of the current player's routine
262 */
263void
264list(void)
265{
266 printhold(player);
267}
268/*
269 * This routine gives a list of a given players holdings
270 */
271void
272list_all(void)
273{
274 int pl;
275
276 while ((pl=getinp("Whose holdings do you want to see? ", name_list)) < num_play)
277 printhold(pl);
278}
279/*
280 * This routine gives the players a chance before it exits.
281 */
282void
283quit(void)
284{
285 putchar('\n')(!__isthreaded ? __sputc('\n', (&__sF[1])) : (putc)('\n',
(&__sF[1])))
;
286 if (getyn("Do you all really want to quit? ") == 0)
287 exit(0);
288}