summaryrefslogtreecommitdiffstats
path: root/sail/dr_2.c
diff options
context:
space:
mode:
authordholland <dholland@NetBSD.org>2009-03-14 18:32:47 +0000
committerdholland <dholland@NetBSD.org>2009-03-14 18:32:47 +0000
commit46cbf84f76cfe8fb29ae3f5a16b5302a687c9691 (patch)
tree1953b1d7a506556d3ce5202928b342822c89d9e4 /sail/dr_2.c
parent8e56f6b8823a74c576682b4191df9d6182d0001d (diff)
downloadbsdgames-darwin-46cbf84f76cfe8fb29ae3f5a16b5302a687c9691.tar.gz
bsdgames-darwin-46cbf84f76cfe8fb29ae3f5a16b5302a687c9691.tar.zst
bsdgames-darwin-46cbf84f76cfe8fb29ae3f5a16b5302a687c9691.zip
String buffer cleanup. sprintf bad.
Diffstat (limited to 'sail/dr_2.c')
-rw-r--r--sail/dr_2.c44
1 files changed, 22 insertions, 22 deletions
diff --git a/sail/dr_2.c b/sail/dr_2.c
index e082a72b..bbf145c0 100644
--- a/sail/dr_2.c
+++ b/sail/dr_2.c
@@ -1,4 +1,4 @@
-/* $NetBSD: dr_2.c,v 1.21 2009/03/14 17:10:01 dholland Exp $ */
+/* $NetBSD: dr_2.c,v 1.22 2009/03/14 18:32:47 dholland Exp $ */
/*
* Copyright (c) 1983, 1993
@@ -34,7 +34,7 @@
#if 0
static char sccsid[] = "@(#)dr_2.c 8.1 (Berkeley) 5/31/93";
#else
-__RCSID("$NetBSD: dr_2.c,v 1.21 2009/03/14 17:10:01 dholland Exp $");
+__RCSID("$NetBSD: dr_2.c,v 1.22 2009/03/14 18:32:47 dholland Exp $");
#endif
#endif /* not lint */
@@ -48,9 +48,9 @@ __RCSID("$NetBSD: dr_2.c,v 1.21 2009/03/14 17:10:01 dholland Exp $");
#define couldwin(f,t) (f->specs->crew2 > t->specs->crew2 * 1.5)
static int str_end(const char *);
-static int score(struct ship *, struct ship *, char *, int);
+static int score(struct ship *, struct ship *, char *, size_t, int);
static void move_ship(struct ship *, const char *, unsigned char *, short *, short *, int *);
-static void try(struct ship *, struct ship *, char *, char *, int, int, int, int, int, int *, int);
+static void try(struct ship *f, struct ship *t, char *command, size_t commandmax, char *temp, size_t tempmax, int ma, int ta, int af, int vma, int dir, int *high, int rakeme);
static void rmend(char *);
const int dtab[] = {0,1,1,2,3,4,4,5}; /* diagonal distances in x==y */
@@ -146,18 +146,18 @@ str_end(const char *str)
}
void
-closeon(struct ship *from, struct ship *to, char *command, int ta, int ma, int af)
+closeon(struct ship *from, struct ship *to, char *command, size_t commandmax, int ta, int ma, int af)
{
int high;
char temp[10];
temp[0] = command[0] = '\0';
high = -30000;
- try(from, to, command, temp, ma, ta, af, ma, from->file->dir, &high, 0);
+ try(from, to, command, commandmax, temp, sizeof(temp), ma, ta, af, ma, from->file->dir, &high, 0);
}
static int
-score(struct ship *ship, struct ship *to, char *movement, int onlytemp)
+score(struct ship *ship, struct ship *to, char *movement, size_t movementmax, int onlytemp)
{
int drift;
int row, col, dir, total, ran;
@@ -170,7 +170,7 @@ score(struct ship *ship, struct ship *to, char *movement, int onlytemp)
drift = fp->drift;
move_ship(ship, movement, &fp->dir, &fp->row, &fp->col, &drift);
if (!*movement)
- strcpy(movement, "d");
+ strlcpy(movement, "d", movementmax);
ran = range(ship, to);
total = -50 * ran;
@@ -228,7 +228,7 @@ move_ship(struct ship *ship, const char *p, unsigned char *dir, short *row, shor
}
static void
-try(struct ship *f, struct ship *t, char *command, char *temp, int ma, int ta, int af, int vma, int dir, int *high, int rakeme)
+try(struct ship *f, struct ship *t, char *command, size_t commandmax, char *temp, size_t tempmax, int ma, int ta, int af, int vma, int dir, int *high, int rakeme)
{
int new, n;
char st[4];
@@ -236,35 +236,35 @@ try(struct ship *f, struct ship *t, char *command, char *temp, int ma, int ta, i
if ((n = str_end(temp)) < '1' || n > '9')
for (n = 1; vma - n >= 0; n++) {
- sprintf(st, "%d", n);
- strcat(temp, st);
- new = score(f, t, temp, rakeme);
+ snprintf(st, sizeof(st), "%d", n);
+ strlcat(temp, st, tempmax);
+ new = score(f, t, temp, tempmax, rakeme);
if (new > *high && (!rakeme || rakeyou)) {
*high = new;
- strcpy(command, temp);
+ strlcpy(command, temp, commandmax);
}
- try(f, t, command, temp, ma-n, ta, af, vma-n,
+ try(f, t, command, commandmax, temp, tempmax, ma-n, ta, af, vma-n,
dir, high, rakeme);
rmend(temp);
}
if ((ma > 0 && ta > 0 && (n = str_end(temp)) != 'l' && n != 'r') || !strlen(temp)) {
- strcat(temp, "r");
- new = score(f, t, temp, rakeme);
+ strlcat(temp, "r", tempmax);
+ new = score(f, t, temp, tempmax, rakeme);
if (new > *high && (!rakeme || (gunsbear(f, t) && !gunsbear(t, f)))) {
*high = new;
- strcpy(command, temp);
+ strlcpy(command, temp, commandmax);
}
- try(f, t, command, temp, ma-1, ta-1, af, min(ma-1, maxmove(f, (dir == 8 ? 1 : dir+1), 0)), (dir == 8 ? 1 : dir+1), high, rakeme);
+ try(f, t, command, commandmax, temp, tempmax, ma-1, ta-1, af, min(ma-1, maxmove(f, (dir == 8 ? 1 : dir+1), 0)), (dir == 8 ? 1 : dir+1), high, rakeme);
rmend(temp);
}
if ((ma > 0 && ta > 0 && (n = str_end(temp)) != 'l' && n != 'r') || !strlen(temp)){
- strcat(temp, "l");
- new = score(f, t, temp, rakeme);
+ strlcat(temp, "l", sizeof(temp));
+ new = score(f, t, temp, tempmax, rakeme);
if (new > *high && (!rakeme || (gunsbear(f, t) && !gunsbear(t, f)))){
*high = new;
- strcpy(command, temp);
+ strlcpy(command, temp, commandmax);
}
- try(f, t, command, temp, ma-1, ta-1, af, (min(ma-1,maxmove(f, (dir-1 ? dir-1 : 8), 0))), (dir-1 ? dir -1 : 8), high, rakeme);
+ try(f, t, command, commandmax, temp, tempmax, ma-1, ta-1, af, (min(ma-1,maxmove(f, (dir-1 ? dir-1 : 8), 0))), (dir-1 ? dir -1 : 8), high, rakeme);
rmend(temp);
}
}