Subject: bin/6569: [PATCH] Sail pointer/integer casts
To: None <gnats-bugs@gnats.netbsd.org>
From: Joseph Myers <jsm28@cam.ac.uk>
List: netbsd-bugs
Date: 12/12/1998 21:59:22
>Number:         6569
>Category:       bin
>Synopsis:       [PATCH] Sail pointer/integer casts
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    bin-bug-people (Utility Bug People)
>State:          open
>Class:          change-request
>Submitter-Id:   net
>Arrival-Date:   Sat Dec 12 14:05:00 1998
>Last-Modified:
>Originator:     Joseph S. Myers
>Organization:
Trinity College, University of Cambridge, UK
>Release:        NetBSD-current of 1998-12-07
>Environment:
[
System: Linux decomino 2.0.36 #1 Mon Nov 16 14:25:34 UTC 1998 i686 unknown
Architecture: i686
]
>Description:

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.

>How-To-Repeat:

>Fix:

diff -ruN sail/assorted.c sail+/assorted.c
--- sail/assorted.c	Tue Oct 14 11:09:41 1997
+++ sail+/assorted.c	Sat Dec 12 21:44:27 1998
@@ -139,17 +139,17 @@
 	hull -= ghits;
 	if (Ghit)
 		Write(portside(from, on, 0) ? W_GUNR : W_GUNL,
-			on, 0, guns, car, 0, 0);
+			on, guns, car, 0, 0);
 	hull -= hhits;
 	hull = hull < 0 ? 0 : hull;
 	if (on->file->captured != 0 && Chit)
-		Write(W_PCREW, on, 0, pc, 0, 0, 0);
+		Write(W_PCREW, on, pc, 0, 0, 0);
 	if (Hhit)
-		Write(W_HULL, on, 0, hull, 0, 0, 0);
+		Write(W_HULL, on, hull, 0, 0, 0);
 	if (Chit)
-		Write(W_CREW, on, 0, crew[0], crew[1], crew[2], 0);
+		Write(W_CREW, on, crew[0], crew[1], crew[2], 0);
 	if (Rhit)
-		Write(W_RIGG, on, 0, rigg[0], rigg[1], rigg[2], rigg[3]);
+		Write(W_RIGG, on, rigg[0], rigg[1], rigg[2], rigg[3]);
 	switch (shot) {
 	case L_ROUND:
 		message = "firing round shot on $$";
@@ -217,7 +217,7 @@
 			break;
 		case 5:
 			message = "rudder cables shot through";
-			Write(W_TA, on, 0, 0, 0, 0, 0);
+			Write(W_TA, on, 0, 0, 0, 0);
 			break;
 		case 6:
 			message = "shot holes below the water line";
@@ -233,10 +233,10 @@
 		if (on->specs->qual <= 0) {
 			makemsg(on, "crew mutinying!");
 			on->specs->qual = 5;
-			Write(W_CAPTURED, on, 0, on->file->index, 0, 0, 0);
+			Write(W_CAPTURED, on, on->file->index, 0, 0, 0);
 		} else 
 			makemsg(on, "crew demoralized");
-		Write(W_QUAL, on, 0, on->specs->qual, 0, 0, 0);
+		Write(W_QUAL, on, on->specs->qual, 0, 0, 0);
 	}
 	*/
 	if (!hull)
