Skip to content

Commit 24f809b

Browse files
hubertfhubertf
hubertf
authored and
hubertf
committed
The game sail(6) has a function Write() which is used both with
integer arguments and with string arguments (cast to long, and in one place to int). The patch here cleans this up, making it into two separate functions; this allows for the game to be made const-correct in future and improves portability. The patch also contains two other fragments: a change to use the symbolic constant SEEK_END with fseek(), and a change to use snprintf in one place to avoid a buffer overrun. Via PR 6569 by Joseph Myers <jsm28@cam.ac.uk>.
1 parent c7bcded commit 24f809b

File tree

16 files changed

+141
-123
lines changed

16 files changed

+141
-123
lines changed

games/sail/assorted.c

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* $NetBSD: assorted.c,v 1.6 1997/10/13 21:02:57 christos Exp $ */
1+
/* $NetBSD: assorted.c,v 1.7 1999/02/10 00:45:45 hubertf Exp $ */
22

33
/*
44
* Copyright (c) 1983, 1993
@@ -38,7 +38,7 @@
3838
#if 0
3939
static char sccsid[] = "@(#)assorted.c 8.2 (Berkeley) 4/28/95";
4040
#else
41-
__RCSID("$NetBSD: assorted.c,v 1.6 1997/10/13 21:02:57 christos Exp $");
41+
__RCSID("$NetBSD: assorted.c,v 1.7 1999/02/10 00:45:45 hubertf Exp $");
4242
#endif
4343
#endif /* not lint */
4444

