Merge branch 'master' into NetHack-3.7

This commit is contained in:
nhmall
2019-07-14 09:57:32 -04:00
18 changed files with 517 additions and 40 deletions

View File

@@ -259,7 +259,7 @@ register const char *bp;
&& cw->cury == 0
&& n0 + (int) strlen(g.toplines) + 3 < CO - 8 /* room for --More-- */
&& (notdied = strncmp(bp, "You die", 7)) != 0) {
nhassert((long) strlen(g.toplines) == cw->curx);
/* nhassert((long) strlen(g.toplines) == cw->curx); */
Strcat(g.toplines, " ");
Strcat(g.toplines, bp);
cw->curx += 2;
@@ -617,6 +617,66 @@ boolean purged; /* True: took history's pointers, False: just cloned them */
}
}
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 (*g.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 (*g.toplines)
a->elements[a->length++] = strdup(g.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];
*g.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
@@ -631,21 +691,25 @@ char *
tty_getmsghistory(init)
boolean init;
{
static int nxtidx;
char *nextmesg;
char *result = 0;
static size_t nxtidx;
static ptr_array_t * saved_messages = NULL;
char *result = NULL;
if (init) {
msghistory_snapshot(FALSE);
nhassert(saved_messages == NULL);
saved_messages = get_message_history();
nxtidx = 0;
wins[WIN_MESSAGE]->flags |= WIN_LOCKHISTORY;
}
if (snapshot_mesgs) {
nextmesg = snapshot_mesgs[nxtidx++];
if (nextmesg) {
result = (char *) nextmesg;
} else {
free_msghistory_snapshot(FALSE);
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;
@@ -674,7 +738,10 @@ const char *msg;
boolean restoring_msghist;
{
static boolean initd = FALSE;
int idx;
static ptr_array_t * saved_messages = NULL;
size_t i;
nhassert(!(wins[WIN_MESSAGE]->flags & WIN_LOCKHISTORY));
if (restoring_msghist && !initd) {
/* we're restoring history from the previous session, but new
@@ -682,7 +749,9 @@ boolean restoring_msghist;
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);
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 */
@@ -704,22 +773,39 @@ boolean restoring_msghist;
#ifdef DUMPLOG
dumplogmsg(g.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(g.toplines, snapshot_mesgs[idx]);
#ifdef DUMPLOG
dumplogmsg(g.toplines);
#endif
}
/* now release the snapshot */
free_msghistory_snapshot(TRUE);
initd = FALSE; /* reset */
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; i < saved_messages->length; i++) {
const char * mesg = saved_messages->elements[i];
remember_topl();
nhassert(mesg);
Strcpy(g.toplines, mesg);
#ifdef DUMPLOG
dumplogmsg(g.toplines);
#endif
}
ptr_array_free(saved_messages);
saved_messages = NULL;
}
initd = FALSE;
}
}
#endif /* TTY_GRAPHICS */

View File

@@ -0,0 +1,8 @@
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%

View File

@@ -0,0 +1,23 @@
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.

View File

@@ -0,0 +1,7 @@
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%

View File

@@ -0,0 +1,73 @@
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.