Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/games/hack Use the right type for the malloc wrapper functio...
details: https://anonhg.NetBSD.org/src/rev/1be95100e3d5
branches: trunk
changeset: 768033:1be95100e3d5
user: dholland <dholland%NetBSD.org@localhost>
date: Sat Aug 06 20:18:26 2011 +0000
description:
Use the right type for the malloc wrapper function, and don't cast the
return value.
(XXX: Except for a pile of allocation macros that produce typed pointer
results; there the typechecking of the result assignment is more valuable
than the warning if the alloc function isn't declared properly. These
macros should go away.)
diffstat:
games/hack/alloc.c | 17 +++++++++--------
games/hack/def.gen.h | 4 ++--
games/hack/def.gold.h | 4 ++--
games/hack/def.monst.h | 4 ++--
games/hack/def.obj.h | 4 ++--
games/hack/def.trap.h | 4 ++--
games/hack/def.wseg.h | 4 ++--
games/hack/extern.h | 4 ++--
games/hack/hack.end.c | 6 +++---
games/hack/hack.engrave.c | 14 +++++++-------
games/hack/hack.h | 4 ++--
games/hack/hack.o_init.c | 6 +++---
games/hack/hack.pager.c | 9 ++++-----
games/hack/hack.rumors.c | 6 +++---
games/hack/hack.topl.c | 7 +++----
15 files changed, 48 insertions(+), 49 deletions(-)
diffs (truncated from 374 to 300 lines):
diff -r 4a7bf89c7c9e -r 1be95100e3d5 games/hack/alloc.c
--- a/games/hack/alloc.c Sat Aug 06 20:00:33 2011 +0000
+++ b/games/hack/alloc.c Sat Aug 06 20:18:26 2011 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: alloc.c,v 1.8 2010/01/17 22:55:20 wiz Exp $ */
+/* $NetBSD: alloc.c,v 1.9 2011/08/06 20:18:26 dholland Exp $ */
/*
* Copyright (c) 1985, Stichting Centrum voor Wiskunde en Informatica,
@@ -63,21 +63,22 @@
#include <sys/cdefs.h>
#ifndef lint
-__RCSID("$NetBSD: alloc.c,v 1.8 2010/01/17 22:55:20 wiz Exp $");
+__RCSID("$NetBSD: alloc.c,v 1.9 2011/08/06 20:18:26 dholland Exp $");
#endif /* not lint */
#include <stdlib.h>
#include "hack.h"
#include "extern.h"
-long *
-alloc(unsigned lth)
+void *
+alloc(size_t len)
{
- long *ptr;
+ void *ptr;
- if (!(ptr = malloc(lth)))
- panic("Cannot get %d bytes", lth);
- return (ptr);
+ ptr = malloc(len);
+ if (ptr == NULL)
+ panic("Cannot get %zu bytes", len);
+ return ptr;
}
#if 0 /* unused */
diff -r 4a7bf89c7c9e -r 1be95100e3d5 games/hack/def.gen.h
--- a/games/hack/def.gen.h Sat Aug 06 20:00:33 2011 +0000
+++ b/games/hack/def.gen.h Sat Aug 06 20:18:26 2011 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: def.gen.h,v 1.5 2003/04/02 18:36:34 jsm Exp $ */
+/* $NetBSD: def.gen.h,v 1.6 2011/08/06 20:18:26 dholland Exp $ */
/*
* Copyright (c) 1985, Stichting Centrum voor Wiskunde en Informatica,
@@ -73,5 +73,5 @@
#define ONCE 0100
};
extern struct gen *fgold, *ftrap;
-#define newgen() (struct gen *) alloc(sizeof(struct gen))
+#define newgen() ((struct gen *) alloc(sizeof(struct gen)))
#endif /* _DEF_GEN_H_ */
diff -r 4a7bf89c7c9e -r 1be95100e3d5 games/hack/def.gold.h
--- a/games/hack/def.gold.h Sat Aug 06 20:00:33 2011 +0000
+++ b/games/hack/def.gold.h Sat Aug 06 20:18:26 2011 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: def.gold.h,v 1.5 2003/04/02 18:36:34 jsm Exp $ */
+/* $NetBSD: def.gold.h,v 1.6 2011/08/06 20:18:26 dholland Exp $ */
/*
* Copyright (c) 1985, Stichting Centrum voor Wiskunde en Informatica,
@@ -69,6 +69,6 @@
long amount;
};
-#define newgold() (struct gold *) alloc(sizeof(struct gold))
+#define newgold() ((struct gold *) alloc(sizeof(struct gold)))
extern struct gold *fgold;
#endif /* _DEF_GOLD_H_ */
diff -r 4a7bf89c7c9e -r 1be95100e3d5 games/hack/def.monst.h
--- a/games/hack/def.monst.h Sat Aug 06 20:00:33 2011 +0000
+++ b/games/hack/def.monst.h Sat Aug 06 20:18:26 2011 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: def.monst.h,v 1.7 2003/04/02 18:36:34 jsm Exp $ */
+/* $NetBSD: def.monst.h,v 1.8 2011/08/06 20:18:26 dholland Exp $ */
/*
* Copyright (c) 1985, Stichting Centrum voor Wiskunde en Informatica,
@@ -107,7 +107,7 @@
long mextra[1]; /* monster dependent info */
};
-#define newmonst(xl) (struct monst *) alloc((unsigned)(xl) + sizeof(struct monst))
+#define newmonst(xl) ((struct monst *) alloc((xl) + sizeof(struct monst)))
extern struct monst *fmon;
extern struct monst *fallen_down;
diff -r 4a7bf89c7c9e -r 1be95100e3d5 games/hack/def.obj.h
--- a/games/hack/def.obj.h Sat Aug 06 20:00:33 2011 +0000
+++ b/games/hack/def.obj.h Sat Aug 06 20:18:26 2011 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: def.obj.h,v 1.5 2003/04/02 18:36:34 jsm Exp $ */
+/* $NetBSD: def.obj.h,v 1.6 2011/08/06 20:18:26 dholland Exp $ */
/*
* Copyright (c) 1985, Stichting Centrum voor Wiskunde en Informatica,
@@ -105,7 +105,7 @@
extern struct obj *fobj;
-#define newobj(xl) (struct obj *) alloc((unsigned)(xl) + sizeof(struct obj))
+#define newobj(xl) ((struct obj *) alloc((xl) + sizeof(struct obj)))
#define ONAME(otmp) ((char *) otmp->oextra)
#define OGOLD(otmp) (otmp->oextra[0])
#endif /* _DEF_OBJ_H_ */
diff -r 4a7bf89c7c9e -r 1be95100e3d5 games/hack/def.trap.h
--- a/games/hack/def.trap.h Sat Aug 06 20:00:33 2011 +0000
+++ b/games/hack/def.trap.h Sat Aug 06 20:18:26 2011 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: def.trap.h,v 1.5 2003/04/02 18:36:35 jsm Exp $ */
+/* $NetBSD: def.trap.h,v 1.6 2011/08/06 20:18:26 dholland Exp $ */
/*
* Copyright (c) 1985, Stichting Centrum voor Wiskunde en Informatica,
@@ -72,7 +72,7 @@
};
extern struct trap *ftrap;
-#define newtrap() (struct trap *) alloc(sizeof(struct trap))
+#define newtrap() ((struct trap *) alloc(sizeof(struct trap)))
/* various kinds of traps */
#define BEAR_TRAP 0
diff -r 4a7bf89c7c9e -r 1be95100e3d5 games/hack/def.wseg.h
--- a/games/hack/def.wseg.h Sat Aug 06 20:00:33 2011 +0000
+++ b/games/hack/def.wseg.h Sat Aug 06 20:18:26 2011 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: def.wseg.h,v 1.5 2003/04/02 18:36:35 jsm Exp $ */
+/* $NetBSD: def.wseg.h,v 1.6 2011/08/06 20:18:26 dholland Exp $ */
/*
* Copyright (c) 1985, Stichting Centrum voor Wiskunde en Informatica,
@@ -71,6 +71,6 @@
unsigned wdispl:1;
};
-#define newseg() (struct wseg *) alloc(sizeof(struct wseg))
+#define newseg() ((struct wseg *) alloc(sizeof(struct wseg)))
#endif /* NOWORM */
#endif /* _DEF_WSEG_H_ */
diff -r 4a7bf89c7c9e -r 1be95100e3d5 games/hack/extern.h
--- a/games/hack/extern.h Sat Aug 06 20:00:33 2011 +0000
+++ b/games/hack/extern.h Sat Aug 06 20:18:26 2011 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: extern.h,v 1.15 2011/08/06 20:00:33 dholland Exp $ */
+/* $NetBSD: extern.h,v 1.16 2011/08/06 20:18:26 dholland Exp $ */
/*-
* Copyright (c) 1997 The NetBSD Foundation, Inc.
@@ -34,7 +34,7 @@
#include <stdio.h>
/* alloc.c */
-long *alloc(unsigned);
+void *alloc(size_t);
/* hack.apply.c */
int doapply(void);
diff -r 4a7bf89c7c9e -r 1be95100e3d5 games/hack/hack.end.c
--- a/games/hack/hack.end.c Sat Aug 06 20:00:33 2011 +0000
+++ b/games/hack/hack.end.c Sat Aug 06 20:18:26 2011 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: hack.end.c,v 1.14 2010/02/03 15:34:38 roy Exp $ */
+/* $NetBSD: hack.end.c,v 1.15 2011/08/06 20:18:26 dholland Exp $ */
/*
* Copyright (c) 1985, Stichting Centrum voor Wiskunde en Informatica,
@@ -63,7 +63,7 @@
#include <sys/cdefs.h>
#ifndef lint
-__RCSID("$NetBSD: hack.end.c,v 1.14 2010/02/03 15:34:38 roy Exp $");
+__RCSID("$NetBSD: hack.end.c,v 1.15 2011/08/06 20:18:26 dholland Exp $");
#endif /* not lint */
#include <signal.h>
@@ -300,7 +300,7 @@
exit(0);
}
-#define newttentry() (struct toptenentry *) alloc(sizeof(struct toptenentry))
+#define newttentry() ((struct toptenentry *) alloc(sizeof(struct toptenentry)))
#define NAMSZ 8
#define DTHSZ 40
#define PERSMAX 1
diff -r 4a7bf89c7c9e -r 1be95100e3d5 games/hack/hack.engrave.c
--- a/games/hack/hack.engrave.c Sat Aug 06 20:00:33 2011 +0000
+++ b/games/hack/hack.engrave.c Sat Aug 06 20:18:26 2011 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: hack.engrave.c,v 1.10 2011/08/06 20:00:33 dholland Exp $ */
+/* $NetBSD: hack.engrave.c,v 1.11 2011/08/06 20:18:26 dholland Exp $ */
/*
* Copyright (c) 1985, Stichting Centrum voor Wiskunde en Informatica,
@@ -63,7 +63,7 @@
#include <sys/cdefs.h>
#ifndef lint
-__RCSID("$NetBSD: hack.engrave.c,v 1.10 2011/08/06 20:00:33 dholland Exp $");
+__RCSID("$NetBSD: hack.engrave.c,v 1.11 2011/08/06 20:18:26 dholland Exp $");
#endif /* not lint */
#include <stdlib.h>
@@ -185,8 +185,8 @@
if ((ep = engr_at(x, y)) != NULL)
del_engr(ep);
- ep = (struct engr *)
- alloc((unsigned) (sizeof(struct engr) + strlen(s) + 1));
+ ep = alloc(sizeof(*ep) + strlen(s) + 1);
+
ep->nxt_engr = head_engr;
head_engr = ep;
ep->engr_x = x;
@@ -316,7 +316,7 @@
}
if (oep)
len += strlen(oep->engr_txt) + spct;
- ep = (struct engr *) alloc((unsigned) (sizeof(struct engr) + len + 1));
+ ep = alloc(sizeof(*ep) + len + 1);
ep->nxt_engr = head_engr;
head_engr = ep;
ep->engr_x = u.ux;
@@ -367,8 +367,8 @@
mread(fd, <h, sizeof(unsigned));
if (lth == 0)
return;
- ep = (struct engr *) alloc(sizeof(struct engr) + lth);
- mread(fd, ep, sizeof(struct engr) + lth);
+ ep = alloc(sizeof(*ep) + lth);
+ mread(fd, ep, sizeof(*ep) + lth);
ep->nxt_engr = head_engr;
ep->engr_txt = (char *) (ep + 1); /* Andreas Bormann */
head_engr = ep;
diff -r 4a7bf89c7c9e -r 1be95100e3d5 games/hack/hack.h
--- a/games/hack/hack.h Sat Aug 06 20:00:33 2011 +0000
+++ b/games/hack/hack.h Sat Aug 06 20:18:26 2011 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: hack.h,v 1.15 2011/08/06 19:47:54 dholland Exp $ */
+/* $NetBSD: hack.h,v 1.16 2011/08/06 20:18:26 dholland Exp $ */
/*
* Copyright (c) 1985, Stichting Centrum voor Wiskunde en Informatica,
@@ -91,7 +91,7 @@
#include "def.rm.h"
#include "def.permonst.h"
-#define newstring(x) (char *) alloc((unsigned)(x))
+#define newstring(x) ((char *) alloc(x))
#include "hack.onames.h"
#define ON 1
diff -r 4a7bf89c7c9e -r 1be95100e3d5 games/hack/hack.o_init.c
--- a/games/hack/hack.o_init.c Sat Aug 06 20:00:33 2011 +0000
+++ b/games/hack/hack.o_init.c Sat Aug 06 20:18:26 2011 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: hack.o_init.c,v 1.11 2011/08/06 20:00:33 dholland Exp $ */
+/* $NetBSD: hack.o_init.c,v 1.12 2011/08/06 20:18:26 dholland Exp $ */
/*
* Copyright (c) 1985, Stichting Centrum voor Wiskunde en Informatica,
@@ -63,7 +63,7 @@
#include <sys/cdefs.h>
#ifndef lint
-__RCSID("$NetBSD: hack.o_init.c,v 1.11 2011/08/06 20:00:33 dholland Exp $");
+__RCSID("$NetBSD: hack.o_init.c,v 1.12 2011/08/06 20:18:26 dholland Exp $");
#endif /* not lint */
#include <string.h>
@@ -206,7 +206,7 @@
for (i = 0; i < SIZE(objects); i++)
if (objects[i].oc_uname) {
mread(fd, &len, sizeof len);
- objects[i].oc_uname = (char *) alloc(len);
+ objects[i].oc_uname = alloc(len);
mread(fd, objects[i].oc_uname, len);
}
}
diff -r 4a7bf89c7c9e -r 1be95100e3d5 games/hack/hack.pager.c
--- a/games/hack/hack.pager.c Sat Aug 06 20:00:33 2011 +0000
+++ b/games/hack/hack.pager.c Sat Aug 06 20:18:26 2011 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: hack.pager.c,v 1.16 2011/08/06 19:53:24 dholland Exp $ */
+/* $NetBSD: hack.pager.c,v 1.17 2011/08/06 20:18:26 dholland Exp $ */
/*
* Copyright (c) 1985, Stichting Centrum voor Wiskunde en Informatica,
@@ -63,7 +63,7 @@
#include <sys/cdefs.h>
#ifndef lint
-__RCSID("$NetBSD: hack.pager.c,v 1.16 2011/08/06 19:53:24 dholland Exp $");
+__RCSID("$NetBSD: hack.pager.c,v 1.17 2011/08/06 20:18:26 dholland Exp $");
#endif /* not lint */
/* This file contains the command routine dowhatis() and a pager. */
Home |
Main Index |
Thread Index |
Old Index