From cc1219b5a8bae222a6ba6a0c755419c9ca200a79 Mon Sep 17 00:00:00 2001 From: Bart House Date: Sun, 14 Jul 2019 14:02:05 -0700 Subject: [PATCH 1/4] Revert type change of lit which would break code. Cast lit (which will be 1) to unsigned int to remove warning. --- src/sp_lev.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/sp_lev.c b/src/sp_lev.c index b2206ae70..ba9d75c72 100644 --- a/src/sp_lev.c +++ b/src/sp_lev.c @@ -3763,7 +3763,7 @@ struct opvar *mc; { int x, y; schar mapc; - uchar lit; + xchar lit; struct opvar *ret = selection_opvar((char *) 0); if (!ov || !mc || !ret) @@ -3783,7 +3783,7 @@ struct opvar *mc; break; case 0: case 1: - if (levl[x][y].lit == lit) + if (levl[x][y].lit == (unsigned int) lit) selection_setpoint(x, y, ret, 1); break; } From d9da488c35de801fd651c3dd0ee8f152d5309337 Mon Sep 17 00:00:00 2001 From: Bart House Date: Sun, 14 Jul 2019 14:30:38 -0700 Subject: [PATCH 2/4] Move fuzzer_start, fuzzer_stop and fuzzer_log to pline.c --- include/extern.h | 6 ++--- src/allmain.c | 63 ++++-------------------------------------------- src/pline.c | 57 +++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 65 insertions(+), 61 deletions(-) diff --git a/include/extern.h b/include/extern.h index 3c74bfda0..ba6164be2 100644 --- a/include/extern.h +++ b/include/extern.h @@ -27,10 +27,7 @@ E void NDECL(newgame); E void FDECL(welcome, (BOOLEAN_P)); E time_t NDECL(get_realtime); E int FDECL(argcheck, (int, char **, enum earlyarg)); -E void NDECL(fuzzer_start); -E void NDECL(fuzzer_stop); E void NDECL(fuzzer_toggle); -E void VDECL(fuzzer_log, (int, const char *, ...)) PRINTF_F(2, 3); E void NDECL(fuzzer_check); E void NDECL(fuzzer_auto_start); E boolean FDECL(fuzzer_msg_history, (const char *)); @@ -1943,6 +1940,9 @@ E void VDECL(raw_printf, (const char *, ...)) PRINTF_F(1, 2); E void VDECL(impossible, (const char *, ...)) PRINTF_F(1, 2); E void VDECL(config_error_add, (const char *, ...)) PRINTF_F(1, 2); E void FDECL(nhassert_failed, (const char *, int)); +E void NDECL(fuzzer_start); +E void NDECL(fuzzer_stop); +E void VDECL(fuzzer_log, (int, const char *, ...)) PRINTF_F(2, 3); /* ### polyself.c ### */ diff --git a/src/allmain.c b/src/allmain.c index 957c47a44..b834f0a8c 100644 --- a/src/allmain.c +++ b/src/allmain.c @@ -4,7 +4,6 @@ /* NetHack may be freely redistributed. See license for details. */ /* various code that was replicated in *main.c */ -#define NEED_VARARGS #include "hack.h" #include @@ -927,38 +926,6 @@ const char *opts; return; } -static FILE * g_fuzzer_log_file = NULL; -static int g_fuzzer_log_level = LOG_MINIMAL; - -/* fuzzer_start() starts the fuzzer opening the fuzzer log file */ -void -fuzzer_start() -{ - if (!iflags.debug_fuzzer) { - const char * fq_replay; - - iflags.debug_fuzzer = TRUE; - iflags.fuzzer_auto_start = FALSE; - - nhassert(g_fuzzer_log_file == NULL); - fq_replay = fqname("fuzzer.log", SAVEPREFIX, 0); - - g_fuzzer_log_file = fopen(fq_replay, "w"); - } -} - -/* fuzzer_stop() stops the fuzzer and close the fuzzer log file */ -void -fuzzer_stop() -{ - if (iflags.debug_fuzzer) { - if(g_fuzzer_log_file != NULL) { - fclose(g_fuzzer_log_file); - g_fuzzer_log_file = NULL; - } - } -} - /* fuzzer_toggle() toggles fuzzer state */ void fuzzer_toggle() @@ -969,29 +936,6 @@ fuzzer_toggle() fuzzer_start(); } -/* fuzzer_log() is used to place messages in the file 'fuzzer.log'. This - * log is the primary tool for monitoring fuzzer activity and tracking down - * issues that the fuzzer is able to reproduce. - */ -void -fuzzer_log -VA_DECL2(int, level, const char *, str) -{ - VA_START(str); - VA_INIT(str, char *); - - if (!g_fuzzer_log_file) - return; - - if (iflags.verbose_logging_start != 0 && moves >= iflags.verbose_logging_start) - g_fuzzer_log_level = LOG_VERBOSE; - - if (level <= g_fuzzer_log_level) - Vfprintf(g_fuzzer_log_file, str, VA_ARGS); - - VA_END(); -} - /* fuzzer_check() is called prior to rhack(0) to allow the fuzzer to * check if it should stop and to allow it to reseed the game. */ @@ -1000,6 +944,8 @@ fuzzer_check() { if (iflags.debug_fuzzer) { + unsigned long seed; + if (moves >= iflags.fuzzer_stop_and_save) { iflags.fuzzer_saving = TRUE; dosave0(); @@ -1008,7 +954,7 @@ fuzzer_check() nh_terminate(EXIT_SUCCESS); } - unsigned long seed = rul(); + seed = rul(); set_random(seed, rn2); fuzzer_log(LOG_MINIMAL, "SEED:%ld:%lu\n", moves, seed); @@ -1022,9 +968,10 @@ void fuzzer_auto_start() { if (iflags.fuzzer_auto_start) { + unsigned long seed; nhassert(!iflags.debug_fuzzer); fuzzer_start(); - unsigned long seed = rul(); + seed = rul(); set_random(seed, rn2); fuzzer_log(LOG_MINIMAL, "START:%ld:%lu\n", moves, seed); } diff --git a/src/pline.c b/src/pline.c index 91e825963..03654355e 100644 --- a/src/pline.c +++ b/src/pline.c @@ -599,4 +599,61 @@ nhassert_failed(filepath, line) impossible("nhassert failed in file '%s' at line %d", filename, line); } +static FILE * g_fuzzer_log_file = NULL; +static int g_fuzzer_log_level = LOG_MINIMAL; + +/* fuzzer_start() starts the fuzzer opening the fuzzer log file */ +void +fuzzer_start() +{ + if (!iflags.debug_fuzzer) { + const char * fq_replay; + + iflags.debug_fuzzer = TRUE; + iflags.fuzzer_auto_start = FALSE; + + nhassert(g_fuzzer_log_file == NULL); + fq_replay = fqname("fuzzer.log", SAVEPREFIX, 0); + + g_fuzzer_log_file = fopen(fq_replay, "w"); + } +} + +/* fuzzer_stop() stops the fuzzer and close the fuzzer log file */ +void +fuzzer_stop() +{ + if (iflags.debug_fuzzer) { + if(g_fuzzer_log_file != NULL) { + fclose(g_fuzzer_log_file); + g_fuzzer_log_file = NULL; + } + } +} + +/* fuzzer_log() is used to place messages in the file 'fuzzer.log'. This + * log is the primary tool for monitoring fuzzer activity and tracking down + * issues that the fuzzer is able to reproduce. + */ +void +fuzzer_log +VA_DECL2(int, lvl, const char *, str) +{ + VA_START(str); + VA_INIT(str, char *); + + if (!g_fuzzer_log_file) + return; + + if (iflags.verbose_logging_start != 0 && + moves >= iflags.verbose_logging_start) + g_fuzzer_log_level = LOG_VERBOSE; + + if (lvl <= g_fuzzer_log_level) + Vfprintf(g_fuzzer_log_file, str, VA_ARGS); + + VA_END(); +} + + /*pline.c*/ From 5428d73287d3e808f4480b04dc9733165dd32e83 Mon Sep 17 00:00:00 2001 From: Bart House Date: Sun, 14 Jul 2019 14:31:00 -0700 Subject: [PATCH 3/4] Remove dead code. --- win/tty/topl.c | 74 -------------------------------------------------- 1 file changed, 74 deletions(-) diff --git a/win/tty/topl.c b/win/tty/topl.c index db151265f..df19eed7a 100644 --- a/win/tty/topl.c +++ b/win/tty/topl.c @@ -17,8 +17,6 @@ STATIC_DCL void FDECL(redotoplin, (const char *)); STATIC_DCL void FDECL(topl_putsym, (CHAR_P)); STATIC_DCL void FDECL(removetopl, (int)); -STATIC_DCL void FDECL(msghistory_snapshot, (BOOLEAN_P)); -STATIC_DCL void FDECL(free_msghistory_snapshot, (BOOLEAN_P)); int tty_doprev_message() @@ -545,78 +543,6 @@ char def; return q; } -/* shared by tty_getmsghistory() and tty_putmsghistory() */ -static char **snapshot_mesgs = 0; - -/* collect currently available message history data into a sequential array; - optionally, purge that data from the active circular buffer set as we go */ -STATIC_OVL void -msghistory_snapshot(purge) -boolean purge; /* clear message history buffer as we copy it */ -{ - char *mesg; - int i, inidx, outidx; - struct WinDesc *cw; - - /* paranoia (too early or too late panic save attempt?) */ - if (WIN_MESSAGE == WIN_ERR || !wins[WIN_MESSAGE]) - return; - cw = wins[WIN_MESSAGE]; - - /* flush toplines[], moving most recent message to history */ - remember_topl(); - - /* for a passive snapshot, we just copy pointers, so can't allow further - history updating to take place because that could clobber them */ - if (!purge) - cw->flags |= WIN_LOCKHISTORY; - - snapshot_mesgs = (char **) alloc((cw->rows + 1) * sizeof(char *)); - outidx = 0; - inidx = cw->maxrow; - for (i = 0; i < cw->rows; ++i) { - snapshot_mesgs[i] = (char *) 0; - mesg = cw->data[inidx]; - if (mesg && *mesg) { - snapshot_mesgs[outidx++] = mesg; - if (purge) { - /* we're taking this pointer away; subsequest history - updates will eventually allocate a new one to replace it */ - cw->data[inidx] = (char *) 0; - cw->datlen[inidx] = 0; - } - } - inidx = (inidx + 1) % cw->rows; - } - snapshot_mesgs[cw->rows] = (char *) 0; /* sentinel */ - - /* for a destructive snapshot, history is now completely empty */ - if (purge) - cw->maxcol = cw->maxrow = 0; -} - -/* release memory allocated to message history snapshot */ -STATIC_OVL void -free_msghistory_snapshot(purged) -boolean purged; /* True: took history's pointers, False: just cloned them */ -{ - if (snapshot_mesgs) { - /* snapshot pointers are no longer in use */ - if (purged) { - int i; - - for (i = 0; snapshot_mesgs[i]; ++i) - free((genericptr_t) snapshot_mesgs[i]); - } - - free((genericptr_t) snapshot_mesgs), snapshot_mesgs = (char **) 0; - - /* history can resume being updated at will now... */ - if (!purged) - wins[WIN_MESSAGE]->flags &= ~WIN_LOCKHISTORY; - } -} - STATIC_OVL ptr_array_t * get_message_history() { From fa5c499268f4f6b687a25a3004c47e5f5dc0a546 Mon Sep 17 00:00:00 2001 From: Bart House Date: Sun, 14 Jul 2019 14:31:30 -0700 Subject: [PATCH 4/4] Fix typo in formatting string. --- src/rnd.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/rnd.c b/src/rnd.c index 5473be949..02ffddce3 100644 --- a/src/rnd.c +++ b/src/rnd.c @@ -62,7 +62,7 @@ rul() unsigned long value; value = (unsigned long) isaac64_next_uint64(&rnglist[CORE].rng_state); - fuzzer_log(LOG_VERBOSE, "RANDOM:%llu\n", value); + fuzzer_log(LOG_VERBOSE, "RANDOM:%lu\n", value); return value; }