extern boolean read_tribute(const char *, const char *, int, char *, int,
unsigned);
extern boolean Death_quote(char *, int);
-extern void livelog_add(long, const char *);
+extern void livelog_add(long ll_type, const char *);
/* ### fountain.c ### */
nh_snprintf(__func__, __LINE__, str, size, __VA_ARGS__)
extern void nh_snprintf(const char *func, int line, char *str, size_t size,
const char *fmt, ...) PRINTF_F(5, 6);
+#define FITSint(x) FITSint_(x, __func__, __LINE__)
+extern int FITSint_(long long, const char *, int);
+#define FITSuint(x) FITSuint_(x, __func__, __LINE__)
+extern unsigned FITSuint_(unsigned long long, const char *, int);
/* ### insight.c ### */
/* since this file is also used in auxiliary programs, don't include all the
function declarations for all of nethack */
#define EXTERN_H /* comment line for pre-compiled headers */
+/* but we need this one */
+#define FITSuint(x) FITSuint_(x, __func__, __LINE__)
+extern unsigned FITSuint_(unsigned long long, const char *, int);
+
#include "config.h"
char *fmt_ptr(const genericptr);
char *
dupstr(const char *string)
{
- return strcpy((char *) alloc(strlen(string) + 1), string);
+ unsigned len = FITSuint(strlen(string));
+ return strcpy((char *) alloc(len + 1), string);
}
/* similar for reasonable size strings, but return the length of the input as well */
int
parse_cond_option(boolean negated, char *opts)
{
- int i;
- size_t sl;
+ int i, sl;
const char *compareto, *uniqpart, prefix[] = "cond_";
if (!opts || strlen(opts) <= sizeof prefix - 1)
/* without extern.h via hack.h, these haven't been declared for us */
extern FILE *fopen_datafile(const char *, const char *, int);
+#define FITSuint(x) FITSuint_((x), __func__, __LINE__)
+/* implementation will be in either dlb_main.c or the core */
+extern unsigned FITSuint_(unsigned long long, const char *, int);
+
#ifdef DLBLIB
/*
if (lp->rev > DLB_MAX_VERS || lp->rev < DLB_MIN_VERS)
return FALSE;
- lp->dir = (libdir *) alloc(lp->nentries * sizeof(libdir));
- lp->sspace = (char *) alloc(lp->strsize);
+ lp->dir = (libdir *) alloc(FITSuint(lp->nentries * sizeof(libdir)));
+ lp->sspace = (char *) alloc(FITSuint(lp->strsize));
/* read in each directory entry */
for (i = 0, sp = lp->sspace; i < lp->nentries; i++) {
RESTORE_WARNING_FORMAT_NONLITERAL
+/* cast to int or panic on overflow; use via macro */
+int
+FITSint_(lua_Integer i, const char *file, int line){
+ int ret = (int)i;
+ if (ret != i)
+ panic("Overflow at %s:%d", file, line);
+ return (int)i;
+}
+
+unsigned
+FITSuint_(unsigned long long i, const char *file, int line){
+ unsigned ret = (unsigned)i;
+ if (ret != i)
+ panic("Overflow at %s:%d", file, line);
+ return (unsigned)i;
+}
+
/*hacklib.c*/
dlb_fseek(fh, 0L, SEEK_SET);
/* extra +1: room to add final '\n' if missing */
- buf = bufout = (char *) alloc(buflen + 1 + 1);
+ buf = bufout = (char *) alloc(FITSint(buflen + 1 + 1));
buf[0] = '\0';
bufin = bufout = buf;
* in use, and fseek(SEEK_END) only yields an upper bound on
* the actual amount of data in that situation.]
*/
- if ((cnt = dlb_fread(bufin, 1, min(buflen, LOADCHUNKSIZE), fh)) < 0L)
+ if ((cnt = dlb_fread(bufin, 1, min((int)buflen, LOADCHUNKSIZE), fh)) < 0L)
break;
buflen -= cnt; /* set up for next iteration, if any */
if (cnt == 0L) {
for (i = 0; i < SIZE(msgtype_names); i++)
if (streq(msgtype_names[i].name, msgtype, TRUE)) {
- //if (!strncmpi(msgtype_names[i].name, msgtype, strlen(msgtype))) {
typ = msgtype_names[i].msgtyp;
break;
}
return;
}
for (k = 0; allopt[k].name; k++) {
- if (!strncmpi(allopt[k].name, optnam, strlen(optnam))) {
+ if (streq(allopt[k].name, optnam, TRUE)) {
+ //if (!strncmpi(allopt[k].name, optnam, strlen(optnam))) {
allopt[k].setwhere = status;
return;
}
static void xexit(int) NORETURN;
char *eos(char *); /* also used by dlb.c */
FILE *fopen_datafile(const char *, const char *);
+unsigned FITSuint_(unsigned long long, const char *, int);
#ifdef DLB
#ifdef DLBLIB
/*NOTREACHED*/
}
+ /* In hacklib.c, but we don't have that and it calls panic() */
+unsigned
+FITSuint_(unsigned long long i, const char *file, int line){
+ unsigned ret = (unsigned)i;
+ if (ret != i) {
+ printf("Overflow at %s:%d\n", file, line);
+ xexit(EXIT_FAILURE);
+ }
+ return (unsigned)i;
+}
/*dlb_main.c*/
extern unsigned _stklen = STKSIZ;
#endif
+unsigned FITSuint_(unsigned long long, const char *, int);
+
/*
* Some of the routines in this source file were moved into .../src/mdlib
* to facilitate the use of a cross-compiler generation of some of the
#endif
#endif /* STRICT_REF_DEF */
+/* In hacklib.c, but we don't have that and it calls panic() */
+unsigned
+FITSuint_(unsigned long long i, const char *file, int line){
+unsigned ret = (unsigned)i;
+if (ret != i) {
+ Fprintf(stdout, "Overflow at %s:%d\n", file, line);
+ makedefs_exit(EXIT_FAILURE);
+}
+return (unsigned)i;
+}
/*makedefs.c*/