Skip to content

Commit c1bee34

Browse files
committed
Make some things unsigned that should be (why would we need e.g. a
negative number of airports?) and remove some related bogus casts.
1 parent 860c202 commit c1bee34

File tree

4 files changed

+52
-45
lines changed

4 files changed

+52
-45
lines changed

games/atc/graphics.c

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* $NetBSD: graphics.c,v 1.16 2009/08/12 04:48:03 dholland Exp $ */
1+
/* $NetBSD: graphics.c,v 1.17 2014/03/22 22:24:21 dholland Exp $ */
22

33
/*-
44
* Copyright (c) 1990, 1993
@@ -46,7 +46,7 @@
4646
#if 0
4747
static char sccsid[] = "@(#)graphics.c 8.1 (Berkeley) 5/31/93";
4848
#else
49-
__RCSID("$NetBSD: graphics.c,v 1.16 2009/08/12 04:48:03 dholland Exp $");
49+
__RCSID("$NetBSD: graphics.c,v 1.17 2014/03/22 22:24:21 dholland Exp $");
5050
#endif
5151
#endif /* not lint */
5252

@@ -130,6 +130,7 @@ void
130130
setup_screen(const C_SCREEN *scp)
131131
{
132132
int i, j;
133+
unsigned iu;
133134
char str[3];
134135
const char *airstr;
135136

@@ -193,22 +194,22 @@ setup_screen(const C_SCREEN *scp)
193194
}
194195