@@ -139,17 +139,17 @@ int rig, shot, hittable, roll;
139139
hull -= ghits;
140140
if (Ghit)
141141
Write(portside(from, on, 0) ? W_GUNR : W_GUNL,
142-
on, 0, guns, car, 0, 0);
142+
on, guns, car, 0, 0);
143143
hull -= hhits;
144144
hull = hull < 0 ? 0 : hull;
145145
if (on->file->captured != 0 && Chit)
146-
Write(W_PCREW, on, 0, pc, 0, 0, 0);
146+
Write(W_PCREW, on, pc, 0, 0, 0);
147147
if (Hhit)
148-
Write(W_HULL, on, 0, hull, 0, 0, 0);
148+
Write(W_HULL, on, hull, 0, 0, 0);
149149
if (Chit)
150-
Write(W_CREW, on, 0, crew[0], crew[1], crew[2], 0);
150+
Write(W_CREW, on, crew[0], crew[1], crew[2], 0);
151151
if (Rhit)
152-
Write(W_RIGG, on, 0, rigg[0], rigg[1], rigg[2], rigg[3]);
152+
Write(W_RIGG, on, rigg[0], rigg[1], rigg[2], rigg[3]);
153153
switch (shot) {
154154
case L_ROUND:
155155
message = "firing round shot on $$";
@@ -217,7 +217,7 @@ int rig, shot, hittable, roll;
217217
break;
218218
case 5:
219219
message = "rudder cables shot through";
220-
Write(W_TA, on, 0, 0, 0, 0, 0);
220+
Write(W_TA, on, 0, 0, 0, 0);
221221
break;
222222
case 6:
223223
message = "shot holes below the water line";
@@ -233,10 +233,10 @@ int rig, shot, hittable, roll;
233233
if (on->specs->qual <= 0) {
234234
makemsg(on, "crew mutinying!");
235235
on->specs->qual = 5;
236-
Write(W_CAPTURED, on, 0, on->file->index, 0, 0, 0);
236+
Write(W_CAPTURED, on, on->file->index, 0, 0, 0);
237237
} else
238238
makemsg(on, "crew demoralized");
239-
Write(W_QUAL, on, 0, on->specs->qual, 0, 0, 0);
239+
Write(W_QUAL, on, on->specs->qual, 0, 0, 0);
240240
}
241241
*/
242242
if (!hull)
@@ -249,12 +249,12 @@ struct ship *from, *to;
249249
char all, flag;
250250
{
251251
if (flag & 1) {
252-
Write(W_UNGRAP, from, 0, to->file->index, all, 0, 0);
253-
Write(W_UNGRAP, to, 0, from->file->index, all, 0, 0);
252+
Write(W_UNGRAP, from, to->file->index, all, 0, 0);
253+
Write(W_UNGRAP, to, from->file->index, all, 0, 0);
254254
}
255255
if (flag & 2) {
256-
Write(W_UNFOUL, from, 0, to->file->index, all, 0, 0);
257-
Write(W_UNFOUL, to, 0, from->file->index, all, 0, 0);
256+
Write(W_UNFOUL, from, to->file->index, all, 0, 0);
257+
Write(W_UNFOUL, to, from->file->index, all, 0, 0);
258258
}
259259
if (!snagged2(from, to)) {
260260
if (!snagged(from)) {
@@ -278,20 +278,20 @@ struct ship *ship, *from;
278278

279279
if (ship->file->struck)
280280
return;
281-
Write(W_STRUCK, ship, 0, 1, 0, 0, 0);
281+
Write(W_STRUCK, ship, 1, 0, 0, 0);
282282
points = ship->specs->pts + from->file->points;
283-
Write(W_POINTS, from, 0, points, 0, 0, 0);
283+
Write(W_POINTS, from, points, 0, 0, 0);
284284
unboard(ship, ship, 0); /* all offense */
285285
unboard(ship, ship, 1); /* all defense */
286286
switch (die()) {
287287
case 3:
288288
case 4: /* ship may sink */
289-
Write(W_SINK, ship, 0, 1, 0, 0, 0);
289+
Write(W_SINK, ship, 1, 0, 0, 0);
290290
break;
291291
case 5:
292292
case 6: /* ship may explode */
293-
Write(W_EXPLODE, ship, 0, 1, 0, 0, 0);
293+
Write(W_EXPLODE, ship, 1, 0, 0, 0);
294294
break;
295295
}
296-
Write(W_SIGNAL, ship, 1, (int) "striking her colours!", 0, 0, 0);
296+
Writestr(W_SIGNAL, ship, "striking her colours!");
297297
}

games/sail/dr_1.c

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* $NetBSD: dr_1.c,v 1.7 1998/08/30 09:19:40 veego Exp $ */
1+
/* $NetBSD: dr_1.c,v 1.8 1999/02/10 00:45:45 hubertf Exp $ */
22

33
/*
44
* Copyright (c) 1983, 1993
@@ -38,7 +38,7 @@
3838
#if 0
3939
static char sccsid[] = "@(#)dr_1.c 8.1 (Berkeley) 5/31/93";
4040
#else
41-
__RCSID("$NetBSD: dr_1.c,v 1.7 1998/08/30 09:19:40 veego Exp $");
41+
__RCSID("$NetBSD: dr_1.c,v 1.8 1999/02/10 00:45:45 hubertf Exp $");
4242
#endif
4343
#endif /* not lint */
4444

@@ -192,7 +192,7 @@ int key;
192192
makemsg(from, "boarders from %s repelled", to->shipname);
193193
(void) sprintf(message, "killed in melee: %d. %s: %d",
194194
totalto, from->shipname, totalfrom);
195-
Write(W_SIGNAL, to, 1, (long) message, 0, 0, 0);
195+
Writestr(W_SIGNAL, to, message);
196196
if (key)
197197
return 1;
198198
} else if (strengthto >= fromstrength * 3) {
@@ -201,7 +201,7 @@ int key;
201201
subtract(to, totalto, crewto, tocap, pcto);
202202
if (key) {
203203
if (fromcap != from)
204-
Write(W_POINTS, fromcap, 0,
204+
Write(W_POINTS, fromcap,
205205
fromcap->file->points -
206206
from->file->struck
207207
? from->specs->pts
@@ -212,22 +212,22 @@ int key;
212212
I guess that what is going on here is that the pointer is multiplied
213213
or something. */
214214

215-
Write(W_CAPTURED, from, 0, to->file->index, 0, 0, 0);
215+
Write(W_CAPTURED, from, to->file->index, 0, 0, 0);
216216
topoints = 2 * from->specs->pts + to->file->points;
217217
if (from->file->struck)
218218
topoints -= from->specs->pts;
219-
Write(W_POINTS, to, 0, topoints, 0, 0, 0);
219+
Write(W_POINTS, to, topoints, 0, 0, 0);
220220
mento = crewto[0] ? crewto[0] : crewto[1];
221221
if (mento) {
222222
subtract(to, mento, crewto, tocap, pcto);
223223
subtract(from, - mento, crewfrom, to, 0);
224224
}
225225
(void) sprintf(message, "captured by the %s!",
226226
to->shipname);
227-
Write(W_SIGNAL, from, 1, (long) message, 0, 0, 0);
227+
Writestr(W_SIGNAL, from, message);
228228
(void) sprintf(message, "killed in melee: %d. %s: %d",
229229
totalto, from->shipname, totalfrom);
230-
Write(W_SIGNAL, to, 1, (long) message, 0, 0, 0);
230+
Writestr(W_SIGNAL, to, message);
231231
mento = 0;
232232
return 0;
233233
}
@@ -434,7 +434,7 @@ next()
434434
}
435435
return -1;
436436
}
437-
Write(W_TURN, SHIP(0), 0, turn, 0, 0, 0);
437+
Write(W_TURN, SHIP(0), turn, 0, 0, 0);
438438
if (turn % 7 == 0 && (die() >= cc->windchange || !windspeed)) {
439439
switch (die()) {
440440
case 1:
@@ -472,7 +472,7 @@ next()
472472
}
473473
else
474474
windspeed++;
475-
Write(W_WIND, SHIP(0), 0, winddir, windspeed, 0, 0);
475+
Write(W_WIND, SHIP(0), winddir, windspeed, 0, 0);
476476
}
477477
return 0;
478478
}

games/sail/dr_2.c

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* $NetBSD: dr_2.c,v 1.8 1998/09/11 14:13:46 hubertf Exp $ */
1+
/* $NetBSD: dr_2.c,v 1.9 1999/02/10 00:45:45 hubertf Exp $ */
22

33
/*
44
* Copyright (c) 1983, 1993
@@ -38,7 +38,7 @@
3838
#if 0
3939
static char sccsid[] = "@(#)dr_2.c 8.1 (Berkeley) 5/31/93";
4040
#else
41-
__RCSID("$NetBSD: dr_2.c,v 1.8 1998/09/11 14:13:46 hubertf Exp $");
41+
__RCSID("$NetBSD: dr_2.c,v 1.9 1999/02/10 00:45:45 hubertf Exp $");
4242
#endif
4343
#endif /* not lint */
4444

@@ -93,8 +93,8 @@ checkup()
9393
continue;
9494
if (die() < 5)
9595
continue;
96-
Write(sink == 1 ? W_SINK : W_EXPLODE, sp, 0, 2, 0, 0, 0);
97-
Write(W_DIR, sp, 0, 0, 0, 0, 0);
96+
Write(sink == 1 ? W_SINK : W_EXPLODE, sp, 2, 0, 0, 0);
97+
Write(W_DIR, sp, 0, 0, 0, 0);
9898
if (snagged(sp))
9999
foreachship(sq)
100100
cleansnag(sp, sq, 1);
@@ -120,10 +120,9 @@ prizecheck()
120120
if (sp->file->struck || sp->file->dir == 0)
121121
continue;
122122
if (sp->specs->crew1 + sp->specs->crew2 + sp->specs->crew3 > sp->file->pcrew * 6) {
123-
Write(W_SIGNAL, sp, 1,
124-
(long)"prize crew overthrown", 0, 0, 0);
125-
Write(W_POINTS, sp->file->captured, 0, sp->file->captured->file->points - 2 * sp->specs->pts, 0, 0, 0);
126-
Write(W_CAPTURED, sp, 0, -1, 0, 0, 0);
123+
Writestr(W_SIGNAL, sp, "prize crew overthrown");
124+
Write(W_POINTS, sp->file->captured, sp->file->captured->file->points - 2 * sp->specs->pts, 0, 0, 0);
125+
Write(W_CAPTURED, sp, -1, 0, 0, 0);
127126
}
128127
}
129128
}