@@ -249,12 +249,12 @@
 char all, flag;
 {
 	if (flag & 1) {
-		Write(W_UNGRAP, from, 0, to->file->index, all, 0, 0);
-		Write(W_UNGRAP, to, 0, from->file->index, all, 0, 0);
+		Write(W_UNGRAP, from, to->file->index, all, 0, 0);
+		Write(W_UNGRAP, to, from->file->index, all, 0, 0);
 	}
 	if (flag & 2) {
-		Write(W_UNFOUL, from, 0, to->file->index, all, 0, 0);
-		Write(W_UNFOUL, to, 0, from->file->index, all, 0, 0);
+		Write(W_UNFOUL, from, to->file->index, all, 0, 0);
+		Write(W_UNFOUL, to, from->file->index, all, 0, 0);
 	}
 	if (!snagged2(from, to)) {
 		if (!snagged(from)) {
@@ -278,20 +278,20 @@
 
 	if (ship->file->struck)
 		return;
-	Write(W_STRUCK, ship, 0, 1, 0, 0, 0);
+	Write(W_STRUCK, ship, 1, 0, 0, 0);
 	points = ship->specs->pts + from->file->points;
-	Write(W_POINTS, from, 0, points, 0, 0, 0);
+	Write(W_POINTS, from, points, 0, 0, 0);
 	unboard(ship, ship, 0);		/* all offense */
 	unboard(ship, ship, 1);		/* all defense */
 	switch (die()) {
 	case 3:
 	case 4:		/* ship may sink */
-		Write(W_SINK, ship, 0, 1, 0, 0, 0);
+		Write(W_SINK, ship, 1, 0, 0, 0);
 		break;
 	case 5:
 	case 6:		/* ship may explode */
-		Write(W_EXPLODE, ship, 0, 1, 0, 0, 0);
+		Write(W_EXPLODE, ship, 1, 0, 0, 0);
 		break;
 	}
-	Write(W_SIGNAL, ship, 1, (int) "striking her colours!", 0, 0, 0);
+	Writestr(W_SIGNAL, ship, "striking her colours!");
 }
diff -ruN sail/dr_1.c sail+/dr_1.c
--- sail/dr_1.c	Sun Aug 30 11:05:21 1998
+++ sail+/dr_1.c	Sat Dec 12 21:44:27 1998
@@ -192,7 +192,7 @@
 		makemsg(from, "boarders from %s repelled", to->shipname);
 		(void) sprintf(message, "killed in melee: %d.  %s: %d",
 			totalto, from->shipname, totalfrom);
-		Write(W_SIGNAL, to, 1, (long) message, 0, 0, 0);
+		Writestr(W_SIGNAL, to, message);
 		if (key)
 			return 1;
 	} else if (strengthto >= fromstrength * 3) {
@@ -201,7 +201,7 @@
 		subtract(to, totalto, crewto, tocap, pcto);
 		if (key) {
 			if (fromcap != from)
-				Write(W_POINTS, fromcap, 0,
+				Write(W_POINTS, fromcap,
 					fromcap->file->points -
 						from->file->struck
 						? from->specs->pts
@@ -212,11 +212,11 @@
    I guess that what is going on here is that the pointer is multiplied
    or something. */
 
-			Write(W_CAPTURED, from, 0, to->file->index, 0, 0, 0);
+			Write(W_CAPTURED, from, to->file->index, 0, 0, 0);
 			topoints = 2 * from->specs->pts + to->file->points;
 			if (from->file->struck)
 				topoints -= from->specs->pts;
-			Write(W_POINTS, to, 0, topoints, 0, 0, 0);
+			Write(W_POINTS, to, topoints, 0, 0, 0);
 			mento = crewto[0] ? crewto[0] : crewto[1];
 			if (mento) {
 				subtract(to, mento, crewto, tocap, pcto);
@@ -224,10 +224,10 @@
 			}
 			(void) sprintf(message, "captured by the %s!",
 				to->shipname);
-			Write(W_SIGNAL, from, 1, (long) message, 0, 0, 0);
+			Writestr(W_SIGNAL, from, message);
 			(void) sprintf(message, "killed in melee: %d.  %s: %d",
 				totalto, from->shipname, totalfrom);
-			Write(W_SIGNAL, to, 1, (long) message, 0, 0, 0);
+			Writestr(W_SIGNAL, to, message);
 			mento = 0;
 			return 0;
 		}
@@ -434,7 +434,7 @@
 		}
 		return -1;
 	}
-	Write(W_TURN, SHIP(0), 0, turn, 0, 0, 0);
+	Write(W_TURN, SHIP(0), turn, 0, 0, 0);
 	if (turn % 7 == 0 && (die() >= cc->windchange || !windspeed)) {
 		switch (die()) {
 		case 1:
@@ -472,7 +472,7 @@
 			}
 		else
 			windspeed++;
-		Write(W_WIND, SHIP(0), 0, winddir, windspeed, 0, 0);
+		Write(W_WIND, SHIP(0), winddir, windspeed, 0, 0);
 	}
 	return 0;
 }
diff -ruN sail/dr_2.c sail+/dr_2.c
--- sail/dr_2.c	Sat Sep 12 11:04:49 1998
+++ sail+/dr_2.c	Sat Dec 12 21:44:27 1998
@@ -93,8 +93,8 @@
 			continue;
 		if (die() < 5)
 			continue;
-		Write(sink == 1 ? W_SINK : W_EXPLODE, sp, 0, 2, 0, 0, 0);
-		Write(W_DIR, sp, 0, 0, 0, 0, 0);
+		Write(sink == 1 ? W_SINK : W_EXPLODE, sp, 2, 0, 0, 0);
+		Write(W_DIR, sp, 0, 0, 0, 0);
 		if (snagged(sp))
 			foreachship(sq)
 				cleansnag(sp, sq, 1);
@@ -120,10 +120,9 @@
 		if (sp->file->struck || sp->file->dir == 0)
 			continue;
 		if (sp->specs->crew1 + sp->specs->crew2 + sp->specs->crew3 > sp->file->pcrew * 6) {
-			Write(W_SIGNAL, sp, 1,
-				(long)"prize crew overthrown", 0, 0, 0);
-			Write(W_POINTS, sp->file->captured, 0, sp->file->captured->file->points - 2 * sp->specs->pts, 0, 0, 0);
-			Write(W_CAPTURED, sp, 0, -1, 0, 0, 0);
+			Writestr(W_SIGNAL, sp, "prize crew overthrown");
+			Write(W_POINTS, sp->file->captured, sp->file->captured->file->points - 2 * sp->specs->pts, 0, 0, 0);
+			Write(W_CAPTURED, sp, -1, 0, 0, 0);
 		}
 	}
 }