195196
str[0] = C_BEACON;
196-
for (i = 0; i < scp->num_beacons; i++) {
197-
str[1] = '0' + i;
198-
(void)wmove(radar, scp->beacon[i].y, scp->beacon[i].x * 2);
197+
for (iu = 0; iu < scp->num_beacons; iu++) {
198+
str[1] = '0' + iu;
199+
(void)wmove(radar, scp->beacon[iu].y, scp->beacon[iu].x * 2);
199200
(void)waddstr(radar, str);
200201
}
201202

202-
for (i = 0; i < scp->num_exits; i++) {
203-
(void)wmove(radar, scp->exit[i].y, scp->exit[i].x * 2);
204-
(void)waddch(radar, '0' + i);
203+
for (iu = 0; iu < scp->num_exits; iu++) {
204+
(void)wmove(radar, scp->exit[iu].y, scp->exit[iu].x * 2);
205+
(void)waddch(radar, '0' + iu);
205206
}
206207

207208
airstr = "^?>?v?<?";
208-
for (i = 0; i < scp->num_airports; i++) {
209-
str[0] = airstr[scp->airport[i].dir];
210-
str[1] = '0' + i;
211-
(void)wmove(radar, scp->airport[i].y, scp->airport[i].x * 2);
209+
for (iu = 0; iu < scp->num_airports; iu++) {
210+
str[0] = airstr[scp->airport[iu].dir];
211+
str[1] = '0' + iu;
212+
(void)wmove(radar, scp->airport[iu].y, scp->airport[iu].x * 2);
212213
(void)waddstr(radar, str);
213214
}
214215

games/atc/input.c

Lines changed: 29 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* $NetBSD: input.c,v 1.24 2009/08/12 04:48:03 dholland Exp $ */
1+
/* $NetBSD: input.c,v 1.25 2014/03/22 22:24:21 dholland Exp $ */
22

33
/*-
44
* Copyright (c) 1990, 1993
@@ -46,7 +46,7 @@
4646
#if 0
4747
static char sccsid[] = "@(#)input.c 8.1 (Berkeley) 5/31/93";
4848
#else
49-
__RCSID("$NetBSD: input.c,v 1.24 2009/08/12 04:48:03 dholland Exp $");
49+
__RCSID("$NetBSD: input.c,v 1.25 2014/03/22 22:24:21 dholland Exp $");
5050
#endif
5151
#endif /* not lint */
5252

@@ -459,36 +459,37 @@ Right(int c __unused)
459459
}
460460

461461
static const char *
462-
delayb(int c)
462+
delayb(int ch)
463463
{
464464
int xdiff, ydiff;
465+
unsigned bn;
465466

466-
c -= '0';
467+
bn = ch -= '0';
467468

468-
if (c >= sp->num_beacons)
469+
if (bn >= sp->num_beacons)
469470
return ("Unknown beacon");
470-
xdiff = sp->beacon[(int)c].x - p.xpos;
471+
xdiff = sp->beacon[bn].x - p.xpos;
471472
xdiff = SGN(xdiff);
472-
ydiff = sp->beacon[(int)c].y - p.ypos;
473+
ydiff = sp->beacon[bn].y - p.ypos;
473474
ydiff = SGN(ydiff);
474475
if (xdiff != displacement[p.dir].dx || ydiff != displacement[p.dir].dy)
475476
return ("Beacon is not in flight path");
476477
p.delayd = 1;
477-
p.delayd_no = c;
478+
p.delayd_no = bn;
478479

479480
if (dest_type != T_NODEST) {
480481
switch (dest_type) {
481482
case T_BEACON:
482-
xdiff = sp->beacon[dest_no].x - sp->beacon[(int)c].x;
483-
ydiff = sp->beacon[dest_no].y - sp->beacon[(int)c].y;
483+
xdiff = sp->beacon[dest_no].x - sp->beacon[bn].x;
484+
ydiff = sp->beacon[dest_no].y - sp->beacon[bn].y;
484485
break;
485486
case T_EXIT:
486-
xdiff = sp->exit[dest_no].x - sp->beacon[(int)c].x;
487-
ydiff = sp->exit[dest_no].y - sp->beacon[(int)c].y;
487+
xdiff = sp->exit[dest_no].x - sp->beacon[bn].x;
488+
ydiff = sp->exit[dest_no].y - sp->beacon[bn].y;
488489
break;
489490
case T_AIRPORT:
490-
xdiff = sp->airport[dest_no].x - sp->beacon[(int)c].x;
491-
ydiff = sp->airport[dest_no].y - sp->beacon[(int)c].y;
491+
xdiff = sp->airport[dest_no].x - sp->beacon[bn].x;
492+
ydiff = sp->airport[dest_no].y - sp->beacon[bn].y;
492493
break;
493494
default:
494495
return ("Bad case in delayb! Get help!");
@@ -587,28 +588,31 @@ setrelalt(int c)
587588
}
588589

589590
static const char *
590-
benum(int c)
591+
benum(int ch)
591592
{
592-
dest_no = c -= '0';
593+
unsigned n;
594+
595+
n = ch - '0';
596+
dest_no = n;
593597

594598
switch (dest_type) {
595599
case T_BEACON:
596-
if (c >= sp->num_beacons)
600+
if (n >= sp->num_beacons)
597601
return ("Unknown beacon");
598-
p.new_dir = DIR_FROM_DXDY(sp->beacon[(int)c].x - p.xpos,
599-
sp->beacon[(int)c].y - p.ypos);
602+
p.new_dir = DIR_FROM_DXDY(sp->beacon[n].x - p.xpos,
603+
sp->beacon[n].y - p.ypos);
600604
break;
601605
case T_EXIT:
602-
if (c >= sp->num_exits)
606+
if (n >= sp->num_exits)
603607
return ("Unknown exit");
604-
p.new_dir = DIR_FROM_DXDY(sp->exit[(int)c].x - p.xpos,
605-
sp->exit[(int)c].y - p.ypos);
608+
p.new_dir = DIR_FROM_DXDY(sp->exit[n].x - p.xpos,
609+
sp->exit[n].y - p.ypos);
606610
break;
607611
case T_AIRPORT:
608-
if (c >= sp->num_airports)
612+
if (n >= sp->num_airports)
609613
return ("Unknown airport");
610-
p.new_dir = DIR_FROM_DXDY(sp->airport[(int)c].x - p.xpos,
611-
sp->airport[(int)c].y - p.ypos);
614+
p.new_dir = DIR_FROM_DXDY(sp->airport[n].x - p.xpos,
615+
sp->airport[n].y - p.ypos);
612616
break;
613617
default:
614618
return ("Unknown case in benum! Get help!");

games/atc/struct.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* $NetBSD: struct.h,v 1.6 2006/06/07 09:36:39 jnemeth Exp $ */
1+
/* $NetBSD: struct.h,v 1.7 2014/03/22 22:24:21 dholland Exp $ */
22

33
/*-
44
* Copyright (c) 1990, 1993
@@ -60,10 +60,10 @@ typedef struct {
6060
int width, height;
6161
int update_secs;
6262
int newplane_time;
63-
int num_exits;
63+
unsigned num_exits;
6464
int num_lines;
65-
int num_beacons;
66-
int num_airports;
65+
unsigned num_beacons;
66+
unsigned num_airports;
6767
EXIT *exit;
6868
LINE *line;
6969
BEACON *beacon;

games/atc/update.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* $NetBSD: update.c,v 1.22 2011/02/15 08:25:25 is Exp $ */
1+
/* $NetBSD: update.c,v 1.23 2014/03/22 22:24:21 dholland Exp $ */
22

33
/*-
44
* Copyright (c) 1990, 1993
@@ -46,7 +46,7 @@
4646
#if 0
4747
static char sccsid[] = "@(#)update.c 8.1 (Berkeley) 5/31/93";
4848
#else
49-
__RCSID("$NetBSD: update.c,v 1.22 2011/02/15 08:25:25 is Exp $");
49+
__RCSID("$NetBSD: update.c,v 1.23 2014/03/22 22:24:21 dholland Exp $");
5050
#endif
5151
#endif /* not lint */
5252

@@ -60,7 +60,8 @@ static int dir_deg(int);
6060
void
6161
update(int dummy __unused)
6262
{
63-
int i, dir_diff, unclean;
63+
int dir_diff, unclean;
64+
unsigned i;
6465
PLANE *pp, *p1, *p2;
6566

6667
#ifdef SYSV
@@ -311,7 +312,8 @@ int
311312
addplane(void)
312313
{
313314
PLANE p, *pp, *p1;
314-
int i, num_starts, isclose, rnd, rnd2, pnum;
315+
int isclose, pnum;
316+
unsigned num_starts, rnd, rnd2, i;
315317

316318
(void)memset(&p, 0, sizeof (p));
317319

0 commit comments

Comments
 (0)