summaryrefslogtreecommitdiffstats
path: root/hack
diff options
context:
space:
mode:
authorchristos <christos@NetBSD.org>2011-08-16 09:26:22 +0000
committerchristos <christos@NetBSD.org>2011-08-16 09:26:22 +0000
commit34b5fff1b8d58f2ddaa89336354958daf8506b15 (patch)
tree09ee1c30254128e6ebf641897fbf6815959369d4 /hack
parent04539cb235b06fd8cacf5c4c40081bd86e0dfa04 (diff)
downloadbsdgames-darwin-34b5fff1b8d58f2ddaa89336354958daf8506b15.tar.gz
bsdgames-darwin-34b5fff1b8d58f2ddaa89336354958daf8506b15.tar.zst
bsdgames-darwin-34b5fff1b8d58f2ddaa89336354958daf8506b15.zip
- document non-literal format strings
- avoid strict aliasing violations, but adding an intermediate function.
Diffstat (limited to 'hack')
-rw-r--r--hack/Makefile9
-rw-r--r--hack/def.monst.h4
-rw-r--r--hack/hack.monst.c10
-rw-r--r--hack/hack.vault.c60
4 files changed, 46 insertions, 37 deletions
diff --git a/hack/Makefile b/hack/Makefile
index febefa23..9b3de2ce 100644
--- a/hack/Makefile
+++ b/hack/Makefile
@@ -1,4 +1,4 @@
-# $NetBSD: Makefile,v 1.43 2011/06/22 02:49:43 mrg Exp $
+# $NetBSD: Makefile,v 1.44 2011/08/16 09:26:22 christos Exp $
# @(#)Makefile 8.2 (Berkeley) 4/27/95
.include <bsd.own.mk>
@@ -41,6 +41,8 @@ hack.h: hack.onames.h
COPTS.hack.bones.c+= -Wno-shadow
COPTS.hack.do.c+= -Wno-shadow
.endif
+COPTS.hack.mon.c+= -Wno-format-nonliteral
+COPTS.hack.rip.c+= -Wno-format-nonliteral
.if !exists(${DESTDIR}${FILESDIR}/perm)
afterinstall: clobber
@@ -57,8 +59,3 @@ clobber:
rm -f ${DESTDIR}/var/games/hackdir/bones*
.include <bsd.prog.mk>
-
-# XXX
-.if ${HAVE_GCC} == 45
-COPTS.hack.vault.c+= -fno-strict-aliasing
-.endif
diff --git a/hack/def.monst.h b/hack/def.monst.h
index f8481c2b..99c2ccf9 100644
--- a/hack/def.monst.h
+++ b/hack/def.monst.h
@@ -1,4 +1,4 @@
-/* $NetBSD: def.monst.h,v 1.8 2011/08/06 20:18:26 dholland Exp $ */
+/* $NetBSD: def.monst.h,v 1.9 2011/08/16 09:26:22 christos Exp $ */
/*
* Copyright (c) 1985, Stichting Centrum voor Wiskunde en Informatica,
@@ -112,6 +112,8 @@ struct monst {
extern struct monst *fmon;
extern struct monst *fallen_down;
+extern void *monster_private(struct monst *);
+
/* these are in mspeed */
#define MSLOW 1 /* slow monster */
#define MFAST 2 /* speeded monster */
diff --git a/hack/hack.monst.c b/hack/hack.monst.c
index 4c30814e..3eb29b43 100644
--- a/hack/hack.monst.c
+++ b/hack/hack.monst.c
@@ -1,4 +1,4 @@
-/* $NetBSD: hack.monst.c,v 1.6 2003/04/02 18:36:38 jsm Exp $ */
+/* $NetBSD: hack.monst.c,v 1.7 2011/08/16 09:26:22 christos Exp $ */
/*
* Copyright (c) 1985, Stichting Centrum voor Wiskunde en Informatica,
@@ -63,7 +63,7 @@
#include <sys/cdefs.h>
#ifndef lint
-__RCSID("$NetBSD: hack.monst.c,v 1.6 2003/04/02 18:36:38 jsm Exp $");
+__RCSID("$NetBSD: hack.monst.c,v 1.7 2011/08/16 09:26:22 christos Exp $");
#endif /* not lint */
#include "hack.h"
@@ -142,3 +142,9 @@ const struct permonst pm_wizard = {
const struct permonst pm_mail_daemon = {"mail daemon", '2', 100, 1, 10, 0, 0, 0};
#endif /* MAIL */
const struct permonst pm_eel = {"giant eel", ';', 15, 6, -3, 3, 6, 0};
+
+void *
+monster_private(struct monst *mon)
+{
+ return mon->mextra;
+}
diff --git a/hack/hack.vault.c b/hack/hack.vault.c
index 482b0207..cbbf1fc8 100644
--- a/hack/hack.vault.c
+++ b/hack/hack.vault.c
@@ -1,4 +1,4 @@
-/* $NetBSD: hack.vault.c,v 1.8 2009/06/07 18:30:39 dholland Exp $ */
+/* $NetBSD: hack.vault.c,v 1.9 2011/08/16 09:26:22 christos Exp $ */
/*
* Copyright (c) 1985, Stichting Centrum voor Wiskunde en Informatica,
@@ -63,7 +63,7 @@
#include <sys/cdefs.h>
#ifndef lint
-__RCSID("$NetBSD: hack.vault.c,v 1.8 2009/06/07 18:30:39 dholland Exp $");
+__RCSID("$NetBSD: hack.vault.c,v 1.9 2011/08/16 09:26:22 christos Exp $");
#endif /* not lint */
#include "hack.h"
@@ -116,7 +116,6 @@ static const struct permonst pm_guard =
static struct monst *guard;
static int gdlevel;
-#define EGD ((struct egd *)(&(guard->mextra[0])))
static void restfakecorr(void);
static int goldincorridor(void);
@@ -126,19 +125,20 @@ restfakecorr(void)
{
int fcx, fcy, fcbeg;
struct rm *crm;
+ struct egd *egd = monster_private(guard);
- while ((fcbeg = EGD->fcbeg) < EGD->fcend) {
- fcx = EGD->fakecorr[fcbeg].fx;
- fcy = EGD->fakecorr[fcbeg].fy;
+ while ((fcbeg = egd->fcbeg) < egd->fcend) {
+ fcx = egd->fakecorr[fcbeg].fx;
+ fcy = egd->fakecorr[fcbeg].fy;
if ((u.ux == fcx && u.uy == fcy) || cansee(fcx, fcy) ||
m_at(fcx, fcy))
return;
crm = &levl[fcx][fcy];
- crm->typ = EGD->fakecorr[fcbeg].ftyp;
+ crm->typ = egd->fakecorr[fcbeg].ftyp;
if (!crm->typ)
crm->seen = 0;
newsym(fcx, fcy);
- EGD->fcbeg++;
+ egd->fcbeg++;
}
/* it seems he left the corridor - let the guard disappear */
mondead(guard);
@@ -149,9 +149,10 @@ static int
goldincorridor(void)
{
int fci;
+ struct egd *egd = monster_private(guard);
- for (fci = EGD->fcbeg; fci < EGD->fcend; fci++)
- if (g_at(EGD->fakecorr[fci].fx, EGD->fakecorr[fci].fy))
+ for (fci = egd->fcbeg; fci < egd->fcend; fci++)
+ if (g_at(egd->fakecorr[fci].fx, egd->fakecorr[fci].fy))
return (1);
return (0);
}
@@ -173,6 +174,7 @@ void
invault(void)
{
int tmp = inroom(u.ux, u.uy);
+ struct egd *egd;
if (tmp < 0 || rooms[tmp].rtype != VAULT) {
u.uinvault = 0;
return;
@@ -221,7 +223,8 @@ fnd:
if (!(guard = makemon(&pm_guard, x, y)))
return;
guard->isgd = guard->mpeaceful = 1;
- EGD->gddone = 0;
+ egd = monster_private(guard);
+ egd->gddone = 0;
gdlevel = dlevel;
if (!cansee(guard->mx, guard->my)) {
mondead(guard);
@@ -249,14 +252,14 @@ fnd:
pline("\"Most likely all that gold was stolen from this vault.\"");
pline("\"Please drop your gold (say d$ ) and follow me.\"");
}
- EGD->gdx = gx;
- EGD->gdy = gy;
- EGD->fcbeg = 0;
- EGD->fakecorr[0].fx = x;
- EGD->fakecorr[0].fy = y;
- EGD->fakecorr[0].ftyp = levl[x][y].typ;
+ egd->gdx = gx;
+ egd->gdy = gy;
+ egd->fcbeg = 0;
+ egd->fakecorr[0].fx = x;
+ egd->fakecorr[0].fy = y;
+ egd->fakecorr[0].ftyp = levl[x][y].typ;
levl[x][y].typ = DOOR;
- EGD->fcend = 1;
+ egd->fcend = 1;
}
}
@@ -266,13 +269,14 @@ gd_move(void)
int x, y, dx, dy, gx, gy, nx, ny, typ;
struct fakecorridor *fcp;
struct rm *crm;
+ struct egd *egd = monster_private(guard);
if (!guard || gdlevel != dlevel) {
impossible("Where is the guard?");
return (2); /* died */
}
if (u.ugold || goldincorridor())
return (0); /* didnt move */
- if (dist(guard->mx, guard->my) > 1 || EGD->gddone) {
+ if (dist(guard->mx, guard->my) > 1 || egd->gddone) {
restfakecorr();
return (0); /* didnt move */
}
@@ -286,9 +290,9 @@ gd_move(void)
if (isok(nx, ny))
if (!IS_WALL(typ = (crm = &levl[nx][ny])->typ) && typ != POOL) {
int i;
- for (i = EGD->fcbeg; i < EGD->fcend; i++)
- if (EGD->fakecorr[i].fx == nx &&
- EGD->fakecorr[i].fy == ny)
+ for (i = egd->fcbeg; i < egd->fcend; i++)
+ if (egd->fakecorr[i].fx == nx &&
+ egd->fakecorr[i].fy == ny)
goto nextnxy;
if ((i = inroom(nx, ny)) >= 0 && rooms[i].rtype == VAULT)
goto nextnxy;
@@ -297,7 +301,7 @@ gd_move(void)
* good place to
* leave him alone
*/
- EGD->gddone = 1;
+ egd->gddone = 1;
if (ACCESSIBLE(typ))
goto newpos;
crm->typ = (typ == SCORR) ? CORR : DOOR;
@@ -307,8 +311,8 @@ gd_move(void)
}
nx = x;
ny = y;
- gx = EGD->gdx;
- gy = EGD->gdy;
+ gx = egd->gdx;
+ gy = egd->gdy;
dx = (gx > x) ? 1 : (gx < x) ? -1 : 0;
dy = (gy > y) ? 1 : (gy < y) ? -1 : 0;
if (abs(gx - x) >= abs(gy - y))
@@ -348,14 +352,14 @@ proceed:
mnewsym(nx, ny);
prl(nx, ny);
}
- fcp = &(EGD->fakecorr[EGD->fcend]);
- if (EGD->fcend++ == FCSIZ)
+ fcp = &(egd->fakecorr[egd->fcend]);
+ if (egd->fcend++ == FCSIZ)
panic("fakecorr overflow");
fcp->fx = nx;
fcp->fy = ny;
fcp->ftyp = typ;
newpos:
- if (EGD->gddone)
+ if (egd->gddone)
nx = ny = 0;
guard->mx = nx;
guard->my = ny;