games/sail/dr_3.c

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* $NetBSD: dr_3.c,v 1.5 1997/10/13 21:03:27 christos Exp $ */
1+
/* $NetBSD: dr_3.c,v 1.6 1999/02/10 00:45:45 hubertf Exp $ */
22

33
/*
44
* Copyright (c) 1983, 1993
@@ -38,7 +38,7 @@
3838
#if 0
3939
static char sccsid[] = "@(#)dr_3.c 8.1 (Berkeley) 5/31/93";
4040
#else
41-
__RCSID("$NetBSD: dr_3.c,v 1.5 1997/10/13 21:03:27 christos Exp $");
41+
__RCSID("$NetBSD: dr_3.c,v 1.6 1999/02/10 00:45:45 hubertf Exp $");
4242
#endif
4343
#endif /* not lint */
4444

@@ -138,8 +138,8 @@ moveall() /* move all comp ships */
138138
if (die() < 4) {
139139
makesignal(sp, "fouled with $$",
140140
sq);
141-
Write(W_FOUL, sp, 0, l, 0, 0, 0);
142-
Write(W_FOUL, sq, 0, n, 0, 0, 0);
141+
Write(W_FOUL, sp, l, 0, 0, 0);
142+
Write(W_FOUL, sq, n, 0, 0, 0);
143143
}
144144
snap++;
145145
}
@@ -170,13 +170,13 @@ moveall() /* move all comp ships */
170170
if (sp->file->dir != 0) {
171171
*sp->file->movebuf = 0;
172172
if (row[n] != sp->file->row)
173-
Write(W_ROW, sp, 0, sp->file->row, 0, 0, 0);
173+
Write(W_ROW, sp, sp->file->row, 0, 0, 0);
174174
if (col[n] != sp->file->col)
175-
Write(W_COL, sp, 0, sp->file->col, 0, 0, 0);
175+
Write(W_COL, sp, sp->file->col, 0, 0, 0);
176176
if (dir[n] != sp->file->dir)
177-
Write(W_DIR, sp, 0, sp->file->dir, 0, 0, 0);
177+
Write(W_DIR, sp, sp->file->dir, 0, 0, 0);
178178
if (drift[n] != sp->file->drift)
179-
Write(W_DRIFT, sp, 0, sp->file->drift, 0, 0, 0);
179+
Write(W_DRIFT, sp, sp->file->drift, 0, 0, 0);
180180
}
181181
n++;
182182
}
@@ -278,7 +278,7 @@ char isdefense;
278278
for (n = 0; n < NBP && bp[n].turnsent; n++)
279279
;
280280
if (n < NBP && sections) {
281-
Write(isdefense ? W_DBP : W_OBP, from, 0,
281+
Write(isdefense ? W_DBP : W_OBP, from,
282282
n, turn, to->file->index, sections);
283283
if (isdefense)
284284
makemsg(from, "repelling boarders");
@@ -355,6 +355,6 @@ checksails()
355355
} else
356356
full = 0;
357357
if ((sp->file->FS != 0) != full)
358-
Write(W_FS, sp, 0, full, 0, 0, 0);
358+
Write(W_FS, sp, full, 0, 0, 0);
359359
}
360360
}