diff -ruN sail/dr_3.c sail+/dr_3.c
--- sail/dr_3.c	Tue Oct 14 11:09:41 1997
+++ sail+/dr_3.c	Sat Dec 12 21:44:27 1998
@@ -138,8 +138,8 @@
 					if (die() < 4) {
 						makesignal(sp, "fouled with $$",
 						    sq);
-						Write(W_FOUL, sp, 0, l, 0, 0, 0);
-						Write(W_FOUL, sq, 0, n, 0, 0, 0);
+						Write(W_FOUL, sp, l, 0, 0, 0);
+						Write(W_FOUL, sq, n, 0, 0, 0);
 					}
 					snap++;
 				}
@@ -170,13 +170,13 @@
 		if (sp->file->dir != 0) {
 			*sp->file->movebuf = 0;
 			if (row[n] != sp->file->row)
-				Write(W_ROW, sp, 0, sp->file->row, 0, 0, 0);
+				Write(W_ROW, sp, sp->file->row, 0, 0, 0);
 			if (col[n] != sp->file->col)
-				Write(W_COL, sp, 0, sp->file->col, 0, 0, 0);
+				Write(W_COL, sp, sp->file->col, 0, 0, 0);
 			if (dir[n] != sp->file->dir)
-				Write(W_DIR, sp, 0, sp->file->dir, 0, 0, 0);
+				Write(W_DIR, sp, sp->file->dir, 0, 0, 0);
 			if (drift[n] != sp->file->drift)
-				Write(W_DRIFT, sp, 0, sp->file->drift, 0, 0, 0);
+				Write(W_DRIFT, sp, sp->file->drift, 0, 0, 0);
 		}
 		n++;
 	}
@@ -278,7 +278,7 @@
 	for (n = 0; n < NBP && bp[n].turnsent; n++)
 		;
 	if (n < NBP && sections) {
-		Write(isdefense ? W_DBP : W_OBP, from, 0,
+		Write(isdefense ? W_DBP : W_OBP, from,
 			n, turn, to->file->index, sections);
 		if (isdefense)
 			makemsg(from, "repelling boarders");
@@ -355,6 +355,6 @@
 		} else
 			full = 0;
 		if ((sp->file->FS != 0) != full)
-			Write(W_FS, sp, 0, full, 0, 0, 0);
+			Write(W_FS, sp, full, 0, 0, 0);
 	}
 }
