Module Name:    src
Committed By:   christos
Date:           Tue Aug 16 09:26:22 UTC 2011

Modified Files:
        src/games/hack: Makefile def.monst.h hack.monst.c hack.vault.c

Log Message:
- document non-literal format strings
- avoid strict aliasing violations, but adding an intermediate function.


To generate a diff of this commit:
cvs rdiff -u -r1.43 -r1.44 src/games/hack/Makefile
cvs rdiff -u -r1.8 -r1.9 src/games/hack/def.monst.h \
    src/games/hack/hack.vault.c
cvs rdiff -u -r1.6 -r1.7 src/games/hack/hack.monst.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/games/hack/Makefile
diff -u src/games/hack/Makefile:1.43 src/games/hack/Makefile:1.44
--- src/games/hack/Makefile:1.43	Tue Jun 21 22:49:43 2011
+++ src/games/hack/Makefile	Tue Aug 16 05:26:22 2011
@@ -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 @@
 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 @@
 	rm -f ${DESTDIR}/var/games/hackdir/bones*
 
 .include <bsd.prog.mk>
-
-# XXX
-.if ${HAVE_GCC} == 45
-COPTS.hack.vault.c+=	-fno-strict-aliasing
-.endif

Index: src/games/hack/def.monst.h
diff -u src/games/hack/def.monst.h:1.8 src/games/hack/def.monst.h:1.9
--- src/games/hack/def.monst.h:1.8	Sat Aug  6 16:18:26 2011
+++ src/games/hack/def.monst.h	Tue Aug 16 05:26:22 2011
@@ -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 @@
 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 */
Index: src/games/hack/hack.vault.c
diff -u src/games/hack/hack.vault.c:1.8 src/games/hack/hack.vault.c:1.9
--- src/games/hack/hack.vault.c:1.8	Sun Jun  7 14:30:39 2009
+++ src/games/hack/hack.vault.c	Tue Aug 16 05:26:22 2011
@@ -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 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 @@
 {
 	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 @@
 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 @@
 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 @@
 		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 @@
 			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 @@
 	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 @@
 					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 @@
 							 * 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 @@
 		}
 	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 @@
 		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;

Index: src/games/hack/hack.monst.c
diff -u src/games/hack/hack.monst.c:1.6 src/games/hack/hack.monst.c:1.7
--- src/games/hack/hack.monst.c:1.6	Wed Apr  2 13:36:38 2003
+++ src/games/hack/hack.monst.c	Tue Aug 16 05:26:22 2011
@@ -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_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;
+}

Reply via email to