$OpenBSD$
--- misc.c.orig	Mon Feb 14 19:11:51 2011
+++ misc.c	Mon Feb 14 19:30:55 2011
@@ -28,6 +28,8 @@
 #include "xgammon.h"
 #include "gammon.h"
 
+#define LINESIZ	512
+
 extern Cursor	     gammon_cursor;
 extern XColor	     fg_col, bg_col; /* gammon_cursor colors */
 
@@ -114,7 +116,7 @@ void RollDice (void)
 		pash = 1;
 	}
 
-	sprintf (add_text, "%s rolls %d and %d.\n", Player[turn-1].name, abs (roll[0]), abs (roll[1]));
+	snprintf (add_text, LINESIZ, "%s rolls %d and %d.\n", Player[turn-1].name, abs (roll[0]), abs (roll[1]));
 
 	AppendDialogText (LOWER, add_text);
 }
@@ -244,10 +246,10 @@ void init_game (void)
 		doubler.owner = 0;
 
 		tournament.game_number++;
-		if      (Player[0].type == HUMAN    && Player[1].type == HUMAN)    sprintf (add_text,"Starting a new game with  %s, ", Player[0].name);
-		else if (Player[0].type == COMPUTER && Player[1].type == COMPUTER) sprintf (add_text,"Starting a new game with xgammon (0)\n");
-		else if (Player[0].type == HUMAN)  sprintf (add_text,"Starting a new game with %s\n", Player[0].name);
-		else 				   sprintf (add_text,"Starting a new game with %s\n", Player[1].name);
+		if      (Player[0].type == HUMAN    && Player[1].type == HUMAN)    snprintf (add_text, LINESIZ, "Starting a new game with  %s, ", Player[0].name);
+		else if (Player[0].type == COMPUTER && Player[1].type == COMPUTER) snprintf (add_text, LINESIZ, "Starting a new game with xgammon (0)\n");
+		else if (Player[0].type == HUMAN)  snprintf (add_text, LINESIZ, "Starting a new game with %s\n", Player[0].name);
+		else 				   snprintf (add_text, LINESIZ, "Starting a new game with %s\n", Player[1].name);
 		AppendDialogText (LOWER, add_text);
 
 
@@ -285,10 +287,10 @@ void init_game (void)
 		DrawDoubler (doubler.value, doubler.owner);
 
 
-		sprintf (add_text, "%s rolled %d, %s rolled %d\n", Player[0].name, abs (roll[0]), Player[1].name, abs (roll[1]));
+		snprintf (add_text, LINESIZ, "%s rolled %d, %s rolled %d\n", Player[0].name, abs (roll[0]), Player[1].name, abs (roll[1]));
 		AppendDialogText (LOWER, add_text);
-		if (roll[0] < 0) sprintf (add_text, "%s makes the first move.\n",   Player[1].name);
-		else		 sprintf (add_text, "%s makes the first move.\n\n", Player[0].name);
+		if (roll[0] < 0) snprintf (add_text, LINESIZ, "%s makes the first move.\n",   Player[1].name);
+		else		 snprintf (add_text, LINESIZ, "%s makes the first move.\n\n", Player[0].name);
 		AppendDialogText (LOWER, add_text);
 		DrawDice (turn);
 
@@ -306,20 +308,20 @@ void AppendMoveString (MOVE *m)
 	int  i;
 
 	if (!m || !(m->from || m->to)) {
-		sprintf (add_text, "%s can't move.\n\n", Player[turn-1].name);
+		snprintf (add_text, LINESIZ, "%s can't move.\n\n", Player[turn-1].name);
 	} else {
-		sprintf (add_text, "%s moves ", Player[turn-1].name);
+		snprintf (add_text, LINESIZ, "%s moves ", Player[turn-1].name);
 
 		for (i=0; i<to_move; i++) {
-			if ((m+i)->from != BAR) sprintf (f,"%d-", (m+i)->from);
-			else strcpy (f,"bar-");
-		        strcat  (add_text, f);
+			if ((m+i)->from != BAR) snprintf (f, 5, "%d-", (m+i)->from);
+			else strlcpy (f,"bar-", 5);
+		        strlcat  (add_text, f, LINESIZ);
 
-			if ((m+i)->to != end_pin) sprintf (t,"%d ", (m+i)->to);
-			else strcpy (t,"off ");
-		        strcat  (add_text, t);
+			if ((m+i)->to != end_pin) snprintf (t, 5, "%d ", (m+i)->to);
+			else strlcpy (t,"off ", 5);
+		        strlcat  (add_text, t, LINESIZ);
 		}
-		strcat (add_text, ".\n\n");
+		strlcat (add_text, ".\n\n", LINESIZ);
 	}
 
 	AppendDialogText (LOWER, add_text);
@@ -419,19 +421,19 @@ void AddResult (int whom)
 	case BACKGAMMON:  gammon_str = "backgammon";	break;
 	}
 
-	sprintf (add_text, "%s wins the %d. game %s and gets %d points.\n", Player[whom-1].name, tournament.game_number, gammon_str, doubler.value);
+	snprintf (add_text, LINESIZ, "%s wins the %d. game %s and gets %d points.\n", Player[whom-1].name, tournament.game_number, gammon_str, doubler.value);
 	AppendDialogText (UPPER, add_text);
-	sprintf (add_text, "%s wins the game %s and gets %d points.\n", Player[whom-1].name, gammon_str, doubler.value);
+	snprintf (add_text, LINESIZ, "%s wins the game %s and gets %d points.\n", Player[whom-1].name, gammon_str, doubler.value);
 	AppendDialogText (LOWER, add_text);
 
-	if      (gammon_resource.moneygame) sprintf (add_text, "score in moneygame match: %s-%d %s-%d\n\n",			     Player[0].name, Player[0].points, Player[1].name, Player[1].points);
-	else if (gammon_resource.winat)     sprintf (add_text, "score in %d point match: %s-%d %s-%d\n\n",  tournament.winning_point, Player[0].name, Player[0].points, Player[1].name, Player[1].points);
+	if      (gammon_resource.moneygame) snprintf (add_text, LINESIZ, "score in moneygame match: %s-%d %s-%d\n\n",			     Player[0].name, Player[0].points, Player[1].name, Player[1].points);
+	else if (gammon_resource.winat)     snprintf (add_text, LINESIZ, "score in %d point match: %s-%d %s-%d\n\n",  tournament.winning_point, Player[0].name, Player[0].points, Player[1].name, Player[1].points);
 	AppendDialogText (LOWER, add_text);
 	AppendDialogText (UPPER, add_text);
 
 	if      (gammon_resource.moneygame) return;
 	else if (gammon_resource.winat && Player[whom-1].points >= tournament.winning_point)
-		sprintf (add_text, "%s wins the %d point match %d-%d .\n\n", Player[whom-1].name, tournament.winning_point, Player[0].points, Player[1].points);
+		snprintf (add_text, LINESIZ, "%s wins the %d point match %d-%d .\n\n", Player[whom-1].name, tournament.winning_point, Player[0].points, Player[1].points);
 
 	AppendDialogText (LOWER, add_text);
 	AppendDialogText (UPPER, add_text);
@@ -726,7 +728,7 @@ void open_protokol (void)
 {
 	if (gammon_resource.protokol) {
 		if (protokol_file) return; /* already open */
-		sprintf (protokol_file_name,"xgammon.protokol.%d", getpid ());
+		snprintf (protokol_file_name, 50, "xgammon.protokol.%d", getpid ());
 		protokol_file = fopen (protokol_file_name, "w");
 	}
 }