diff -ruN sail/dr_4.c sail+/dr_4.c
--- sail/dr_4.c	Tue Oct 14 11:09:42 1997
+++ sail+/dr_4.c	Sat Dec 12 21:44:27 1998
@@ -69,7 +69,7 @@
 {
 	if (capship(from)->nationality != capship(to)->nationality && die() > 2)
 		return;
-	Write(W_GRAP, from, 0, to->file->index, 0, 0, 0);
-	Write(W_GRAP, to, 0, from->file->index, 0, 0, 0);
+	Write(W_GRAP, from, to->file->index, 0, 0, 0);
+	Write(W_GRAP, to, from->file->index, 0, 0, 0);
 	makesignal(from, "grappled with $$", to);
 }
diff -ruN sail/dr_5.c sail+/dr_5.c
--- sail/dr_5.c	Tue Oct 14 11:09:42 1997
+++ sail+/dr_5.c	Sat Dec 12 21:44:27 1998
@@ -62,11 +62,11 @@
 				totalfrom = 0;
 			}
 		}
-		Write(W_CREW, from, 0, crewfrom[0], crewfrom[1], crewfrom[2], 0);
+		Write(W_CREW, from, crewfrom[0], crewfrom[1], crewfrom[2], 0);
 	} else if (totalfrom) {
 		pcfrom -= totalfrom;
 		pcfrom = pcfrom < 0 ? 0 : pcfrom;
-		Write(W_PCREW, from, 0, pcfrom, 0, 0, 0);
+		Write(W_PCREW, from, pcfrom, 0, 0, 0);
 	}
 }
 
diff -ruN sail/extern.h sail+/extern.h
--- sail/extern.h	Mon Sep 14 11:05:04 1998
+++ sail+/extern.h	Sat Dec 12 21:44:27 1998
@@ -435,6 +435,7 @@
 int sync_exists __P((int));
 int sync_open __P((void));
 void sync_close __P((int));
-void Write __P((int, struct ship *, int, long, long, long, long));
+void Write __P((int, struct ship *, long, long, long, long));
+void Writestr __P((int, struct ship *, const char *));
 int Sync __P((void));
-int sync_update __P((int, struct ship *, long, long, long, long));
+int sync_update __P((int, struct ship *, const char *, long, long, long, long));
diff -ruN sail/parties.c sail+/parties.c
--- sail/parties.c	Tue Oct 14 11:09:44 1997
+++ sail+/parties.c	Sat Dec 12 21:44:27 1998
@@ -82,5 +82,5 @@
 
 	for (n = 0; n < NBP; p++, n++)
 		if (p->turnsent && (p->toship == to || isdefense || ship == to))
-			Write(isdefense ? W_DBP : W_OBP, ship, 0, n, 0, 0, 0);
+			Write(isdefense ? W_DBP : W_OBP, ship, n, 0, 0, 0);
 }
diff -ruN sail/pl_1.c sail+/pl_1.c
--- sail/pl_1.c	Tue Oct 14 11:09:44 1997
+++ sail+/pl_1.c	Sat Dec 12 21:44:27 1998
@@ -109,7 +109,7 @@
 		if (conditions != LEAVE_SYNC) {
 			makemsg(ms, "Captain %s relinquishing.",
 				mf->captain);
-			Write(W_END, ms, 0, 0, 0, 0, 0);
+			Write(W_END, ms, 0, 0, 0, 0);
 			(void) Sync();
 		}
 	}
diff -ruN sail/pl_3.c sail+/pl_3.c
--- sail/pl_3.c	Sun Aug 30 11:05:21 1998
+++ sail+/pl_3.c	Sat Dec 12 21:44:27 1998
@@ -234,8 +234,8 @@
 		case 'g':
 			if (die() < 3
 			    || ms->nationality == capship(sp)->nationality) {
-				Write(W_GRAP, ms, 0, sp->file->index, 0, 0, 0);
-				Write(W_GRAP, sp, 0, player, 0, 0, 0);
+				Write(W_GRAP, ms, sp->file->index, 0, 0, 0);
+				Write(W_GRAP, sp, player, 0, 0, 0);
 				Msg("Attempt succeeds!");
 				makesignal(ms, "grappled with $$", sp);
 			} else