games/sail/dr_4.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* $NetBSD: dr_4.c,v 1.6 1997/10/13 21:03:37 christos Exp $ */
1+
/* $NetBSD: dr_4.c,v 1.7 1999/02/10 00:45:45 hubertf Exp $ */
22

33
/*
44
* Copyright (c) 1983, 1993
@@ -38,7 +38,7 @@
3838
#if 0
3939
static char sccsid[] = "@(#)dr_4.c 8.2 (Berkeley) 4/28/95";
4040
#else
41-
__RCSID("$NetBSD: dr_4.c,v 1.6 1997/10/13 21:03:37 christos Exp $");
41+
__RCSID("$NetBSD: dr_4.c,v 1.7 1999/02/10 00:45:45 hubertf Exp $");
4242
#endif
4343
#endif /* not lint */
4444

@@ -69,7 +69,7 @@ struct ship *from, *to;
6969
{
7070
if (capship(from)->nationality != capship(to)->nationality && die() > 2)
7171
return;
72-
Write(W_GRAP, from, 0, to->file->index, 0, 0, 0);
73-
Write(W_GRAP, to, 0, from->file->index, 0, 0, 0);
72+
Write(W_GRAP, from, to->file->index, 0, 0, 0);
73+
Write(W_GRAP, to, from->file->index, 0, 0, 0);
7474
makesignal(from, "grappled with $$", to);
7575
}

games/sail/dr_5.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* $NetBSD: dr_5.c,v 1.5 1997/10/13 19:43:47 christos Exp $ */
1+
/* $NetBSD: dr_5.c,v 1.6 1999/02/10 00:45:45 hubertf Exp $ */
22

