From a4317b738aeae6b8ed8d8e28d3dcb9e2c1282595 Mon Sep 17 00:00:00 2001 From: Bart House Date: Sun, 14 Jul 2019 21:09:07 -0700 Subject: [PATCH 01/25] Revert "Fix typo in formatting string." This reverts commit fa5c499268f4f6b687a25a3004c47e5f5dc0a546. --- src/rnd.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/rnd.c b/src/rnd.c index 02ffddce3..5473be949 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:%lu\n", value); + fuzzer_log(LOG_VERBOSE, "RANDOM:%llu\n", value); return value; } From 340ec01cafb931a38209d31df2c8512528853c0d Mon Sep 17 00:00:00 2001 From: Bart House Date: Sun, 14 Jul 2019 21:09:16 -0700 Subject: [PATCH 02/25] Revert "Remove dead code." This reverts commit 5428d73287d3e808f4480b04dc9733165dd32e83. --- win/tty/topl.c | 74 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 74 insertions(+) diff --git a/win/tty/topl.c b/win/tty/topl.c index df19eed7a..db151265f 100644 --- a/win/tty/topl.c +++ b/win/tty/topl.c @@ -17,6 +17,8 @@ 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() @@ -543,6 +545,78 @@ 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 a66fed3d5a140e873def653e84e6931441bad210 Mon Sep 17 00:00:00 2001 From: Bart House Date: Sun, 14 Jul 2019 21:09:29 -0700 Subject: [PATCH 03/25] Revert "Move fuzzer_start, fuzzer_stop and fuzzer_log to pline.c" This reverts commit d9da488c35de801fd651c3dd0ee8f152d5309337. --- include/extern.h | 6 ++--- src/allmain.c | 63 ++++++++++++++++++++++++++++++++++++++++++++---- src/pline.c | 57 ------------------------------------------- 3 files changed, 61 insertions(+), 65 deletions(-) diff --git a/include/extern.h b/include/extern.h index ba6164be2..3c74bfda0 100644 --- a/include/extern.h +++ b/include/extern.h @@ -27,7 +27,10 @@ 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 *)); @@ -1940,9 +1943,6 @@ 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 b834f0a8c..957c47a44 100644 --- a/src/allmain.c +++ b/src/allmain.c @@ -4,6 +4,7 @@ /* NetHack may be freely redistributed. See license for details. */ /* various code that was replicated in *main.c */ +#define NEED_VARARGS #include "hack.h" #include @@ -926,6 +927,38 @@ 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() @@ -936,6 +969,29 @@ 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. */ @@ -944,8 +1000,6 @@ fuzzer_check() { if (iflags.debug_fuzzer) { - unsigned long seed; - if (moves >= iflags.fuzzer_stop_and_save) { iflags.fuzzer_saving = TRUE; dosave0(); @@ -954,7 +1008,7 @@ fuzzer_check() nh_terminate(EXIT_SUCCESS); } - seed = rul(); + unsigned long seed = rul(); set_random(seed, rn2); fuzzer_log(LOG_MINIMAL, "SEED:%ld:%lu\n", moves, seed); @@ -968,10 +1022,9 @@ void fuzzer_auto_start() { if (iflags.fuzzer_auto_start) { - unsigned long seed; nhassert(!iflags.debug_fuzzer); fuzzer_start(); - seed = rul(); + unsigned long 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 03654355e..91e825963 100644 --- a/src/pline.c +++ b/src/pline.c @@ -599,61 +599,4 @@ 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 3adaa798582f02f646bc123f9f0166b752513f1e Mon Sep 17 00:00:00 2001 From: Bart House Date: Sun, 14 Jul 2019 21:09:38 -0700 Subject: [PATCH 04/25] Revert "Revert type change of lit which would break code." This reverts commit cc1219b5a8bae222a6ba6a0c755419c9ca200a79. --- 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 ba9d75c72..b2206ae70 100644 --- a/src/sp_lev.c +++ b/src/sp_lev.c @@ -3763,7 +3763,7 @@ struct opvar *mc; { int x, y; schar mapc; - xchar lit; + uchar 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 == (unsigned int) lit) + if (levl[x][y].lit == lit) selection_setpoint(x, y, ret, 1); break; } From 0f0b6c5aabd7a4559d78c104027aa14396fa1e32 Mon Sep 17 00:00:00 2001 From: Bart House Date: Sun, 14 Jul 2019 21:10:07 -0700 Subject: [PATCH 05/25] Revert "Tweaks to fuzzer scripts." This reverts commit cd375064ddbf70770a934820e37b796c4623a145. --- win/win32/scripts/fuzzer/longtest.bat | 13 ------------- win/win32/scripts/fuzzer/runtill.bat | 4 ---- 2 files changed, 17 deletions(-) diff --git a/win/win32/scripts/fuzzer/longtest.bat b/win/win32/scripts/fuzzer/longtest.bat index 64b6286bd..e5e8d1529 100644 --- a/win/win32/scripts/fuzzer/longtest.bat +++ b/win/win32/scripts/fuzzer/longtest.bat @@ -7,19 +7,6 @@ set STEP_SIZE=5000 set FINAL_MOVE=500000 set START_MOVE=5000 -set BIN_DIR=..\..\..\..\bin\Debug\Win32 -set SAVED_GAME=%USERNAME%-wizard.NetHack-saved-game -set LOG_FILE=%BIN_DIR%\runtil.log -set FUZZER_LOG=%BIN_DIR%\fuzzer.log -set FUZZER_DIR=%BIN_DIR%\fuzzer -set SAVE_DIR=%FUZZER_DIR%\save -set BASELINE=%FUZZER_DIR%\fuzzer.log - -if exist %FUZZER_DIR% rmdir /s /q %FUZZER_DIR% - -mkdir %FUZZER_DIR% -mkdir %SAVE_DIR% - for /L %%i in (%START_MOVE%, %STEP_SIZE%, %FINAL_MOVE%) do ( call runtill.bat %%i diff --git a/win/win32/scripts/fuzzer/runtill.bat b/win/win32/scripts/fuzzer/runtill.bat index cdbd954f3..ebb5aa4b6 100644 --- a/win/win32/scripts/fuzzer/runtill.bat +++ b/win/win32/scripts/fuzzer/runtill.bat @@ -18,11 +18,9 @@ set SAVED_GAME=%USERNAME%-wizard.NetHack-saved-game set LOG_FILE=%BIN_DIR%\runtil.log set FUZZER_LOG=%BIN_DIR%\fuzzer.log set FUZZER_DIR=%BIN_DIR%\fuzzer -set SAVE_DIR=%FUZZER_DIR%\save set BASELINE=%FUZZER_DIR%\fuzzer.log if not exist %FUZZER_DIR% mkdir %FUZZER_DIR% -if not exist %SAVE_DIR% mkdir %SAVE_DIR% call clean.bat @@ -30,7 +28,6 @@ if not exist %FUZZER_DIR%\%SAVED_GAME% ( %BIN_DIR%\nethack -D -F 0 copy %BIN_DIR%\%SAVED_GAME% %FUZZER_DIR% - copy %BIN_DIR%\%SAVED_GAME% %SAVE_DIR%\0.save ) call restore.bat @@ -71,7 +68,6 @@ if ERRORLEVEL 1 ( del /q %FUZZER_DIR%\%SAVED_GAME% copy %BIN_DIR%\%SAVED_GAME% %FUZZER_DIR% -copy %BIN_DIR%\%SAVED_GAME% %SAVE_DIR%\!STOP_MOVE!.save echo !START_MOVE! to !STOP_MOVE!. echo SUCCESS. From 5d2181ced35a19cca76b97d2cf11a0d84465100b Mon Sep 17 00:00:00 2001 From: Bart House Date: Sun, 14 Jul 2019 21:10:27 -0700 Subject: [PATCH 06/25] Revert "Fix build issue on linux." This reverts commit d33160d069c00e26de902e48c2bfda2de2eeeb3d. --- src/allmain.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/allmain.c b/src/allmain.c index 957c47a44..cde2ef9a2 100644 --- a/src/allmain.c +++ b/src/allmain.c @@ -4,7 +4,7 @@ /* NetHack may be freely redistributed. See license for details. */ /* various code that was replicated in *main.c */ -#define NEED_VARARGS + #include "hack.h" #include From 4c1c247028fb42eed9f9b460f5c75996a70a98a0 Mon Sep 17 00:00:00 2001 From: Bart House Date: Sun, 14 Jul 2019 21:10:39 -0700 Subject: [PATCH 07/25] Revert "Fuzzer improvements." This reverts commit 435f1c46267a194e44f0b75c7348be5a900d8ede. --- include/decl.h | 4 - include/extern.h | 9 -- include/flag.h | 4 - src/allmain.c | 131 -------------------------- src/hacklib.c | 12 +-- src/restore.c | 2 - src/rnd.c | 29 +----- src/save.c | 14 +-- sys/winnt/nttty.c | 10 +- sys/winnt/windmain.c | 19 +--- win/win32/scripts/fuzzer/clean.bat | 8 -- win/win32/scripts/fuzzer/longtest.bat | 23 ----- win/win32/scripts/fuzzer/restore.bat | 7 -- win/win32/scripts/fuzzer/runtill.bat | 73 -------------- 14 files changed, 8 insertions(+), 337 deletions(-) delete mode 100644 win/win32/scripts/fuzzer/clean.bat delete mode 100644 win/win32/scripts/fuzzer/longtest.bat delete mode 100644 win/win32/scripts/fuzzer/restore.bat delete mode 100644 win/win32/scripts/fuzzer/runtill.bat diff --git a/include/decl.h b/include/decl.h index 711ba614e..834b14ab8 100644 --- a/include/decl.h +++ b/include/decl.h @@ -462,10 +462,6 @@ struct ptr_array { }; typedef struct ptr_array ptr_array_t; -/* logging verbosity levels */ -#define LOG_MINIMAL 0 -#define LOG_VERBOSE 1 - #undef E #endif /* DECL_H */ diff --git a/include/extern.h b/include/extern.h index 3c74bfda0..d2ed2ff9e 100644 --- a/include/extern.h +++ b/include/extern.h @@ -27,13 +27,6 @@ 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 *)); /* ### apply.c ### */ @@ -957,7 +950,6 @@ E boolean FDECL(fuzzymatch, (const char *, const char *, const char *, BOOLEAN_P)); E void FDECL(init_random, (int FDECL((*fn), (int)))); E void FDECL(reseed_random, (int FDECL((*fn), (int)))); -E void FDECL(set_random, (unsigned long, int FDECL((*fn), (int)))); E time_t NDECL(getnow); E int NDECL(getyear); #if 0 @@ -2169,7 +2161,6 @@ E int FDECL(rnd, (int)); E int FDECL(d, (int, int)); E int FDECL(rne, (int)); E int FDECL(rnz, (int)); -E unsigned long NDECL(rul); /* ### role.c ### */ diff --git a/include/flag.h b/include/flag.h index 50f76c457..3ea3ada26 100644 --- a/include/flag.h +++ b/include/flag.h @@ -447,10 +447,6 @@ struct instance_flags { chosen_windowport[], but do not switch to it in the midst of options processing */ boolean obsolete; /* obsolete options can point at this, it isn't used */ - boolean fuzzer_auto_start; /* start fuzzer automatically */ - int fuzzer_stop_and_save; /* move when fuzzer stops and saves game */ - boolean fuzzer_saving; /* fuzzer is saving game */ - int verbose_logging_start; /* move when verbose fuzzer logging starts */ }; /* diff --git a/src/allmain.c b/src/allmain.c index cde2ef9a2..082447b3b 100644 --- a/src/allmain.c +++ b/src/allmain.c @@ -436,8 +436,6 @@ boolean resuming; #ifdef MAIL ckmailstatus(); #endif - fuzzer_check(); - rhack((char *) 0); } if (u.utotype) /* change dungeon level */ @@ -585,8 +583,6 @@ newgame() { int i; - fuzzer_auto_start(); - #ifdef MFLOPPY gameDiskPrompt(); #endif @@ -926,131 +922,4 @@ const char *opts; #endif 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() -{ - if (iflags.debug_fuzzer) - fuzzer_stop(); - else - 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. - */ -void -fuzzer_check() -{ - if (iflags.debug_fuzzer) - { - if (moves >= iflags.fuzzer_stop_and_save) { - iflags.fuzzer_saving = TRUE; - dosave0(); - exit_nhwindows("Goodbye from the fuzzer..."); - fuzzer_stop(); - nh_terminate(EXIT_SUCCESS); - } - - unsigned long seed = rul(); - set_random(seed, rn2); - fuzzer_log(LOG_MINIMAL, "SEED:%ld:%lu\n", moves, seed); - - } -} - -/* fuzzer_auto_start is called when creating a new game to allow - * the fuzzer to start itself. - */ -void -fuzzer_auto_start() -{ - if (iflags.fuzzer_auto_start) { - nhassert(!iflags.debug_fuzzer); - fuzzer_start(); - unsigned long seed = rul(); - set_random(seed, rn2); - fuzzer_log(LOG_MINIMAL, "START:%ld:%lu\n", moves, seed); - } -} - -/* fuzzer_msg_history is called during save file recovery to allow - * the fuzzer to snoop the messages being recovered. The fuzzer - * saves a seed as a message in save files and this is the mechanism - * used to recover that seed if the fuzzer is being auto started. - */ -boolean -fuzzer_msg_history(msg) - const char * msg; -{ - long saved_moves; - unsigned long saved_seed; - if (sscanf(msg, "SEED:%ld:%lu", &saved_moves, &saved_seed) == 2) { - nhassert(saved_moves == moves); - if (iflags.fuzzer_auto_start) { - fuzzer_start(); - set_random(saved_seed, rn2); - fuzzer_log(LOG_MINIMAL, "START:%ld:%lu\n", moves, saved_seed); - } - return TRUE; - } - - return FALSE; -} /*allmain.c*/ diff --git a/src/hacklib.c b/src/hacklib.c index 1f43325df..9fe316517 100644 --- a/src/hacklib.c +++ b/src/hacklib.c @@ -854,7 +854,7 @@ STATIC_DCL struct tm *NDECL(getlt); /* Sets the seed for the random number generator */ #ifdef USE_ISAAC64 -void +static void set_random(seed, fn) unsigned long seed; int FDECL((*fn), (int)); @@ -865,7 +865,7 @@ int FDECL((*fn), (int)); #else /* USE_ISAAC64 */ /*ARGSUSED*/ -void +static void set_random(seed, fn) unsigned long seed; int FDECL((*fn), (int)) UNUSED; @@ -917,7 +917,7 @@ int FDECL((*fn), (int)); { /* only reseed if we are certain that the seed generation is unguessable * by the players. */ - if (has_strong_rngseed && !iflags.debug_fuzzer) + if (has_strong_rngseed) init_random(fn); } @@ -1108,9 +1108,6 @@ phase_of_the_moon() /* 0-7, with 0: new, 4: full */ register struct tm *lt = getlt(); register int epact, diy, goldn; - if(iflags.debug_fuzzer) - return rn2(8); - diy = lt->tm_yday; goldn = (lt->tm_year % 19) + 1; epact = (11 * goldn + 18) % 30; @@ -1125,9 +1122,6 @@ friday_13th() { register struct tm *lt = getlt(); - if(iflags.debug_fuzzer) - return rn2(30); - /* tm_wday (day of week; 0==Sunday) == 5 => Friday */ return (boolean) (lt->tm_wday == 5 && lt->tm_mday == 13); } diff --git a/src/restore.c b/src/restore.c index 7d1f6d894..b6126a227 100644 --- a/src/restore.c +++ b/src/restore.c @@ -1231,8 +1231,6 @@ register int fd; panic("restore_msghistory: msg too big (%d)", msgsize); mread(fd, (genericptr_t) msg, msgsize); msg[msgsize] = '\0'; - if(fuzzer_msg_history(msg)) - continue; putmsghistory(msg, TRUE); ++msgcount; } diff --git a/src/rnd.c b/src/rnd.c index 5473be949..0ca649fbb 100644 --- a/src/rnd.c +++ b/src/rnd.c @@ -56,21 +56,10 @@ int FDECL((*fn), (int)); (int) sizeof seed); } -unsigned long -rul() -{ - unsigned long value; - - value = (unsigned long) isaac64_next_uint64(&rnglist[CORE].rng_state); - fuzzer_log(LOG_VERBOSE, "RANDOM:%llu\n", value); - - return value; -} - static int RND(int x) { - return (rul() % x); + return (isaac64_next_uint64(&rnglist[CORE].rng_state) % x); } /* 0 <= rn2(x) < x, but on a different sequence from the "main" rn2; @@ -80,8 +69,6 @@ int rn2_on_display_rng(x) register int x; { - if (iflags.debug_fuzzer) - return rn2(x); return (isaac64_next_uint64(&rnglist[DISP].rng_state) % x); } @@ -107,20 +94,6 @@ register int x; seed *= 2739110765; return (int)((seed >> 16) % (unsigned)x); } - -unsigned long -rul() -{ -#if defined(LINT) && defined(UNIX) - return (unsigned long) rand(); -#else /* LINT */ -#if defined(UNIX) || defined(RANDOM) - return (unsigned long) Rand(); -#else - return (unsigned long) (Rand() >> 3); -#endif /* defined(UNIX) || defined(RANDOM) */ -#endif /* LINT */ -} #endif /* USE_ISAAC64 */ /* 0 <= rn2(x) < x */ diff --git a/src/save.c b/src/save.c index e931eae76..e0af4b8d2 100644 --- a/src/save.c +++ b/src/save.c @@ -139,7 +139,7 @@ dosave0() return 0; #endif - HUP if (!iflags.debug_fuzzer && iflags.window_inited) { + HUP if (iflags.window_inited) { nh_uncompress(fq_save); fd = open_savefile(); if (fd > 0) { @@ -1238,18 +1238,6 @@ int fd, mode; bwrite(fd, (genericptr_t) msg, msglen); ++msgcount; } - /* If the fuzzer is stopping and saving, save a seed as a message. - In 3.7, we will modify the save file format and save the seed - directly in the saved game state. */ - if (iflags.fuzzer_saving) { - char message[BUFSIZ]; - unsigned long seed = rul(); - sprintf(message, "SEED:%ld:%lu", moves, seed); - fuzzer_log(LOG_MINIMAL, "STOP:%ld:%lu\n", moves, seed); - msglen = strlen(message); - bwrite(fd, (genericptr_t) &msglen, sizeof msglen); - bwrite(fd, (genericptr_t) message, msglen); - } bwrite(fd, (genericptr_t) &minusone, sizeof (int)); } debugpline1("Stored %d messages into savefile.", msgcount); diff --git a/sys/winnt/nttty.c b/sys/winnt/nttty.c index 4cca4dcbd..a8000bc05 100644 --- a/sys/winnt/nttty.c +++ b/sys/winnt/nttty.c @@ -475,14 +475,8 @@ int *x, *y, *mod; coord cc; DWORD count; really_move_cursor(); - if (iflags.debug_fuzzer) { - int poskey = randomkey(); - if (poskey == 0) { - *x = rn2(console.width); - *y = rn2(console.height); - } - return poskey; - } + if (iflags.debug_fuzzer) + return randomkey(); ch = (program_state.done_hup) ? '\033' : keyboard_handler.pCheckInput( diff --git a/sys/winnt/windmain.c b/sys/winnt/windmain.c index d1712ffe4..b2bb18e79 100644 --- a/sys/winnt/windmain.c +++ b/sys/winnt/windmain.c @@ -336,7 +336,7 @@ attempt_restore: resuming = TRUE; /* not starting new game */ if (discover) You("are in non-scoring discovery mode."); - if ((discover || wizard) && !iflags.fuzzer_auto_start) { + if (discover || wizard) { if (yn("Do you want to keep the save file?") == 'n') (void) delete_savefile(); else { @@ -461,23 +461,6 @@ char *argv[]; case 'X': discover = TRUE, wizard = FALSE; break; - case 'F': - { - iflags.fuzzer_auto_start = 1; - - if (argc > 1 && argv[1][0] != '-') { - argc--; - argv++; - iflags.fuzzer_stop_and_save = atoi(*argv); - - if (argc > 1 && argv[1][0] != '-') { - argc--; - argv++; - iflags.verbose_logging_start = atoi(*argv); - } - } - } - break; #ifdef NEWS case 'n': iflags.news = FALSE; diff --git a/win/win32/scripts/fuzzer/clean.bat b/win/win32/scripts/fuzzer/clean.bat deleted file mode 100644 index a02c48739..000000000 --- a/win/win32/scripts/fuzzer/clean.bat +++ /dev/null @@ -1,8 +0,0 @@ -set BIN_DIR=..\..\..\..\bin\Debug\Win32 - -set FUZZER_LOG=%BIN_DIR%\fuzzer.log -set FUZZER_DIR=%BIN_DIR%\fuzzer - -if exist %BIN_DIR%\%USERNAME%* del %BIN_DIR%\%USERNAME%* -if exist %FUZZER_LOG% del %FUZZER_LOG% - diff --git a/win/win32/scripts/fuzzer/longtest.bat b/win/win32/scripts/fuzzer/longtest.bat deleted file mode 100644 index e5e8d1529..000000000 --- a/win/win32/scripts/fuzzer/longtest.bat +++ /dev/null @@ -1,23 +0,0 @@ -echo off - -SETLOCAL ENABLEEXTENSIONS -SETLOCAL ENABLEDELAYEDEXPANSION - -set STEP_SIZE=5000 -set FINAL_MOVE=500000 -set START_MOVE=5000 - -for /L %%i in (%START_MOVE%, %STEP_SIZE%, %FINAL_MOVE%) do ( - - call runtill.bat %%i - - if ERRORLEVEL 1 ( - echo FAILED getting running to %%i. - exit /b 1 - ) - -) - -echo SUCCESS. - - diff --git a/win/win32/scripts/fuzzer/restore.bat b/win/win32/scripts/fuzzer/restore.bat deleted file mode 100644 index 9752fed96..000000000 --- a/win/win32/scripts/fuzzer/restore.bat +++ /dev/null @@ -1,7 +0,0 @@ -call clean.bat - -set BIN_DIR=..\..\..\..\bin\Debug\Win32 -set SAVED_GAME=%USERNAME%-wizard.NetHack-saved-game -set FUZZER_DIR=%BIN_DIR%\fuzzer - -copy %FUZZER_DIR%\%SAVED_GAME% %BIN_DIR%\%SAVED_GAME% diff --git a/win/win32/scripts/fuzzer/runtill.bat b/win/win32/scripts/fuzzer/runtill.bat deleted file mode 100644 index ebb5aa4b6..000000000 --- a/win/win32/scripts/fuzzer/runtill.bat +++ /dev/null @@ -1,73 +0,0 @@ -REM -REM runtill target_move -REM -echo off - -SETLOCAL ENABLEEXTENSIONS -SETLOCAL ENABLEDELAYEDEXPANSION - -set TARGET_MOVE=%1 - -if %TARGET_MOVE% == "" ( - echo Usage:runtill target_move - goto :eof -) - -set BIN_DIR=..\..\..\..\bin\Debug\Win32 -set SAVED_GAME=%USERNAME%-wizard.NetHack-saved-game -set LOG_FILE=%BIN_DIR%\runtil.log -set FUZZER_LOG=%BIN_DIR%\fuzzer.log -set FUZZER_DIR=%BIN_DIR%\fuzzer -set BASELINE=%FUZZER_DIR%\fuzzer.log - -if not exist %FUZZER_DIR% mkdir %FUZZER_DIR% - -call clean.bat - -if not exist %FUZZER_DIR%\%SAVED_GAME% ( - %BIN_DIR%\nethack -D -F 0 - - copy %BIN_DIR%\%SAVED_GAME% %FUZZER_DIR% -) - -call restore.bat - -%BIN_DIR%\nethack -D -F %TARGET_MOVE% - -move %BIN_DIR%\*.snap %BIN_DIR%\snapshots -copy %FUZZER_LOG% %BASELINE% - -for /f "tokens=2,3 delims=: usebackq" %%i in (`findstr /c:START %BASELINE%`) do ( - set START_SEED=%%j - set START_MOVE=%%i -) - -for /f "tokens=2,3 delims=: usebackq" %%i in (`findstr /c:STOP %BASELINE%`) do ( - set STOP_SEED=%%j - set STOP_MOVE=%%i -) - -if !STOP_MOVE! LSS %TARGET_MOVE% ( - cls - echo FAILED: Failed to reach target move. !STOP_MOVE! is not GTE %TARGET_MOVE%. - exit /b 1 -) - -call restore.bat - -%BIN_DIR%\nethack -D -F %TARGET_MOVE% - -fc %FUZZER_LOG% %BASELINE% - -if ERRORLEVEL 1 ( - cls - echo FAILED: Unable to reproduce same timeline - exit /b 1 -) - -del /q %FUZZER_DIR%\%SAVED_GAME% - -copy %BIN_DIR%\%SAVED_GAME% %FUZZER_DIR% - -echo !START_MOVE! to !STOP_MOVE!. -echo SUCCESS. From 454419e6c10a8dc8d220d3615a8554f27eeb217b Mon Sep 17 00:00:00 2001 From: Bart House Date: Sun, 14 Jul 2019 21:10:51 -0700 Subject: [PATCH 08/25] Revert "Removed the older version of tty_putmsghistory and tty_getmsghistory." This reverts commit aa95e20ca7cbb2a90f8076f04410886c0733dc74. --- win/tty/topl.c | 110 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 110 insertions(+) diff --git a/win/tty/topl.c b/win/tty/topl.c index db151265f..b19bc0700 100644 --- a/win/tty/topl.c +++ b/win/tty/topl.c @@ -617,6 +617,115 @@ boolean purged; /* True: took history's pointers, False: just cloned them */ } } +#if 0 +/* + * This is called by the core save routines. + * Each time we are called, we return one string from the + * message history starting with the oldest message first. + * When none are left, we return a final null string. + * + * History is collected at the time of the first call. + * Any new messages issued after that point will not be + * included among the output of the subsequent calls. + */ +char * +tty_getmsghistory(init) +boolean init; +{ + static int nxtidx; + char *nextmesg; + char *result = 0; + + if (init) { + msghistory_snapshot(FALSE); + nxtidx = 0; + } + + if (snapshot_mesgs) { + nextmesg = snapshot_mesgs[nxtidx++]; + if (nextmesg) { + result = (char *) nextmesg; + } else { + free_msghistory_snapshot(FALSE); + } + } + return result; +} + +/* + * This is called by the core savefile restore routines. + * Each time we are called, we stuff the string into our message + * history recall buffer. The core will send the oldest message + * first (actually it sends them in the order they exist in the + * save file, but that is supposed to be the oldest first). + * These messages get pushed behind any which have been issued + * since this session with the program has been started, since + * they come from a previous session and logically precede + * anything (like "Restoring save file...") that's happened now. + * + * Called with a null pointer to finish up restoration. + * + * It's also called by the quest pager code when a block message + * has a one-line summary specified. We put that line directly + * into message history for ^P recall without having displayed it. + */ +void +tty_putmsghistory(msg, restoring_msghist) +const char *msg; +boolean restoring_msghist; +{ + static boolean initd = FALSE; + int idx; +#ifdef DUMPLOG + extern unsigned saved_pline_index; /* pline.c */ +#endif + + if (restoring_msghist && !initd) { + /* we're restoring history from the previous session, but new + messages have already been issued this session ("Restoring...", + for instance); collect current history (ie, those new messages), + and also clear it out so that nothing will be present when the + restored ones are being put into place */ + msghistory_snapshot(TRUE); + initd = TRUE; +#ifdef DUMPLOG + /* this suffices; there's no need to scrub saved_pline[] pointers */ + saved_pline_index = 0; +#endif + } + + if (msg) { + /* Caller is asking us to remember a top line that needed more. + Should we call more? This can happen when the player has set + iflags.force_invmenu and they attempt to shoot with nothing in + the quiver. */ + if (ttyDisplay && ttyDisplay->toplin == TOPLINE_NEED_MORE) + ttyDisplay->toplin = TOPLINE_NON_EMPTY; + + /* move most recent message to history, make this become most recent */ + remember_topl(); + Strcpy(toplines, msg); +#ifdef DUMPLOG + dumplogmsg(toplines); +#endif + } else if (snapshot_mesgs) { + nhassert(ttyDisplay == NULL || + ttyDisplay->toplin != TOPLINE_NEED_MORE); + + /* done putting arbitrary messages in; put the snapshot ones back */ + for (idx = 0; snapshot_mesgs[idx]; ++idx) { + remember_topl(); + Strcpy(toplines, snapshot_mesgs[idx]); +#ifdef DUMPLOG + dumplogmsg(toplines); +#endif + } + /* now release the snapshot */ + free_msghistory_snapshot(TRUE); + initd = FALSE; /* reset */ + } +} +#else STATIC_OVL ptr_array_t * get_message_history() { @@ -810,6 +919,7 @@ boolean restoring_msghist; } } +#endif #endif /* TTY_GRAPHICS */ From 9bc190d2fcf9463b17c65d19fe0b242d3c5afa2a Mon Sep 17 00:00:00 2001 From: Bart House Date: Sun, 14 Jul 2019 21:11:41 -0700 Subject: [PATCH 09/25] Revert "Add stopping in the debugger when nhassert() is hit in the windows port." This reverts commit 5d2872dd4f24fb76f29bf34f6f950394910d6d33. --- sys/winnt/winnt.c | 12 +----------- 1 file changed, 1 insertion(+), 11 deletions(-) diff --git a/sys/winnt/winnt.c b/sys/winnt/winnt.c index 39978cab4..8d513c59e 100644 --- a/sys/winnt/winnt.c +++ b/sys/winnt/winnt.c @@ -718,19 +718,9 @@ nt_assert_failed(expression, filepath, line) { const char * filename; + /* get file name from path */ filename = strrchr(filepath, '\\'); filename = (filename == NULL ? filepath : filename + 1); - - if (IsDebuggerPresent()) { - char message[BUFSIZ]; - snprintf(message, sizeof(message), - "nhassert(%s) failed in file '%s' at line %d", - expression, filename, line); - OutputDebugStringA(message); - DebugBreak(); - } - - /* get file name from path */ impossible("nhassert(%s) failed in file '%s' at line %d", expression, filename, line); } From 1c5b28e7f9a23707a60b7e952ee61b43e9d548a2 Mon Sep 17 00:00:00 2001 From: Bart House Date: Sun, 14 Jul 2019 21:12:21 -0700 Subject: [PATCH 10/25] Revert "Re-worked tty_putmsgistory and tty_getmsghistory." This reverts commit 1d0b8b4680512a85a045006b3adf7fe65100f1bd. --- win/tty/topl.c | 196 ------------------------------------------------- 1 file changed, 196 deletions(-) diff --git a/win/tty/topl.c b/win/tty/topl.c index b19bc0700..74331dece 100644 --- a/win/tty/topl.c +++ b/win/tty/topl.c @@ -617,7 +617,6 @@ boolean purged; /* True: took history's pointers, False: just cloned them */ } } -#if 0 /* * This is called by the core save routines. * Each time we are called, we return one string from the @@ -725,201 +724,6 @@ boolean restoring_msghist; initd = FALSE; /* reset */ } } -#else -STATIC_OVL ptr_array_t * -get_message_history() -{ - char *mesg; - int i; - struct WinDesc *cw; - size_t max_length; - ptr_array_t * a; - - nhassert(WIN_MESSAGE != WIN_ERR); - nhassert(wins[WIN_MESSAGE] != NULL); - - /* paranoia (too early or too late panic save attempt?) */ - if (WIN_MESSAGE == WIN_ERR || !wins[WIN_MESSAGE]) - return NULL; - - cw = wins[WIN_MESSAGE]; - - max_length = cw->rows; - - if (*toplines) max_length++; - - a = ptr_array_new(max_length); - - nhassert(cw->maxrow <= cw->rows); - for (i = 0; i < cw->rows; ++i) { - mesg = cw->data[(i + cw->maxrow) % cw->rows]; - if (mesg && *mesg) - a->elements[a->length++] = strdup(mesg); - } - if (*toplines) - a->elements[a->length++] = strdup(toplines); - - return a; -} - -STATIC_OVL void -purge_message_history() -{ - int i; - struct WinDesc *cw; - - nhassert(WIN_MESSAGE != WIN_ERR); - nhassert(wins[WIN_MESSAGE] != NULL); - - cw = wins[WIN_MESSAGE]; - - *toplines = '\0'; - - for (i = 0; i < cw->rows; ++i) { - if (cw->data[i]) { - free(cw->data[i]); - cw->data[i] = (char *) 0; - cw->datlen[i] = 0; - } - } - - cw->maxcol = cw->maxrow = 0; -} - -/* - * This is called by the core save routines. - * Each time we are called, we return one string from the - * message history starting with the oldest message first. - * When none are left, we return a final null string. - * - * History is collected at the time of the first call. - * Any new messages issued after that point will not be - * included among the output of the subsequent calls. - */ -char * -tty_getmsghistory(init) -boolean init; -{ - static size_t nxtidx; - static ptr_array_t * saved_messages = NULL; - char *result = NULL; - - if (init) { - nhassert(saved_messages == NULL); - saved_messages = get_message_history(); - nxtidx = 0; - wins[WIN_MESSAGE]->flags |= WIN_LOCKHISTORY; - } - - if (saved_messages) { - if (nxtidx < saved_messages->length) - result = saved_messages->elements[nxtidx++]; - - if (result == NULL) { - ptr_array_free(saved_messages); - saved_messages = NULL; - wins[WIN_MESSAGE]->flags &= ~WIN_LOCKHISTORY; - } - } - return result; -} - -/* - * This is called by the core savefile restore routines. - * Each time we are called, we stuff the string into our message - * history recall buffer. The core will send the oldest message - * first (actually it sends them in the order they exist in the - * save file, but that is supposed to be the oldest first). - * These messages get pushed behind any which have been issued - * since this session with the program has been started, since - * they come from a previous session and logically precede - * anything (like "Restoring save file...") that's happened now. - * - * Called with a null pointer to finish up restoration. - * - * It's also called by the quest pager code when a block message - * has a one-line summary specified. We put that line directly - * into message history for ^P recall without having displayed it. - */ -void -tty_putmsghistory(msg, restoring_msghist) -const char *msg; -boolean restoring_msghist; -{ - static boolean initd = FALSE; - static ptr_array_t * saved_messages = NULL; - size_t i; -#ifdef DUMPLOG - extern unsigned saved_pline_index; /* pline.c */ -#endif - - nhassert(!(wins[WIN_MESSAGE]->flags & WIN_LOCKHISTORY)); - - if (restoring_msghist && !initd) { - /* we're restoring history from the previous session, but new - messages have already been issued this session ("Restoring...", - for instance); collect current history (ie, those new messages), - and also clear it out so that nothing will be present when the - restored ones are being put into place */ - nhassert(saved_messages == NULL); - saved_messages = get_message_history(); - purge_message_history(); - initd = TRUE; -#ifdef DUMPLOG - /* this suffices; there's no need to scrub saved_pline[] pointers */ - saved_pline_index = 0; -#endif - } - - if (msg) { - /* Caller is asking us to remember a top line that needed more. - Should we call more? This can happen when the player has set - iflags.force_invmenu and they attempt to shoot with nothing in - the quiver. */ - if (ttyDisplay && ttyDisplay->toplin == TOPLINE_NEED_MORE) - ttyDisplay->toplin = TOPLINE_NON_EMPTY; - - /* move most recent message to history, make this become most recent */ - remember_topl(); - Strcpy(toplines, msg); -#ifdef DUMPLOG - dumplogmsg(toplines); -#endif - return; - } - - /* tty_putmsghistory() is called with msg==NULL to indidate that - * we are finished restoring the message history. If we saved - * some message history when we started, its time now to appened - * those saved messages. - * - * We don't otherwise expect to get called with msg==NULL. - * - */ - nhassert(restoring_msghist && initd); - - if (initd && restoring_msghist) { - if (saved_messages) { - nhassert(ttyDisplay == NULL || - ttyDisplay->toplin != TOPLINE_NEED_MORE); - - for (i = 0; ilength; i++) { - const char * mesg = saved_messages->elements[i]; - remember_topl(); - nhassert(mesg); - Strcpy(toplines, mesg); -#ifdef DUMPLOG - dumplogmsg(toplines); -#endif - } - ptr_array_free(saved_messages); - saved_messages = NULL; - } - initd = FALSE; - } - -} -#endif #endif /* TTY_GRAPHICS */ From f7c956c35a20b0c316e3268762be991cb70c37dc Mon Sep 17 00:00:00 2001 From: Bart House Date: Sun, 14 Jul 2019 21:12:59 -0700 Subject: [PATCH 11/25] Revert "Adding ptr_array data structure." This reverts commit e665d3b85024e3a7580e80888a70b47d5ae9384c. --- include/decl.h | 7 ------- include/extern.h | 2 -- src/hacklib.c | 34 ---------------------------------- 3 files changed, 43 deletions(-) diff --git a/include/decl.h b/include/decl.h index 834b14ab8..5ebaa326e 100644 --- a/include/decl.h +++ b/include/decl.h @@ -455,13 +455,6 @@ struct early_opt { boolean valallowed; }; -struct ptr_array { - size_t length; - size_t max_length; - void ** elements; -}; -typedef struct ptr_array ptr_array_t; - #undef E #endif /* DECL_H */ diff --git a/include/extern.h b/include/extern.h index d2ed2ff9e..abea20a68 100644 --- a/include/extern.h +++ b/include/extern.h @@ -968,8 +968,6 @@ E void FDECL(strbuf_append, (strbuf_t *, const char *)); E void FDECL(strbuf_reserve, (strbuf_t *, int)); E void FDECL(strbuf_empty, (strbuf_t *)); E void FDECL(strbuf_nl_to_crlf, (strbuf_t *)); -E struct ptr_array * FDECL(ptr_array_new, (size_t length)); -E void FDECL(ptr_array_free, (struct ptr_array *)); /* ### invent.c ### */ diff --git a/src/hacklib.c b/src/hacklib.c index 9fe316517..b97a78a65 100644 --- a/src/hacklib.c +++ b/src/hacklib.c @@ -1223,38 +1223,4 @@ strbuf_t *strbuf; } } -ptr_array_t * -ptr_array_new(max_length) - size_t max_length; -{ - size_t esize = max_length * sizeof(void *); - ptr_array_t * a = (ptr_array_t *) malloc(sizeof(ptr_array_t) + esize); - a->elements = (void **)(a + 1); - a->length = 0; - a->max_length = max_length; - memset(a->elements, 0, esize); - return a; -} - -void -ptr_array_free(a) - ptr_array_t * a; -{ - size_t i; - - nhassert(a->length <= a->max_length); - - for(i = 0; i < a->length; i++) - if(a->elements[i]) - free(a->elements[i]); - - for (i = a->length; i < a->max_length; i++) { - nhassert(a->elements[i] == NULL); - if(a->elements[i]) - free(a->elements[i]); - } - - free(a); -} - /*hacklib.c*/ From 2df1b179ca0498b4a4fe2d3996a4f4282c13ef93 Mon Sep 17 00:00:00 2001 From: Bart House Date: Sun, 14 Jul 2019 21:13:18 -0700 Subject: [PATCH 12/25] Revert "Removing assertion that does not hold under all scenarios." This reverts commit c44ad5645d90267e7ed1d1a6c57acc1437dca10e. --- win/tty/topl.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/win/tty/topl.c b/win/tty/topl.c index 74331dece..cfd17838d 100644 --- a/win/tty/topl.c +++ b/win/tty/topl.c @@ -259,7 +259,7 @@ register const char *bp; && cw->cury == 0 && n0 + (int) strlen(toplines) + 3 < CO - 8 /* room for --More-- */ && (notdied = strncmp(bp, "You die", 7)) != 0) { - /* nhassert((long) strlen(toplines) == cw->curx); */ + nhassert((long) strlen(toplines) == cw->curx); Strcat(toplines, " "); Strcat(toplines, bp); cw->curx += 2; From ec05e1ec70f956cecdf23ebfefc81ef2f22f8ce8 Mon Sep 17 00:00:00 2001 From: Bart House Date: Sun, 14 Jul 2019 21:13:43 -0700 Subject: [PATCH 13/25] Revert "Fix compiler warnings." This reverts commit 90f5aa91b794ad333fc04693677d0a7a9d8ca18e. --- src/dungeon.c | 3 +-- src/sp_lev.c | 2 +- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/src/dungeon.c b/src/dungeon.c index 0e483a11d..27b748104 100644 --- a/src/dungeon.c +++ b/src/dungeon.c @@ -2409,8 +2409,7 @@ recalc_mapseen() struct monst *mtmp; struct cemetery *bp, **bonesaddr; unsigned i, ridx; - int x, y, ltyp, count; - unsigned int atmp; + int x, y, ltyp, count, atmp; /* Should not happen in general, but possible if in the process * of being booted from the quest. The mapseen object gets diff --git a/src/sp_lev.c b/src/sp_lev.c index b2206ae70..dbab1dfdc 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) From 177bd39646bcfbdcf9c10783fc9066ff15631464 Mon Sep 17 00:00:00 2001 From: Bart House Date: Sun, 14 Jul 2019 21:15:01 -0700 Subject: [PATCH 14/25] Revert "Tweaks to nhassert implementation. Change to warnings on MSC build." This reverts commit 2f3da35c6893d2a44e8281ae209f00d54eefa2f2. --- include/extern.h | 2 +- include/global.h | 2 +- include/ntconf.h | 12 ------------ src/pline.c | 15 ++------------- sys/winnt/winnt.c | 17 ----------------- 5 files changed, 4 insertions(+), 44 deletions(-) diff --git a/include/extern.h b/include/extern.h index abea20a68..5812366f2 100644 --- a/include/extern.h +++ b/include/extern.h @@ -1932,7 +1932,7 @@ E void VDECL(verbalize, (const char *, ...)) PRINTF_F(1, 2); 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 FDECL(nhassert_failed, (const char *, const char *, int)); /* ### polyself.c ### */ diff --git a/include/global.h b/include/global.h index 1bcc2ae5d..ada34523c 100644 --- a/include/global.h +++ b/include/global.h @@ -378,7 +378,7 @@ struct savefile_info { /* Supply nhassert macro if not supplied by port */ #ifndef nhassert #define nhassert(expression) (void)((!!(expression)) || \ - (nhassert_failed(__FILE__, __LINE__), 0)) + (nhassert_failed(#expression, __FILE__, __LINE__), 0)) #endif #endif /* GLOBAL_H */ diff --git a/include/ntconf.h b/include/ntconf.h index 0c76ed718..62c269bab 100644 --- a/include/ntconf.h +++ b/include/ntconf.h @@ -134,8 +134,6 @@ extern void NDECL(getlock); #ifndef HAS_STDINT_H #define HAS_STDINT_H /* force include of stdint.h in integer.h */ #endif -/* Turn on some additional warnings */ -#pragma warning(3:4389) #endif /* _MSC_VER */ /* The following is needed for prototypes of certain functions */ @@ -272,14 +270,4 @@ extern int FDECL(alternative_palette, (char *)); #define nethack_enter(argc, argv) nethack_enter_winnt() extern void FDECL(nethack_exit, (int)) NORETURN; extern boolean FDECL(file_exists, (const char *)); - -/* Override the default version of nhassert. The default version is unable - * to generate a string form of the expression due to the need to be - * compatible with compilers which do not support macro stringization (i.e. - * #x to turn x into its string form). - */ -extern void FDECL(nt_assert_failed, (const char *, const char *, int)); -#define nhassert(expression) (void)((!!(expression)) || \ - (nt_assert_failed(#expression, __FILE__, __LINE__), 0)) - #endif /* NTCONF_H */ diff --git a/src/pline.c b/src/pline.c index 91e825963..535b75e95 100644 --- a/src/pline.c +++ b/src/pline.c @@ -583,20 +583,9 @@ VA_DECL(const char *, str) } /* nhassert_failed is called when an nhassert's condition is false */ -void -nhassert_failed(filepath, line) - const char * filepath; - int line; +void nhassert_failed(const char * exp, const char * file, int line) { - const char * filename; - - /* attempt to get filename from path. TODO: we really need a port provided - * function to return a filename from a path */ - filename = strrchr(filepath, '/'); - filename = (filename == NULL ? strrchr(filepath, '\\') : filename); - filename = (filename == NULL ? filepath : filename + 1); - - impossible("nhassert failed in file '%s' at line %d", filename, line); + impossible("NHASSERT(%s) in '%s' at line %d", exp, file, line); } /*pline.c*/ diff --git a/sys/winnt/winnt.c b/sys/winnt/winnt.c index 8d513c59e..0e19e1f76 100644 --- a/sys/winnt/winnt.c +++ b/sys/winnt/winnt.c @@ -708,23 +708,6 @@ sys_random_seed(VOID_ARGS) } return ourseed; } - -/* nt_assert_failed is called when an nhassert's condition is false */ -void -nt_assert_failed(expression, filepath, line) - const char * expression; - const char * filepath; - int line; -{ - const char * filename; - - /* get file name from path */ - filename = strrchr(filepath, '\\'); - filename = (filename == NULL ? filepath : filename + 1); - impossible("nhassert(%s) failed in file '%s' at line %d", - expression, filename, line); -} - #endif /* WIN32 */ /*winnt.c*/ From a90f9d4365802b0ead7f41b8cffb69e70aaaf676 Mon Sep 17 00:00:00 2001 From: Bart House Date: Sun, 14 Jul 2019 21:15:31 -0700 Subject: [PATCH 15/25] Revert "Fixed sign/unsigned comparisions." This reverts commit 0e8e5aac93e660a001dccb66df7320023aaa36de. --- src/teleport.c | 4 ++-- win/tty/topl.c | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/teleport.c b/src/teleport.c index 0c8271845..100a74d3b 100644 --- a/src/teleport.c +++ b/src/teleport.c @@ -1143,10 +1143,10 @@ struct monst *mtmp; sent out of his room (caller might resort to goodpos() if we report failure here, so this isn't full prevention) */ if (mtmp->isshk && inhishop(mtmp)) { - if (levl[x][y].roomno != (unsigned char) ESHK(mtmp)->shoproom) + if (levl[x][y].roomno != ESHK(mtmp)->shoproom) return FALSE; } else if (mtmp->ispriest && inhistemple(mtmp)) { - if (levl[x][y].roomno != (unsigned char) EPRI(mtmp)->shroom) + if (levl[x][y].roomno != EPRI(mtmp)->shroom) return FALSE; } /* current location is */ diff --git a/win/tty/topl.c b/win/tty/topl.c index cfd17838d..bb79be26c 100644 --- a/win/tty/topl.c +++ b/win/tty/topl.c @@ -259,7 +259,7 @@ register const char *bp; && cw->cury == 0 && n0 + (int) strlen(toplines) + 3 < CO - 8 /* room for --More-- */ && (notdied = strncmp(bp, "You die", 7)) != 0) { - nhassert((long) strlen(toplines) == cw->curx); + nhassert(strlen(toplines) == cw->curx); Strcat(toplines, " "); Strcat(toplines, bp); cw->curx += 2; From fe9fc4cac15002a28af608e96045d0332c68f95a Mon Sep 17 00:00:00 2001 From: Bart House Date: Sun, 14 Jul 2019 21:15:54 -0700 Subject: [PATCH 16/25] Revert "Added nhassert to core." This reverts commit 0ca299acb3b52c90e65ad3ca3eb69ccfa8cceb97. --- include/extern.h | 1 - include/global.h | 5 ----- include/ntconf.h | 10 ++++++++++ src/pline.c | 6 ------ sys/winnt/winnt.c | 10 ++++++++++ win/tty/topl.c | 8 ++++---- win/tty/wintty.c | 6 +++--- 7 files changed, 27 insertions(+), 19 deletions(-) diff --git a/include/extern.h b/include/extern.h index 5812366f2..0761d224e 100644 --- a/include/extern.h +++ b/include/extern.h @@ -1932,7 +1932,6 @@ E void VDECL(verbalize, (const char *, ...)) PRINTF_F(1, 2); 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 *, const char *, int)); /* ### polyself.c ### */ diff --git a/include/global.h b/include/global.h index ada34523c..6e0f96ebf 100644 --- a/include/global.h +++ b/include/global.h @@ -375,10 +375,5 @@ struct savefile_info { #define nethack_enter(argc, argv) ((void) 0) #endif -/* Supply nhassert macro if not supplied by port */ -#ifndef nhassert -#define nhassert(expression) (void)((!!(expression)) || \ - (nhassert_failed(#expression, __FILE__, __LINE__), 0)) -#endif #endif /* GLOBAL_H */ diff --git a/include/ntconf.h b/include/ntconf.h index 62c269bab..9d79006f0 100644 --- a/include/ntconf.h +++ b/include/ntconf.h @@ -267,6 +267,16 @@ extern int FDECL(set_win32_option, (const char *, const char *)); extern int FDECL(alternative_palette, (char *)); #endif +#ifdef NDEBUG +#define nhassert(expression) ((void)0) +#else +extern void FDECL(nhassert_failed, (const char * exp, const char * file, + int line)); + +#define nhassert(expression) (void)((!!(expression)) || \ + (nhassert_failed(#expression, __FILE__, __LINE__), 0)) +#endif + #define nethack_enter(argc, argv) nethack_enter_winnt() extern void FDECL(nethack_exit, (int)) NORETURN; extern boolean FDECL(file_exists, (const char *)); diff --git a/src/pline.c b/src/pline.c index 535b75e95..d7db3f43d 100644 --- a/src/pline.c +++ b/src/pline.c @@ -582,10 +582,4 @@ VA_DECL(const char *, str) #endif } -/* nhassert_failed is called when an nhassert's condition is false */ -void nhassert_failed(const char * exp, const char * file, int line) -{ - impossible("NHASSERT(%s) in '%s' at line %d", exp, file, line); -} - /*pline.c*/ diff --git a/sys/winnt/winnt.c b/sys/winnt/winnt.c index 0e19e1f76..d54982975 100644 --- a/sys/winnt/winnt.c +++ b/sys/winnt/winnt.c @@ -475,6 +475,16 @@ char *buf; } #endif /* RUNTIME_PORT_ID */ +/* nhassert_failed is called when an nhassert's condition is false */ +void nhassert_failed(const char * exp, const char * file, int line) +{ + char message[BUFSZ]; + snprintf(message, sizeof(message), + "NHASSERT(%s) in '%s' at line %d", exp, file, line); + + impossible(message); +} + void nethack_exit(code) int code; diff --git a/win/tty/topl.c b/win/tty/topl.c index bb79be26c..14e9bc548 100644 --- a/win/tty/topl.c +++ b/win/tty/topl.c @@ -259,7 +259,7 @@ register const char *bp; && cw->cury == 0 && n0 + (int) strlen(toplines) + 3 < CO - 8 /* room for --More-- */ && (notdied = strncmp(bp, "You die", 7)) != 0) { - nhassert(strlen(toplines) == cw->curx); + /* nhassert(strlen(toplines) == cw->curx); */ Strcat(toplines, " "); Strcat(toplines, bp); cw->curx += 2; @@ -313,7 +313,7 @@ char c; if (ttyDisplay->curx == 0 && ttyDisplay->cury > 0) tty_curs(BASE_WINDOW, CO, (int) ttyDisplay->cury - 1); backsp(); - nhassert(ttyDisplay->curx > 0); + /* nhassert(ttyDisplay->curx > 0); */ ttyDisplay->curx--; cw->curx = ttyDisplay->curx; return; @@ -708,8 +708,8 @@ boolean restoring_msghist; dumplogmsg(toplines); #endif } else if (snapshot_mesgs) { - nhassert(ttyDisplay == NULL || - ttyDisplay->toplin != TOPLINE_NEED_MORE); + /* nhassert(ttyDisplay == NULL || + ttyDisplay->toplin != TOPLINE_NEED_MORE); */ /* done putting arbitrary messages in; put the snapshot ones back */ for (idx = 0; snapshot_mesgs[idx]; ++idx) { diff --git a/win/tty/wintty.c b/win/tty/wintty.c index 63861d62b..6d5042f8e 100644 --- a/win/tty/wintty.c +++ b/win/tty/wintty.c @@ -2321,7 +2321,7 @@ boolean blocking; /* with ttys, all windows are blocking */ more(); ttyDisplay->toplin = TOPLINE_NEED_MORE; /* more resets this */ tty_clear_nhwindow(window); - nhassert(ttyDisplay->toplin == TOPLINE_EMPTY); + /* nhassert(ttyDisplay->toplin == TOPLINE_EMPTY); */ } else ttyDisplay->toplin = TOPLINE_EMPTY; cw->curx = cw->cury = 0; @@ -2409,7 +2409,7 @@ winid window; case NHW_MESSAGE: if (ttyDisplay->toplin != TOPLINE_EMPTY) tty_display_nhwindow(WIN_MESSAGE, TRUE); - nhassert(ttyDisplay->toplin == TOPLINE_EMPTY); + /* nhassert(ttyDisplay->toplin == TOPLINE_EMPTY); */ /*FALLTHRU*/ case NHW_STATUS: case NHW_BASE: @@ -3164,7 +3164,7 @@ const char *mesg; more(); ttyDisplay->toplin = TOPLINE_NEED_MORE; /* more resets this */ tty_clear_nhwindow(WIN_MESSAGE); - nhassert(ttyDisplay->toplin == TOPLINE_EMPTY); + /* nhassert(ttyDisplay->toplin == TOPLINE_EMPTY); */ } /* normally means skip further messages, but in this case it means cancel the current prompt; any other messages should From 04f4ac94cabb85b785e7544352ccbe6f167b7ecf Mon Sep 17 00:00:00 2001 From: Bart House Date: Sun, 14 Jul 2019 21:16:27 -0700 Subject: [PATCH 17/25] Revert "Comment out nhassert() calls." This reverts commit 45a9c5eb14326521188457fe87a9d853b44a64ce. --- win/tty/topl.c | 8 ++++---- win/tty/wintty.c | 6 +++--- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/win/tty/topl.c b/win/tty/topl.c index 14e9bc548..bb79be26c 100644 --- a/win/tty/topl.c +++ b/win/tty/topl.c @@ -259,7 +259,7 @@ register const char *bp; && cw->cury == 0 && n0 + (int) strlen(toplines) + 3 < CO - 8 /* room for --More-- */ && (notdied = strncmp(bp, "You die", 7)) != 0) { - /* nhassert(strlen(toplines) == cw->curx); */ + nhassert(strlen(toplines) == cw->curx); Strcat(toplines, " "); Strcat(toplines, bp); cw->curx += 2; @@ -313,7 +313,7 @@ char c; if (ttyDisplay->curx == 0 && ttyDisplay->cury > 0) tty_curs(BASE_WINDOW, CO, (int) ttyDisplay->cury - 1); backsp(); - /* nhassert(ttyDisplay->curx > 0); */ + nhassert(ttyDisplay->curx > 0); ttyDisplay->curx--; cw->curx = ttyDisplay->curx; return; @@ -708,8 +708,8 @@ boolean restoring_msghist; dumplogmsg(toplines); #endif } else if (snapshot_mesgs) { - /* nhassert(ttyDisplay == NULL || - ttyDisplay->toplin != TOPLINE_NEED_MORE); */ + nhassert(ttyDisplay == NULL || + ttyDisplay->toplin != TOPLINE_NEED_MORE); /* done putting arbitrary messages in; put the snapshot ones back */ for (idx = 0; snapshot_mesgs[idx]; ++idx) { diff --git a/win/tty/wintty.c b/win/tty/wintty.c index 6d5042f8e..63861d62b 100644 --- a/win/tty/wintty.c +++ b/win/tty/wintty.c @@ -2321,7 +2321,7 @@ boolean blocking; /* with ttys, all windows are blocking */ more(); ttyDisplay->toplin = TOPLINE_NEED_MORE; /* more resets this */ tty_clear_nhwindow(window); - /* nhassert(ttyDisplay->toplin == TOPLINE_EMPTY); */ + nhassert(ttyDisplay->toplin == TOPLINE_EMPTY); } else ttyDisplay->toplin = TOPLINE_EMPTY; cw->curx = cw->cury = 0; @@ -2409,7 +2409,7 @@ winid window; case NHW_MESSAGE: if (ttyDisplay->toplin != TOPLINE_EMPTY) tty_display_nhwindow(WIN_MESSAGE, TRUE); - /* nhassert(ttyDisplay->toplin == TOPLINE_EMPTY); */ + nhassert(ttyDisplay->toplin == TOPLINE_EMPTY); /*FALLTHRU*/ case NHW_STATUS: case NHW_BASE: @@ -3164,7 +3164,7 @@ const char *mesg; more(); ttyDisplay->toplin = TOPLINE_NEED_MORE; /* more resets this */ tty_clear_nhwindow(WIN_MESSAGE); - /* nhassert(ttyDisplay->toplin == TOPLINE_EMPTY); */ + nhassert(ttyDisplay->toplin == TOPLINE_EMPTY); } /* normally means skip further messages, but in this case it means cancel the current prompt; any other messages should From 988d474d426e8e8dace97475dcf8b31787c4a062 Mon Sep 17 00:00:00 2001 From: Bart House Date: Sun, 14 Jul 2019 21:16:59 -0700 Subject: [PATCH 18/25] Revert "Added assertions to check toplin state." This reverts commit 1db45c8016484114841f39ffe70c8d9cdd1ad92c. --- win/tty/wintty.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/win/tty/wintty.c b/win/tty/wintty.c index 63861d62b..6d5042f8e 100644 --- a/win/tty/wintty.c +++ b/win/tty/wintty.c @@ -2321,7 +2321,7 @@ boolean blocking; /* with ttys, all windows are blocking */ more(); ttyDisplay->toplin = TOPLINE_NEED_MORE; /* more resets this */ tty_clear_nhwindow(window); - nhassert(ttyDisplay->toplin == TOPLINE_EMPTY); + /* nhassert(ttyDisplay->toplin == TOPLINE_EMPTY); */ } else ttyDisplay->toplin = TOPLINE_EMPTY; cw->curx = cw->cury = 0; @@ -2409,7 +2409,7 @@ winid window; case NHW_MESSAGE: if (ttyDisplay->toplin != TOPLINE_EMPTY) tty_display_nhwindow(WIN_MESSAGE, TRUE); - nhassert(ttyDisplay->toplin == TOPLINE_EMPTY); + /* nhassert(ttyDisplay->toplin == TOPLINE_EMPTY); */ /*FALLTHRU*/ case NHW_STATUS: case NHW_BASE: @@ -3164,7 +3164,7 @@ const char *mesg; more(); ttyDisplay->toplin = TOPLINE_NEED_MORE; /* more resets this */ tty_clear_nhwindow(WIN_MESSAGE); - nhassert(ttyDisplay->toplin == TOPLINE_EMPTY); + /* nhassert(ttyDisplay->toplin == TOPLINE_EMPTY); */ } /* normally means skip further messages, but in this case it means cancel the current prompt; any other messages should From a598428fc9bdabf33d482855f8b5db4c78896a10 Mon Sep 17 00:00:00 2001 From: Bart House Date: Sun, 14 Jul 2019 21:17:19 -0700 Subject: [PATCH 19/25] Revert "Fixed bug with inmore and toplin state management." This reverts commit 0f57f0e48ca6e6823fb238566d5faddd3cf0726b. --- win/tty/topl.c | 23 ++++------------------- 1 file changed, 4 insertions(+), 19 deletions(-) diff --git a/win/tty/topl.c b/win/tty/topl.c index bb79be26c..d2a889cc9 100644 --- a/win/tty/topl.c +++ b/win/tty/topl.c @@ -139,7 +139,7 @@ const char *str; putsyms(str); cl_end(); ttyDisplay->toplin = TOPLINE_NEED_MORE; - if (ttyDisplay->cury && otoplin != TOPLINE_SPECIAL_PROMPT) + if (ttyDisplay->cury && otoplin != 3) more(); } @@ -204,15 +204,12 @@ more() { struct WinDesc *cw = wins[WIN_MESSAGE]; + /* avoid recursion -- only happens from interrupts */ + if (ttyDisplay->inmore++) + return; if (iflags.debug_fuzzer) return; - /* avoid recursion -- only happens from interrupts */ - if (ttyDisplay->inmore) - return; - - ttyDisplay->inmore++; - if (ttyDisplay->toplin) { tty_curs(BASE_WINDOW, cw->curx + 1, cw->cury); if (cw->curx >= CO - 8) @@ -259,7 +256,6 @@ register const char *bp; && cw->cury == 0 && n0 + (int) strlen(toplines) + 3 < CO - 8 /* room for --More-- */ && (notdied = strncmp(bp, "You die", 7)) != 0) { - nhassert(strlen(toplines) == cw->curx); Strcat(toplines, " "); Strcat(toplines, bp); cw->curx += 2; @@ -313,7 +309,6 @@ char c; if (ttyDisplay->curx == 0 && ttyDisplay->cury > 0) tty_curs(BASE_WINDOW, CO, (int) ttyDisplay->cury - 1); backsp(); - nhassert(ttyDisplay->curx > 0); ttyDisplay->curx--; cw->curx = ttyDisplay->curx; return; @@ -694,13 +689,6 @@ boolean restoring_msghist; } if (msg) { - /* Caller is asking us to remember a top line that needed more. - Should we call more? This can happen when the player has set - iflags.force_invmenu and they attempt to shoot with nothing in - the quiver. */ - if (ttyDisplay && ttyDisplay->toplin == TOPLINE_NEED_MORE) - ttyDisplay->toplin = TOPLINE_NON_EMPTY; - /* move most recent message to history, make this become most recent */ remember_topl(); Strcpy(toplines, msg); @@ -708,9 +696,6 @@ boolean restoring_msghist; dumplogmsg(toplines); #endif } else if (snapshot_mesgs) { - nhassert(ttyDisplay == NULL || - ttyDisplay->toplin != TOPLINE_NEED_MORE); - /* done putting arbitrary messages in; put the snapshot ones back */ for (idx = 0; snapshot_mesgs[idx]; ++idx) { remember_topl(); From 44d84c3163988502e041a4c3aa178cadc54d5797 Mon Sep 17 00:00:00 2001 From: Bart House Date: Sun, 14 Jul 2019 21:17:39 -0700 Subject: [PATCH 20/25] Revert "Modified nhassert_failed to call impossoible." This reverts commit 3e4a0759a37ec6fe62d026cdd02dadd0ec6f682d. --- sys/winnt/winnt.c | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/sys/winnt/winnt.c b/sys/winnt/winnt.c index d54982975..e9041262d 100644 --- a/sys/winnt/winnt.c +++ b/sys/winnt/winnt.c @@ -478,11 +478,18 @@ char *buf; /* nhassert_failed is called when an nhassert's condition is false */ void nhassert_failed(const char * exp, const char * file, int line) { - char message[BUFSZ]; - snprintf(message, sizeof(message), - "NHASSERT(%s) in '%s' at line %d", exp, file, line); + char message[128]; + _snprintf(message, sizeof(message), + "NHASSERT(%s) in '%s' at line %d\n", exp, file, line); - impossible(message); + if (IsDebuggerPresent()) { + OutputDebugStringA(message); + DebugBreak(); + } + + // strip off the newline + message[strlen(message) - 1] = '\0'; + error(message); } void From 733e760638dbef96484b097a9a92b261503e2c74 Mon Sep 17 00:00:00 2001 From: Bart House Date: Sun, 14 Jul 2019 21:18:03 -0700 Subject: [PATCH 21/25] Revert "Remove the remapping of snprintf to _snprintf when compiling with MSC." This reverts commit 9801635f56804a195c2b1f5c6bec0e239c9c4935. --- include/ntconf.h | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/include/ntconf.h b/include/ntconf.h index 9d79006f0..994615c2d 100644 --- a/include/ntconf.h +++ b/include/ntconf.h @@ -146,6 +146,14 @@ extern void NDECL(getlock); #define strncmpi(a, b, c) strnicmp(a, b, c) #endif +#ifdef _MSC_VER +/* Visual Studio defines this in their own headers, which we don't use */ +#ifndef snprintf +#define snprintf _snprintf +#pragma warning( \ + disable : 4996) /* deprecation warning suggesting snprintf_s */ +#endif +#endif #include #include From 05d77d91b827d35da4c3845b4324648a5a47e052 Mon Sep 17 00:00:00 2001 From: Bart House Date: Sun, 14 Jul 2019 21:28:03 -0700 Subject: [PATCH 22/25] Revert "Moved declaration of topline state to wintty.h." This reverts commit 7bb41c797fb2491dc39102ddd4f1d31bd74c10c8. --- include/decl.h | 6 ++++++ include/wintty.h | 6 ------ 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/include/decl.h b/include/decl.h index 5ebaa326e..6c0f9721c 100644 --- a/include/decl.h +++ b/include/decl.h @@ -455,6 +455,12 @@ struct early_opt { boolean valallowed; }; +/* topline states */ +#define TOPLINE_EMPTY 0 /* empty */ +#define TOPLINE_NEED_MORE 1 /* non-empty, need --More-- */ +#define TOPLINE_NON_EMPTY 2 /* non-empty, no --More-- required */ +#define TOPLINE_SPECIAL_PROMPT 3 /* special prompt state */ + #undef E #endif /* DECL_H */ diff --git a/include/wintty.h b/include/wintty.h index e6388ec0d..6994fc93f 100644 --- a/include/wintty.h +++ b/include/wintty.h @@ -50,12 +50,6 @@ struct WinDesc { #define WIN_STOP 1 /* for NHW_MESSAGE; stops output */ #define WIN_LOCKHISTORY 2 /* for NHW_MESSAGE; suppress history updates */ -/* topline states */ -#define TOPLINE_EMPTY 0 /* empty */ -#define TOPLINE_NEED_MORE 1 /* non-empty, need --More-- */ -#define TOPLINE_NON_EMPTY 2 /* non-empty, no --More-- required */ -#define TOPLINE_SPECIAL_PROMPT 3 /* special prompt state */ - /* descriptor for tty-based displays -- all the per-display data */ struct DisplayDesc { short rows, cols; /* width and height of tty display */ From e83fcd0353b03ce3ed6ff5b33e2d4576c11dac79 Mon Sep 17 00:00:00 2001 From: Bart House Date: Sun, 14 Jul 2019 21:28:40 -0700 Subject: [PATCH 23/25] Revert "Improved readability of topline state management." This reverts commit 08a19108678e772ab52ee195be74101b2792accb. --- include/decl.h | 6 ------ win/tty/getline.c | 6 +++--- win/tty/topl.c | 24 ++++++++++++------------ win/tty/wintty.c | 48 +++++++++++++++++++++-------------------------- 4 files changed, 36 insertions(+), 48 deletions(-) diff --git a/include/decl.h b/include/decl.h index 6c0f9721c..5ebaa326e 100644 --- a/include/decl.h +++ b/include/decl.h @@ -455,12 +455,6 @@ struct early_opt { boolean valallowed; }; -/* topline states */ -#define TOPLINE_EMPTY 0 /* empty */ -#define TOPLINE_NEED_MORE 1 /* non-empty, need --More-- */ -#define TOPLINE_NON_EMPTY 2 /* non-empty, no --More-- required */ -#define TOPLINE_SPECIAL_PROMPT 3 /* special prompt state */ - #undef E #endif /* DECL_H */ diff --git a/win/tty/getline.c b/win/tty/getline.c index a3abfcc53..f4894a950 100644 --- a/win/tty/getline.c +++ b/win/tty/getline.c @@ -52,10 +52,10 @@ getlin_hook_proc hook; struct WinDesc *cw = wins[WIN_MESSAGE]; boolean doprev = 0; - if (ttyDisplay->toplin == TOPLINE_NEED_MORE && !(cw->flags & WIN_STOP)) + if (ttyDisplay->toplin == 1 && !(cw->flags & WIN_STOP)) more(); cw->flags &= ~WIN_STOP; - ttyDisplay->toplin = TOPLINE_SPECIAL_PROMPT; + ttyDisplay->toplin = 3; /* special prompt state */ ttyDisplay->inread++; /* issue the prompt */ @@ -193,7 +193,7 @@ getlin_hook_proc hook; } else tty_nhbell(); } - ttyDisplay->toplin = TOPLINE_NON_EMPTY; + ttyDisplay->toplin = 2; /* nonempty, no --More-- required */ ttyDisplay->inread--; clear_nhwindow(WIN_MESSAGE); /* clean up after ourselves */ diff --git a/win/tty/topl.c b/win/tty/topl.c index d2a889cc9..62fb3eb53 100644 --- a/win/tty/topl.c +++ b/win/tty/topl.c @@ -138,7 +138,7 @@ const char *str; end_glyphout(); /* in case message printed during graphics output */ putsyms(str); cl_end(); - ttyDisplay->toplin = TOPLINE_NEED_MORE; + ttyDisplay->toplin = 1; if (ttyDisplay->cury && otoplin != 3) more(); } @@ -151,7 +151,7 @@ const char *str; struct WinDesc *cw = wins[WIN_MESSAGE]; if (!(cw->flags & WIN_STOP)) { - if (ttyDisplay->cury && ttyDisplay->toplin == TOPLINE_NON_EMPTY) + if (ttyDisplay->cury && ttyDisplay->toplin == 2) tty_clear_nhwindow(WIN_MESSAGE); cw->curx = cw->cury = 0; @@ -159,8 +159,8 @@ const char *str; cl_end(); addtopl(str); - if (ttyDisplay->cury && ttyDisplay->toplin != TOPLINE_SPECIAL_PROMPT) - ttyDisplay->toplin = TOPLINE_NON_EMPTY; + if (ttyDisplay->cury && ttyDisplay->toplin != 3) + ttyDisplay->toplin = 2; } } @@ -196,7 +196,7 @@ const char *s; tty_curs(BASE_WINDOW, cw->curx + 1, cw->cury); putsyms(s); cl_end(); - ttyDisplay->toplin = TOPLINE_NEED_MORE; + ttyDisplay->toplin = 1; } void @@ -236,7 +236,7 @@ more() home(); cl_end(); } - ttyDisplay->toplin = TOPLINE_EMPTY; + ttyDisplay->toplin = 0; ttyDisplay->inmore = 0; } @@ -252,7 +252,7 @@ register const char *bp; /* If there is room on the line, print message on same line */ /* But messages like "You die..." deserve their own line */ n0 = strlen(bp); - if ((ttyDisplay->toplin == TOPLINE_NEED_MORE || (cw->flags & WIN_STOP)) + if ((ttyDisplay->toplin == 1 || (cw->flags & WIN_STOP)) && cw->cury == 0 && n0 + (int) strlen(toplines) + 3 < CO - 8 /* room for --More-- */ && (notdied = strncmp(bp, "You die", 7)) != 0) { @@ -263,9 +263,9 @@ register const char *bp; addtopl(bp); return; } else if (!(cw->flags & WIN_STOP)) { - if (ttyDisplay->toplin == TOPLINE_NEED_MORE) { + if (ttyDisplay->toplin == 1) { more(); - } else if (cw->cury) { /* for toplin == TOPLINE_NON_EMPTY && cury > 1 */ + } else if (cw->cury) { /* for when flags.toplin == 2 && cury > 1 */ docorner(1, cw->cury + 1); /* reset cury = 0 if redraw screen */ cw->curx = cw->cury = 0; /* from home--cls() & docorner(1,n) */ } @@ -381,10 +381,10 @@ char def; char prompt[BUFSZ]; yn_number = 0L; - if (ttyDisplay->toplin == TOPLINE_NEED_MORE && !(cw->flags & WIN_STOP)) + if (ttyDisplay->toplin == 1 && !(cw->flags & WIN_STOP)) more(); cw->flags &= ~WIN_STOP; - ttyDisplay->toplin = TOPLINE_SPECIAL_PROMPT; + ttyDisplay->toplin = 3; /* special prompt state */ ttyDisplay->inread++; if (resp) { char *rb, respbuf[QBUFSZ]; @@ -531,7 +531,7 @@ char def; dumplogmsg(toplines); #endif ttyDisplay->inread--; - ttyDisplay->toplin = TOPLINE_NON_EMPTY; + ttyDisplay->toplin = 2; if (ttyDisplay->intr) ttyDisplay->intr--; if (wins[WIN_MESSAGE]->cury) diff --git a/win/tty/wintty.c b/win/tty/wintty.c index 6d5042f8e..b4e22ae02 100644 --- a/win/tty/wintty.c +++ b/win/tty/wintty.c @@ -332,7 +332,7 @@ int sig_unused UNUSED; new_status_window(); if (u.ux) { i = ttyDisplay->toplin; - ttyDisplay->toplin = TOPLINE_EMPTY; + ttyDisplay->toplin = 0; docrt(); bot(); ttyDisplay->toplin = i; @@ -420,7 +420,7 @@ char **argv UNUSED; /* set up tty descriptor */ ttyDisplay = (struct DisplayDesc *) alloc(sizeof (struct DisplayDesc)); - ttyDisplay->toplin = TOPLINE_EMPTY; + ttyDisplay->toplin = 0; ttyDisplay->rows = hgt; ttyDisplay->cols = wid; ttyDisplay->curx = ttyDisplay->cury = 0; @@ -1621,12 +1621,12 @@ winid window; switch (cw->type) { case NHW_MESSAGE: - if (ttyDisplay->toplin != TOPLINE_EMPTY) { + if (ttyDisplay->toplin) { home(); cl_end(); if (cw->cury) docorner(1, cw->cury + 1); - ttyDisplay->toplin = TOPLINE_EMPTY; + ttyDisplay->toplin = 0; } break; case NHW_STATUS: @@ -2317,13 +2317,12 @@ boolean blocking; /* with ttys, all windows are blocking */ switch (cw->type) { case NHW_MESSAGE: - if (ttyDisplay->toplin == TOPLINE_NEED_MORE) { + if (ttyDisplay->toplin == 1) { more(); - ttyDisplay->toplin = TOPLINE_NEED_MORE; /* more resets this */ + ttyDisplay->toplin = 1; /* more resets this */ tty_clear_nhwindow(window); - /* nhassert(ttyDisplay->toplin == TOPLINE_EMPTY); */ } else - ttyDisplay->toplin = TOPLINE_EMPTY; + ttyDisplay->toplin = 0; cw->curx = cw->cury = 0; if (!cw->active) iflags.window_inited = TRUE; @@ -2331,8 +2330,8 @@ boolean blocking; /* with ttys, all windows are blocking */ case NHW_MAP: end_glyphout(); if (blocking) { - if (ttyDisplay->toplin != TOPLINE_EMPTY) - ttyDisplay->toplin = TOPLINE_NEED_MORE; + if (!ttyDisplay->toplin) + ttyDisplay->toplin = 1; tty_display_nhwindow(WIN_MESSAGE, TRUE); return; } @@ -2362,7 +2361,7 @@ boolean blocking; /* with ttys, all windows are blocking */ cw->offx = 0; if (cw->type == NHW_MENU) cw->offy = 0; - if (ttyDisplay->toplin == TOPLINE_NEED_MORE) + if (ttyDisplay->toplin == 1) tty_display_nhwindow(WIN_MESSAGE, TRUE); #ifdef H2344_BROKEN if (cw->maxrow >= (int) ttyDisplay->rows @@ -2378,7 +2377,7 @@ boolean blocking; /* with ttys, all windows are blocking */ cl_eos(); } else clear_screen(); - ttyDisplay->toplin = TOPLINE_EMPTY; + ttyDisplay->toplin = 0; } else { if (WIN_MESSAGE != WIN_ERR) tty_clear_nhwindow(WIN_MESSAGE); @@ -2407,9 +2406,8 @@ winid window; switch (cw->type) { case NHW_MESSAGE: - if (ttyDisplay->toplin != TOPLINE_EMPTY) + if (ttyDisplay->toplin) tty_display_nhwindow(WIN_MESSAGE, TRUE); - /* nhassert(ttyDisplay->toplin == TOPLINE_EMPTY); */ /*FALLTHRU*/ case NHW_STATUS: case NHW_BASE: @@ -3160,11 +3158,10 @@ const char *mesg; response to a prompt, we'll assume that the display is up to date */ tty_putstr(WIN_MESSAGE, 0, mesg); /* if `mesg' didn't wrap (triggering --More--), force --More-- now */ - if (ttyDisplay->toplin == TOPLINE_NEED_MORE) { + if (ttyDisplay->toplin == 1) { more(); - ttyDisplay->toplin = TOPLINE_NEED_MORE; /* more resets this */ + ttyDisplay->toplin = 1; /* more resets this */ tty_clear_nhwindow(WIN_MESSAGE); - /* nhassert(ttyDisplay->toplin == TOPLINE_EMPTY); */ } /* normally means skip further messages, but in this case it means cancel the current prompt; any other messages should @@ -3204,7 +3201,7 @@ tty_wait_synch() (void) fflush(stdout); } else if (ttyDisplay->inread > program_state.gameover) { /* this can only happen if we were reading and got interrupted */ - ttyDisplay->toplin = TOPLINE_SPECIAL_PROMPT; + ttyDisplay->toplin = 3; /* do this twice; 1st time gets the Quit? message again */ (void) tty_doprev_message(); (void) tty_doprev_message(); @@ -3533,9 +3530,8 @@ tty_nhgetch() i = '\033'; /* map NUL to ESC since nethack doesn't expect NUL */ else if (i == EOF) i = '\033'; /* same for EOF */ - /* topline has been seen - we can clear need for more */ - if (ttyDisplay && ttyDisplay->toplin == TOPLINE_NEED_MORE) - ttyDisplay->toplin = TOPLINE_NON_EMPTY; + if (ttyDisplay && ttyDisplay->toplin == 1) + ttyDisplay->toplin = 2; #ifdef TTY_TILES_ESCCODES { /* hack to force output of the window select code */ @@ -3614,9 +3610,8 @@ tty_nhgetch() i = '\033'; /* map NUL to ESC since nethack doesn't expect NUL */ else if (i == EOF) i = '\033'; /* same for EOF */ - /* topline has been seen - we can clear need for more */ - if (ttyDisplay && ttyDisplay->toplin == TOPLINE_NEED_MORE) - ttyDisplay->toplin = TOPLINE_NON_EMPTY; + if (ttyDisplay && ttyDisplay->toplin == 1) + ttyDisplay->toplin = 2; #ifdef TTY_TILES_ESCCODES { /* hack to force output of the window select code */ @@ -3661,9 +3656,8 @@ int *x, *y, *mod; i = ntposkey(x, y, mod); if (!i && mod && (*mod == 0 || *mod == EOF)) i = '\033'; /* map NUL or EOF to ESC, nethack doesn't expect either */ - /* topline has been seen - we can clear need for more */ - if (ttyDisplay && ttyDisplay->toplin == TOPLINE_NEED_MORE) - ttyDisplay->toplin = TOPLINE_NON_EMPTY; + if (ttyDisplay && ttyDisplay->toplin == 1) + ttyDisplay->toplin = 2; #else /* !WIN32CON */ nhUse(x); nhUse(y); From 5870cb6a92c7d13477980568ed31cf7cf5b7524f Mon Sep 17 00:00:00 2001 From: Bart House Date: Sun, 14 Jul 2019 21:28:55 -0700 Subject: [PATCH 24/25] Revert "Added experimental feature NEW_KEYBOARD_HIT." This reverts commit bc65112ce07c6e2056ed28b5e93954679fb36acd. --- include/config.h | 8 +--- include/extern.h | 15 ------- include/ntconf.h | 3 -- include/unixconf.h | 2 - include/winprocs.h | 12 ------ include/wintty.h | 4 -- src/allmain.c | 4 -- src/windows.c | 14 ------- sys/winnt/nttty.c | 10 ----- sys/winnt/winnt.c | 7 +--- win/share/safeproc.c | 11 ----- win/tty/wintty.c | 97 -------------------------------------------- win/win32/mswproc.c | 12 ------ win/win32/winMS.h | 3 -- 14 files changed, 3 insertions(+), 199 deletions(-) diff --git a/include/config.h b/include/config.h index f054de5c4..d12576f9d 100644 --- a/include/config.h +++ b/include/config.h @@ -564,13 +564,9 @@ typedef unsigned char uchar; %N first character of player name DUMPLOG_FILE is not used if SYSCF is defined */ -#endif /* DUMPLOG_FILE */ +#endif -#endif /* DUMPLOG */ - -/* NEW_KEYBOARD_HIT adds new window proc to return whether keyboard has been hit - and character input is available */ -/* #define NEW_KEYBOARD_HIT */ +#endif #define USE_ISAAC64 /* Use cross-plattform, bundled RNG */ diff --git a/include/extern.h b/include/extern.h index 0761d224e..90548cf37 100644 --- a/include/extern.h +++ b/include/extern.h @@ -1147,9 +1147,6 @@ E void NDECL(gettty); E void NDECL(setftty); E void FDECL(settty, (const char *)); E int NDECL(tgetch); -#ifdef NEW_KEYBOARD_HIT -E boolean NDECL(tkbhit); -#endif E void FDECL(cmov, (int x, int y)); E void FDECL(nocmov, (int x, int y)); @@ -1555,9 +1552,6 @@ E void FDECL(mplayer_talk, (struct monst *)); #ifndef WIN32 E int NDECL(tgetch); -#ifdef NEW_KEYBOARD_HIT -E boolean NDECL(tkbhit); -#endif #endif #ifndef TOS E char NDECL(switchar); @@ -1588,9 +1582,7 @@ E void FDECL(gotoxy, (int, int)); #endif #ifdef TOS E int FDECL(_copyfile, (char *, char *)); -#ifndef NEW_KEYBOARD_HIT E int NDECL(kbhit); -#endif E void NDECL(set_colors); E void NDECL(restore_colors); #ifdef SUSPEND @@ -1600,9 +1592,7 @@ E int NDECL(dosuspend); #ifdef WIN32 E char *FDECL(get_username, (int *)); E void FDECL(nt_regularize, (char *)); -#ifndef NEW_KEYBOARD_HIT E int NDECL((*nt_kbhit)); -#endif E void FDECL(Delay, (int)); #endif /* WIN32 */ #endif /* MICRO || WIN32 */ @@ -1670,15 +1660,10 @@ E void FDECL(regex_free, (struct nhregex *)); #ifdef WIN32 E void NDECL(get_scr_size); -#ifndef NEW_KEYBOARD_HIT E int NDECL(nttty_kbhit); -#endif E void FDECL(nttty_open, (int)); E void NDECL(nttty_rubout); E int NDECL(tgetch); -#ifdef NEW_KEYBOARD_HIT -E boolean NDECL(tkbhit); -#endif E int FDECL(ntposkey, (int *, int *, int *)); E void FDECL(set_output_mode, (int)); E void NDECL(synch_cursor); diff --git a/include/ntconf.h b/include/ntconf.h index 994615c2d..eb106090f 100644 --- a/include/ntconf.h +++ b/include/ntconf.h @@ -252,11 +252,8 @@ int _RTLENTRY _EXPFUNC read(int __handle, void _FAR *__buf, unsigned __len); #ifndef CURSES_GRAPHICS #include /* conflicting definitions with curses.h */ #endif - -#ifndef NEW_KEYBOARD_HIT #undef kbhit /* Use our special NT kbhit */ #define kbhit (*nt_kbhit) -#endif #ifdef LAN_FEATURES #define MAX_LAN_USERNAME 20 diff --git a/include/unixconf.h b/include/unixconf.h index f9ac16f0c..c126d6839 100644 --- a/include/unixconf.h +++ b/include/unixconf.h @@ -311,9 +311,7 @@ #define HLOCK "perm" /* an empty file used for locking purposes */ -#ifndef NEW_KEYBOARD_HIT #define tgetch getchar -#endif #ifndef NOSHELL #define SHELL /* do not delete the '!' command */ diff --git a/include/winprocs.h b/include/winprocs.h index d1cea9a3c..36962750e 100644 --- a/include/winprocs.h +++ b/include/winprocs.h @@ -79,9 +79,6 @@ struct window_procs { (int, const char *, const char *, BOOLEAN_P)); void FDECL((*win_status_update), (int, genericptr_t, int, int, int, unsigned long *)); boolean NDECL((*win_can_suspend)); -#ifdef NEW_KEYBOARD_HIT - boolean NDECL((*win_keyboard_hit)); -#endif }; extern @@ -163,9 +160,6 @@ extern */ #define status_enablefield (*windowprocs.win_status_enablefield) #define status_update (*windowprocs.win_status_update) -#ifdef NEW_KEYBOARD_HIT -#define keyboard_hit (*windowprocs.win_keyboard_hit) -#endif /* * WINCAP @@ -385,9 +379,6 @@ struct chain_procs { (CARGS, int, const char *, const char *, BOOLEAN_P)); void FDECL((*win_status_update), (CARGS, int, genericptr_t, int, int, int, unsigned long *)); boolean FDECL((*win_can_suspend), (CARGS)); -#ifdef NEW_KEYBOARD_HIT - boolean FDECL((*keyboard_hit), (CARGS)); -#endif }; #endif /* WINCHAIN */ @@ -458,9 +449,6 @@ extern void FDECL(safe_status_enablefield, (int, const char *, const char *, BOOLEAN_P)); extern void FDECL(safe_status_update, (int, genericptr_t, int, int, int, unsigned long *)); extern boolean NDECL(safe_can_suspend); -#ifdef NEW_KEYBOARD_HIT -extern boolean NDECL(safe_keyboard_hit); -#endif extern void FDECL(stdio_raw_print, (const char *)); extern void FDECL(stdio_raw_print_bold, (const char *)); extern void NDECL(stdio_wait_synch); diff --git a/include/wintty.h b/include/wintty.h index 6994fc93f..4863d6e10 100644 --- a/include/wintty.h +++ b/include/wintty.h @@ -247,10 +247,6 @@ E void FDECL(genl_outrip, (winid, int, time_t)); E char *FDECL(tty_getmsghistory, (BOOLEAN_P)); E void FDECL(tty_putmsghistory, (const char *, BOOLEAN_P)); -#ifdef NEW_KEYBOARD_HIT -E boolean NDECL(tty_keyboard_hit); -#endif - #ifdef NO_TERMS #ifdef MAC #ifdef putchar diff --git a/src/allmain.c b/src/allmain.c index 082447b3b..57170b66c 100644 --- a/src/allmain.c +++ b/src/allmain.c @@ -374,11 +374,7 @@ boolean resuming; if (multi >= 0 && occupation) { #if defined(MICRO) || defined(WIN32) abort_lev = 0; -#ifdef NEW_KEYBOARD_HIT - if (keyboard_hit()) { -#else if (kbhit()) { -#endif if ((ch = pgetchar()) == ABORT) abort_lev++; else diff --git a/src/windows.c b/src/windows.c index 0d2ce514d..ad7b91b0d 100644 --- a/src/windows.c +++ b/src/windows.c @@ -523,9 +523,6 @@ static void NDECL(hup_void_ndecl); static void FDECL(hup_void_fdecl_int, (int)); static void FDECL(hup_void_fdecl_winid, (winid)); static void FDECL(hup_void_fdecl_constchar_p, (const char *)); -#ifdef NEW_KEYBOARD_HIT -static boolean NDECL(hup_keyboard_hit); -#endif static struct window_procs hup_procs = { "hup", 0L, 0L, hup_init_nhwindows, @@ -573,9 +570,6 @@ static struct window_procs hup_procs = { hup_void_ndecl, /* status_finish */ genl_status_enablefield, hup_status_update, genl_can_suspend_no, -#ifdef NEW_KEYBOARD_HIT - hup_keyboard_hit -#endif }; static void FDECL((*previnterface_exit_nhwindows), (const char *)) = 0; @@ -630,14 +624,6 @@ hup_nhgetch(VOID_ARGS) return '\033'; /* ESC */ } -#ifdef NEW_KEYBOARD_HIT -static boolean -hup_keyboard_hit(VOID_ARGS) -{ - return FALSE; -} -#endif - /*ARGSUSED*/ static char hup_yn_function(prompt, resp, deflt) diff --git a/sys/winnt/nttty.c b/sys/winnt/nttty.c index a8000bc05..3233dc9cb 100644 --- a/sys/winnt/nttty.c +++ b/sys/winnt/nttty.c @@ -398,12 +398,10 @@ int mode; // unused { DWORD cmode; -#ifndef NEW_KEYBOARD_HIT /* Initialize the function pointer that points to * the kbhit() equivalent, in this TTY case nttty_kbhit() */ nt_kbhit = nttty_kbhit; -#endif if (!SetConsoleCtrlHandler((PHANDLER_ROUTINE) CtrlHandler, TRUE)) { /* Unable to set control handler */ @@ -438,19 +436,11 @@ int portdebug; return ch; } -#ifndef NEW_KEYBOARD_HIT int nttty_kbhit() { return keyboard_handler.pNHkbhit(console.hConIn, &ir); } -#else -boolean -tkbhit() -{ - return keyboard_handler.pNHkbhit(console.hConIn, &ir) != 0; -} -#endif int tgetch() diff --git a/sys/winnt/winnt.c b/sys/winnt/winnt.c index e9041262d..f6a9aa791 100644 --- a/sys/winnt/winnt.c +++ b/sys/winnt/winnt.c @@ -56,7 +56,6 @@ extern void NDECL(backsp); int NDECL(windows_console_custom_nhgetch); extern void NDECL(safe_routines); -#ifndef NEW_KEYBOARD_HIT /* The function pointer nt_kbhit contains a kbhit() equivalent * which varies depending on which window port is active. * For the tty port it is tty_kbhit() [from nttty.c] @@ -66,7 +65,6 @@ extern void NDECL(safe_routines); int def_kbhit(void); int (*nt_kbhit)() = def_kbhit; -#endif char switchar() @@ -160,13 +158,11 @@ max_filename() return 0; } -#ifndef NEW_KEYBOARD_HIT int def_kbhit() { return 0; } -#endif /* * Strip out troublesome file system characters. @@ -514,9 +510,7 @@ int code; exit(code); } -#ifndef NEW_KEYBOARD_HIT #undef kbhit -#endif #include int @@ -725,6 +719,7 @@ sys_random_seed(VOID_ARGS) } return ourseed; } + #endif /* WIN32 */ /*winnt.c*/ diff --git a/win/share/safeproc.c b/win/share/safeproc.c index 9f3e0ce2f..ab5cb1c5a 100644 --- a/win/share/safeproc.c +++ b/win/share/safeproc.c @@ -101,9 +101,6 @@ struct window_procs safe_procs = { safe_status_update, #endif safe_can_suspend, -#ifdef NEW_KEYBOARD_HIT - safe_keyboard_hit -#endif }; struct window_procs * @@ -389,14 +386,6 @@ safe_can_suspend() return FALSE; } -#ifdef NEW_KEYBOARD_HIT -boolean -safe_keyboard_hit() -{ - return FALSE; -} -#endif - void safe_nhbell() { diff --git a/win/tty/wintty.c b/win/tty/wintty.c index b4e22ae02..85c1ca59d 100644 --- a/win/tty/wintty.c +++ b/win/tty/wintty.c @@ -36,12 +36,6 @@ extern void msmsg(const char *, ...); #endif #endif -#ifdef NEW_KEYBOARD_HIT -#if defined(UNIX) -#include -#endif -#endif - #ifdef TTY_TILES_ESCCODES extern short glyph2tile[]; #define TILE_ANSI_COMMAND 'z' @@ -139,9 +133,6 @@ struct window_procs tty_procs = { genl_status_update, #endif genl_can_suspend_yes, -#ifdef NEW_KEYBOARD_HIT - tty_keyboard_hit -#endif }; static int maxwin = 0; /* number of windows in use */ @@ -3488,7 +3479,6 @@ const char *str; #endif } -#ifndef NEW_KEYBOARD_HIT int tty_nhgetch() { @@ -3543,93 +3533,6 @@ tty_nhgetch() #endif /* TTY_TILES_ESCCODES */ return i; } -#else /* NEW_KEYBOARD_HIT */ -#ifdef UNIX -static boolean stdin_non_blocking = FALSE; - -int -tgetch() -{ - static volatile int nesting = 0; - int i; - char nestbuf; - - if (stdin_non_blocking) { - fcntl(0, F_SETFL, fcntl(0, F_GETFL) & ~O_NONBLOCK); - stdin_non_blocking = FALSE; - } - - /* kludge alert: Some Unix variants return funny values if getc() - * is called, interrupted, and then called again. There - * is non-reentrant code in the internal _filbuf() routine, called by - * getc(). - */ - i = (++nesting == 1) - ? getchar() - : (read(fileno(stdin), (genericptr_t) &nestbuf, 1) == 1) - ? (int) nestbuf : EOF; - --nesting; - - return i; -} - -boolean -tkbhit() -{ - int i; - if (!stdin_non_blocking) { - fcntl(0, F_SETFL, fcntl(0, F_GETFL) | O_NONBLOCK); - stdin_non_blocking = TRUE; - } - i = getchar(); - if (i != EOF) ungetc(i, stdin); - return (i != EOF); - } -#endif - -int -tty_nhgetch() -{ - int i; - HUPSKIP_RESULT('\033'); - print_vt_code1(AVTC_INLINE_SYNC); - (void) fflush(stdout); - /* Note: if raw_print() and wait_synch() get called to report terminal - * initialization problems, then wins[] and ttyDisplay might not be - * available yet. Such problems will probably be fatal before we get - * here, but validate those pointers just in case... - */ - if (WIN_MESSAGE != WIN_ERR && wins[WIN_MESSAGE]) - wins[WIN_MESSAGE]->flags &= ~WIN_STOP; - if (iflags.debug_fuzzer) { - i = randomkey(); - } else { - i = tgetch(); - } - if (!i) - i = '\033'; /* map NUL to ESC since nethack doesn't expect NUL */ - else if (i == EOF) - i = '\033'; /* same for EOF */ - if (ttyDisplay && ttyDisplay->toplin == 1) - ttyDisplay->toplin = 2; -#ifdef TTY_TILES_ESCCODES - { - /* hack to force output of the window select code */ - int tmp = vt_tile_current_window; - - vt_tile_current_window++; - print_vt_code2(AVTC_SELECT_WINDOW, tmp); - } -#endif /* TTY_TILES_ESCCODES */ - return i; -} - -boolean tty_keyboard_hit() -{ - /* tgetch provider needs to also provide tkbhit() */ - return tkbhit(); -} -#endif /* NEW_KEYBOARD_HIT */ /* * return a key, or 0, in which case a mouse button was pressed diff --git a/win/win32/mswproc.c b/win/win32/mswproc.c index a5aa02bb4..b637c463f 100644 --- a/win/win32/mswproc.c +++ b/win/win32/mswproc.c @@ -116,9 +116,6 @@ struct window_procs mswin_procs = { mswin_status_init, mswin_status_finish, mswin_status_enablefield, mswin_status_update, genl_can_suspend_yes, -#ifdef NEW_KEYBOARD_HIT - mswin_keyboard_hit -#endif }; /* @@ -1405,15 +1402,6 @@ mswin_nhgetch() return (key); } -#ifdef NEW_KEYBOARD_HIT -/* boolean keyboard_hit() -- returns TRUE if input is available */ -boolean -mswin_keyboard_hit() -{ - return mswin_have_input() != 0; -} -#endif - /* int nh_poskey(int *x, int *y, int *mod) -- Returns a single character input from the user or a diff --git a/win/win32/winMS.h b/win/win32/winMS.h index c649917dc..c5ee77368 100644 --- a/win/win32/winMS.h +++ b/win/win32/winMS.h @@ -167,9 +167,6 @@ void mswin_raw_print(const char *str); void mswin_raw_print_bold(const char *str); void mswin_raw_print_flush(); int mswin_nhgetch(void); -#ifdef NEW_KEYBOARD_HIT -boolean mswin_keyboard_hit(void); -#endif int mswin_nh_poskey(int *x, int *y, int *mod); void mswin_nhbell(void); int mswin_doprev_message(void); From a607ea2b7f2a24ba8c8f9ae2ace27bf922f4656f Mon Sep 17 00:00:00 2001 From: Bart House Date: Sun, 14 Jul 2019 21:29:41 -0700 Subject: [PATCH 25/25] Revert "When fuzzing, use the number of moves as a proxy for the hour." This reverts commit f75deae0bcca5bdd4afddb40291e5e2bb0ecd846. --- src/hacklib.c | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/src/hacklib.c b/src/hacklib.c index b97a78a65..7cf5a47c6 100644 --- a/src/hacklib.c +++ b/src/hacklib.c @@ -1129,8 +1129,7 @@ friday_13th() int night() { - register int hour = (iflags.debug_fuzzer ? (moves / 1000) % 24 : - getlt()->tm_hour); + register int hour = getlt()->tm_hour; return (hour < 6 || hour > 21); } @@ -1138,10 +1137,7 @@ night() int midnight() { - register int hour = (iflags.debug_fuzzer ? (moves / 1000) % 24 : - getlt()->tm_hour); - - return (hour == 0); + return (getlt()->tm_hour == 0); } /* strbuf_init() initializes strbuf state for use */