diff -ruN sail/pl_4.c sail+/pl_4.c
--- sail/pl_4.c	Tue Oct 14 11:09:45 1997
+++ sail+/pl_4.c	Sat Dec 12 21:44:27 1998
@@ -58,12 +58,12 @@
 			if (sgetch("Increase to Full sails? ",
 				(struct ship *)0, 1) == 'y') {
 				changed = 1;
-				Write(W_FS, ms, 0, 1, 0, 0, 0);
+				Write(W_FS, ms, 1, 0, 0, 0);
 			}
 		} else {
 			if (sgetch("Reduce to Battle sails? ",
 				(struct ship *)0, 1) == 'y') {
-				Write(W_FS, ms, 0, 0, 0, 0, 0);
+				Write(W_FS, ms, 0, 0, 0, 0);
 				changed = 1;
 			}
 		}
@@ -83,7 +83,7 @@
 		;
 	p[-1] = '"';
 	*p = 0;
-	Write(W_SIGNAL, ms, 1, (long)buf, 0, 0, 0);
+	Writestr(W_SIGNAL, ms, buf);
 }
 
 void
diff -ruN sail/pl_5.c sail+/pl_5.c
--- sail/pl_5.c	Tue Oct 14 11:09:46 1997
+++ sail+/pl_5.c	Sat Dec 12 21:44:27 1998
@@ -127,7 +127,7 @@
 		Msg("Movement error.");
 		if (ta < 0 && moved) {
 			if (mf->FS == 1) {
-				Write(W_FS, ms, 0, 0, 0, 0, 0);
+				Write(W_FS, ms, 0, 0, 0, 0);
 				Msg("No hands to set full sails.");
 			}
 		} else if (ma >= 0)
@@ -135,7 +135,7 @@
 	}
 	if (af && !moved) {
 		if (mf->FS == 1) {
-			Write(W_FS, ms, 0, 0, 0, 0, 0);
+			Write(W_FS, ms, 0, 0, 0, 0);
 			Msg("No hands to set full sails.");
 		}
 	}
@@ -143,7 +143,7 @@
 		(void) strcpy(movebuf, buf);
 	else
 		(void) strcpy(movebuf, "d");
-	Write(W_MOVE, ms, 1, (long)movebuf, 0, 0, 0);
+	Writestr(W_MOVE, ms, movebuf);
 	Msg("Helm: %s.", movebuf);
 }
 
@@ -228,7 +228,7 @@
 			}
 			if (buf > '0')
 				Msg("Sending all crew sections.");
-			Write(isdefense ? W_DBP : W_OBP, ms, 0,
+			Write(isdefense ? W_DBP : W_OBP, ms,
 				j, turn, to->file->index, men);
 			if (isdefense) {
 				(void) wmove(slot_w, 2, 0);
diff -ruN sail/pl_6.c sail+/pl_6.c
--- sail/pl_6.c	Tue Oct 14 11:09:46 1997
+++ sail+/pl_6.c	Sat Dec 12 21:44:27 1998
@@ -81,7 +81,7 @@
 			int max = ptr->guns/4;
 			if (ptr->hull < max) {
 				FIX(hull, max);
-				Write(W_HULL, ms, 0, ptr->hull, 0, 0, 0);
+				Write(W_HULL, ms, ptr->hull, 0, 0, 0);
 			}
 			break;
 			}
@@ -90,14 +90,14 @@
 				int max = ptr->guns/5 - ptr->carL;
 				if (ptr->gunL < max) {
 					FIX(gunL, max);
-					Write(W_GUNL, ms, 0, ptr->gunL,
+					Write(W_GUNL, ms, ptr->gunL,
 						ptr->carL, 0, 0);
 				}
 			} else {
 				int max = ptr->guns/5 - ptr->carR;
 				if (ptr->gunR < max) {
 					FIX(gunR, max);
-					Write(W_GUNR, ms, 0, ptr->gunR,
+					Write(W_GUNR, ms, ptr->gunR,
 						ptr->carR, 0, 0);
 				}
 			}
@@ -106,19 +106,19 @@
 #define X 2
 			if (ptr->rig4 >= 0 && ptr->rig4 < X) {
 				FIX(rig4, X);
-				Write(W_RIG4, ms, 0, ptr->rig4, 0, 0, 0);
+				Write(W_RIG4, ms, ptr->rig4, 0, 0, 0);
 			}
 			if (count && ptr->rig3 < X) {
 				FIX(rig3, X);
-				Write(W_RIG3, ms, 0, ptr->rig3, 0, 0, 0);
+				Write(W_RIG3, ms, ptr->rig3, 0, 0, 0);
 			}
 			if (count && ptr->rig2 < X) {
 				FIX(rig2, X);
-				Write(W_RIG2, ms, 0, ptr->rig2, 0, 0, 0);
+				Write(W_RIG2, ms, ptr->rig2, 0, 0, 0);
 			}
 			if (count && ptr->rig1 < X) {
 				FIX(rig1, X);
-				Write(W_RIG1, ms, 0, ptr->rig1, 0, 0, 0);
+				Write(W_RIG1, ms, ptr->rig1, 0, 0, 0);
 			}
 			break;
 		}
diff -ruN sail/pl_7.c sail+/pl_7.c
--- sail/pl_7.c	Sun Aug 30 11:05:21 1998
+++ sail+/pl_7.c	Sat Dec 12 21:44:27 1998
@@ -113,7 +113,7 @@
 			mf->readyR = R_LOADED;
 	}
 	if (!hasdriver)