33
/*
44
* Copyright (c) 1983, 1993
@@ -38,7 +38,7 @@
3838
#if 0
3939
static char sccsid[] = "@(#)dr_5.c 8.2 (Berkeley) 4/28/95";
4040
#else
41-
__RCSID("$NetBSD: dr_5.c,v 1.5 1997/10/13 19:43:47 christos Exp $");
41+
__RCSID("$NetBSD: dr_5.c,v 1.6 1999/02/10 00:45:45 hubertf Exp $");
4242
#endif
4343
#endif /* not lint */
4444

@@ -62,11 +62,11 @@ int totalfrom, crewfrom[3];
6262
totalfrom = 0;
6363
}
6464
}
65-
Write(W_CREW, from, 0, crewfrom[0], crewfrom[1], crewfrom[2], 0);
65+
Write(W_CREW, from, crewfrom[0], crewfrom[1], crewfrom[2], 0);
6666
} else if (totalfrom) {
6767
pcfrom -= totalfrom;
6868
pcfrom = pcfrom < 0 ? 0 : pcfrom;
69-
Write(W_PCREW, from, 0, pcfrom, 0, 0, 0);
69+
Write(W_PCREW, from, pcfrom, 0, 0, 0);
7070
}
7171
}
7272

games/sail/extern.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* $NetBSD: extern.h,v 1.8 1998/09/13 15:27:30 hubertf Exp $ */
1+
/* $NetBSD: extern.h,v 1.9 1999/02/10 00:45:45 hubertf Exp $ */
22

33
/*
44
* Copyright (c) 1983, 1993
@@ -435,6 +435,7 @@ void makemsg __P((struct ship *, const char *, ...))
435435
int sync_exists __P((int));
436436
int sync_open __P((void));
437437
void sync_close __P((int));
438-
void Write __P((int, struct ship *, int, long, long, long, long));
438+
void Write __P((int, struct ship *, long, long, long, long));
439+
void Writestr __P((int, struct ship *, const char *));
439440
int Sync __P((void));
440-
int sync_update __P((int, struct ship *, long, long, long, long));
441+
int sync_update __P((int, struct ship *, const char *, long, long, long, long));

games/sail/parties.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* $NetBSD: parties.c,v 1.5 1997/10/13 19:44:47 christos Exp $ */
1+
/* $NetBSD: parties.c,v 1.6 1999/02/10 00:45:46 hubertf Exp $ */
22

33
/*
44
* Copyright (c) 1983, 1993
@@ -38,7 +38,7 @@
3838
#if 0
3939
static char sccsid[] = "@(#)parties.c 8.2 (Berkeley) 4/28/95";
4040
#else
41-
__RCSID("$NetBSD: parties.c,v 1.5 1997/10/13 19:44:47 christos Exp $");
41+
__RCSID("$NetBSD: parties.c,v 1.6 1999/02/10 00:45:46 hubertf Exp $");
4242
#endif
4343
#endif /* not lint */
4444

@@ -82,5 +82,5 @@ char isdefense;
8282

8383
for (n = 0; n < NBP; p++, n++)
8484
if (p->turnsent && (p->toship == to || isdefense || ship == to))
85-
Write(isdefense ? W_DBP : W_OBP, ship, 0, n, 0, 0, 0);
85+
Write(isdefense ? W_DBP : W_OBP, ship, n, 0, 0, 0);
8686
}

games/sail/pl_1.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* $NetBSD: pl_1.c,v 1.5 1997/10/13 21:04:02 christos Exp $ */
1+
/* $NetBSD: pl_1.c,v 1.6 1999/02/10 00:45:46 hubertf Exp $ */
22

33
/*
44
* Copyright (c) 1983, 1993
@@ -38,7 +38,7 @@
3838
#if 0
3939
static char sccsid[] = "@(#)pl_1.c 8.1 (Berkeley) 5/31/93";
4040
#else
41-
__RCSID("$NetBSD: pl_1.c,v 1.5 1997/10/13 21:04:02 christos Exp $");
41+
__RCSID("$NetBSD: pl_1.c,v 1.6 1999/02/10 00:45:46 hubertf Exp $");
4242
#endif
4343
#endif /* not lint */
4444

@@ -109,7 +109,7 @@ int conditions;
109109
if (conditions != LEAVE_SYNC) {
110110
makemsg(ms, "Captain %s relinquishing.",
111111
mf->captain);
112-
Write(W_END, ms, 0, 0, 0, 0, 0);
112+
Write(W_END, ms, 0, 0, 0, 0);
113113
(void) Sync();
114114
}
115115
}

0 commit comments

Comments
 (0)