-		Write(W_DDEAD, SHIP(0), 0, 0, 0, 0, 0);
+		Write(W_DDEAD, SHIP(0), 0, 0, 0, 0);
 
 	if (sc_hasprompt) {
 		(void) wmove(scroll_w, sc_line, 0);
@@ -127,11 +127,11 @@
 		(void) wprintw(scroll_w, "%s%s", sc_prompt, sc_buf);
 
 	if (turn % 50 == 0)
-		Write(W_ALIVE, SHIP(0), 0, 0, 0, 0, 0);
+		Write(W_ALIVE, SHIP(0), 0, 0, 0, 0);
 	if (mf->FS && (!mc->rig1 || windspeed == 6))
-		Write(W_FS, ms, 0, 0, 0, 0, 0);
+		Write(W_FS, ms, 0, 0, 0, 0);
 	if (mf->FS == 1)
-		Write(W_FS, ms, 0, 2, 0, 0, 0);
+		Write(W_FS, ms, 2, 0, 0, 0);
 
 	if (mf->struck)
 		leave(LEAVE_QUIT);
diff -ruN sail/pl_main.c sail+/pl_main.c
--- sail/pl_main.c	Tue Oct 14 11:09:47 1997
+++ sail+/pl_main.c	Sat Dec 12 21:44:27 1998
@@ -181,7 +181,7 @@
 	mf = ms->file;
 	mc = ms->specs;
 
-	Write(W_BEGIN, ms, 0, 0, 0, 0, 0);
+	Write(W_BEGIN, ms, 0, 0, 0, 0);
 	if (Sync() < 0)
 		leave(LEAVE_SYNC);
 
@@ -214,7 +214,7 @@
 		    captain[strlen(captain) - 1] = '\0';
 	}
 	captain[sizeof captain - 1] = '\0';
-	Write(W_CAPTAIN, ms, 1, (long)captain, 0, 0, 0);
+	Writestr(W_CAPTAIN, ms, captain);
 	for (n = 0; n < 2; n++) {
 		char buf[10];
 
@@ -249,7 +249,8 @@
 
 	initscreen();
 	draw_board();
-	(void) sprintf(message, "Captain %s assuming command", captain);
-	Write(W_SIGNAL, ms, 1, (long)message, 0, 0, 0);
+	(void) snprintf(message, sizeof message, "Captain %s assuming command",
+			captain);
+	Writestr(W_SIGNAL, ms, message);
 	newturn(0);
 }
diff -ruN sail/sync.c sail+/sync.c
--- sail/sync.c	Sat Sep 12 11:04:50 1998
+++ sail+/sync.c	Sat Dec 12 21:46:45 1998
@@ -121,7 +121,7 @@
 	fmtship(format, sizeof(format), fmt, ship);
 	(void) vsprintf(message, format, ap);
 	va_end(ap);
-	Write(W_SIGNAL, from, 1, (long)message, 0, 0, 0);
+	Writestr(W_SIGNAL, from, message);
 }
 
 void
@@ -146,8 +146,9 @@
 #endif
 	(void) vsprintf(message, fmt, ap);
 	va_end(ap);
-	Write(W_SIGNAL, from, 1, (long)message, 0, 0, 0);
+	Writestr(W_SIGNAL, from, message);
 }
+
 int
 sync_exists(game)
 	int game;
@@ -199,25 +200,37 @@
 }
 
 void
-Write(type, ship, isstr, a, b, c, d)
+Write(type, ship, a, b, c, d)
 	int type;
 	struct ship *ship;
-	int isstr;
 	long a, b, c, d;
 {
 
-	if (isstr)
-		(void) sprintf(sync_bp, "%d %d %d %s\n",
-			type, ship->file->index, isstr, (char *) a);
-	else
-		(void) sprintf(sync_bp, "%d %d %d %ld %ld %ld %ld\n",
-			type, ship->file->index, isstr, a, b, c, d);
+	(void) sprintf(sync_bp, "%d %d 0 %ld %ld %ld %ld\n",
+		       type, ship->file->index, a, b, c, d);
+	while (*sync_bp++)
+		;
+	sync_bp--;
+	if (sync_bp >= &sync_buf[sizeof sync_buf])
+		abort();
+	(void) sync_update(type, ship, NULL, a, b, c, d);
+}
+
+void
+Writestr(type, ship, a)
+	int type;
+	struct ship *ship;
+	const char *a;
+{
+
+	(void) sprintf(sync_bp, "%d %d 1 %s\n",
+		       type, ship->file->index, a);
 	while (*sync_bp++)
 		;
 	sync_bp--;
 	if (sync_bp >= &sync_buf[sizeof sync_buf])
 		abort();
-	(void) sync_update(type, ship, a, b, c, d);
+	(void) sync_update(type, ship, a, 0, 0, 0, 0);
 }
 
 int
@@ -226,6 +239,7 @@
 	sig_t sighup, sigint;
 	int n;
 	int type, shipnum, isstr;
+	char *astr;
 	long a, b, c, d;
 	char buf[80];
 	char erred = 0;
@@ -280,19 +294,21 @@
 			*p = 0;
 			for (p = buf; *p == ' '; p++)
 				;
-			a = (long)p;
-			b = c = d = 0;
-		} else
+			astr = p;
+			a = b = c = d = 0;
+		} else {
 			if (fscanf(sync_fp, "%ld%ld%ld%ld", &a, &b, &c, &d) != 4)
 				goto bad;
-		if (sync_update(type, SHIP(shipnum), a, b, c, d) < 0)
+			astr = NULL;
+		}
+		if (sync_update(type, SHIP(shipnum), astr, a, b, c, d) < 0)
 			goto bad;
 	}
 bad:
 	erred++;
 out:
 	if (!erred && sync_bp != sync_buf) {
-		(void) fseek(sync_fp, 0L, 2);
+		(void) fseek(sync_fp, 0L, SEEK_END);
 		(void) fwrite(sync_buf, sizeof *sync_buf, sync_bp - sync_buf,
 			sync_fp);
 		(void) fflush(sync_fp);
@@ -310,9 +326,10 @@
 }
 
 int
-sync_update(type, ship, a, b, c, d)
+sync_update(type, ship, astr, a, b, c, d)
 	int type;
 	struct ship *ship;
+	const char *astr;
 	long a, b, c, d;
 {
 	switch (type) {
@@ -377,9 +394,9 @@
 	case W_SIGNAL:
 		if (mode == MODE_PLAYER) {
 			if (nobells)
-				Signal("$$: %s", ship, (char *) a);
+				Signal("$$: %s", ship, astr);
 			else
-				Signal("\7$$: %s", ship, (char *) a);
+				Signal("\7$$: %s", ship, astr);
 		}
 		break;
 	case W_CREW: {
@@ -390,7 +407,7 @@
 		break;
 		}
 	case W_CAPTAIN:
-		(void) strncpy(ship->file->captain, (char *)a,
+		(void) strncpy(ship->file->captain, astr,
 			sizeof ship->file->captain - 1);
 		ship->file->captain[sizeof ship->file->captain - 1] = 0;
 		break;
@@ -429,7 +446,7 @@
 		ship->specs->hull = a;
 		break;
 	case W_MOVE:
-		(void) strncpy(ship->file->movebuf, (char *)a,
+		(void) strncpy(ship->file->movebuf, astr,
 			sizeof ship->file->movebuf - 1);
 		ship->file->movebuf[sizeof ship->file->movebuf - 1] = 0;
 		break;
>Audit-Trail:
>Unformatted: