From 7bb41c797fb2491dc39102ddd4f1d31bd74c10c8 Mon Sep 17 00:00:00 2001 From: Bart House Date: Thu, 11 Jul 2019 16:34:25 -0700 Subject: [PATCH 01/11] Moved declaration of topline state to wintty.h. --- 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 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/include/wintty.h b/include/wintty.h index 6994fc93f..e6388ec0d 100644 --- a/include/wintty.h +++ b/include/wintty.h @@ -50,6 +50,12 @@ 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 9801635f56804a195c2b1f5c6bec0e239c9c4935 Mon Sep 17 00:00:00 2001 From: Bart House Date: Thu, 11 Jul 2019 20:46:19 -0700 Subject: [PATCH 02/11] Remove the remapping of snprintf to _snprintf when compiling with MSC. _snprintf and snprintf have one very important semantic difference. _snprintf does NOT add terminating null character when the buffer limit is reached while snprintf guarantees a terminating null character. It was a mistake to make this naming change hiding the fact that the semantics don't match what the developer might expect. --- include/ntconf.h | 8 -------- 1 file changed, 8 deletions(-) diff --git a/include/ntconf.h b/include/ntconf.h index 994615c2d..9d79006f0 100644 --- a/include/ntconf.h +++ b/include/ntconf.h @@ -146,14 +146,6 @@ 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 3e4a0759a37ec6fe62d026cdd02dadd0ec6f682d Mon Sep 17 00:00:00 2001 From: Bart House Date: Thu, 11 Jul 2019 20:55:27 -0700 Subject: [PATCH 03/11] Modified nhassert_failed to call impossoible. --- sys/winnt/winnt.c | 15 ++++----------- 1 file changed, 4 insertions(+), 11 deletions(-) diff --git a/sys/winnt/winnt.c b/sys/winnt/winnt.c index e9041262d..d54982975 100644 --- a/sys/winnt/winnt.c +++ b/sys/winnt/winnt.c @@ -478,18 +478,11 @@ 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[128]; - _snprintf(message, sizeof(message), - "NHASSERT(%s) in '%s' at line %d\n", exp, file, line); + char message[BUFSZ]; + snprintf(message, sizeof(message), + "NHASSERT(%s) in '%s' at line %d", exp, file, line); - if (IsDebuggerPresent()) { - OutputDebugStringA(message); - DebugBreak(); - } - - // strip off the newline - message[strlen(message) - 1] = '\0'; - error(message); + impossible(message); } void From 0f57f0e48ca6e6823fb238566d5faddd3cf0726b Mon Sep 17 00:00:00 2001 From: Bart House Date: Thu, 11 Jul 2019 21:04:29 -0700 Subject: [PATCH 04/11] Fixed bug with inmore and toplin state management. When fuzzing, we would increment ttyDisplay->inmore but then prematurely exit more() leaving ttyDisplay->inmore set. Under various conditions, we can request to remember the topline when the topline had not yet been acknowledged leaving toplin state in an inappropriate state. --- win/tty/topl.c | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/win/tty/topl.c b/win/tty/topl.c index d2a889cc9..bb79be26c 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 != 3) + if (ttyDisplay->cury && otoplin != TOPLINE_SPECIAL_PROMPT) more(); } @@ -204,12 +204,15 @@ 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) @@ -256,6 +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); Strcat(toplines, " "); Strcat(toplines, bp); cw->curx += 2; @@ -309,6 +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); ttyDisplay->curx--; cw->curx = ttyDisplay->curx; return; @@ -689,6 +694,13 @@ 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); @@ -696,6 +708,9 @@ 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 1db45c8016484114841f39ffe70c8d9cdd1ad92c Mon Sep 17 00:00:00 2001 From: Bart House Date: Thu, 11 Jul 2019 20:58:20 -0700 Subject: [PATCH 05/11] Added assertions to check toplin state. --- 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 8ea315ab1..0422129fd 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 45a9c5eb14326521188457fe87a9d853b44a64ce Mon Sep 17 00:00:00 2001 From: Bart House Date: Thu, 11 Jul 2019 21:23:12 -0700 Subject: [PATCH 06/11] Comment out nhassert() calls. --- 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 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 0422129fd..8ea315ab1 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 0ca299acb3b52c90e65ad3ca3eb69ccfa8cceb97 Mon Sep 17 00:00:00 2001 From: Bart House Date: Thu, 11 Jul 2019 22:01:39 -0700 Subject: [PATCH 07/11] Added nhassert to core. --- 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, 19 insertions(+), 27 deletions(-) diff --git a/include/extern.h b/include/extern.h index 0761d224e..5812366f2 100644 --- a/include/extern.h +++ b/include/extern.h @@ -1932,6 +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 *, const char *, int)); /* ### polyself.c ### */ diff --git a/include/global.h b/include/global.h index 6e0f96ebf..ada34523c 100644 --- a/include/global.h +++ b/include/global.h @@ -375,5 +375,10 @@ 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 9d79006f0..62c269bab 100644 --- a/include/ntconf.h +++ b/include/ntconf.h @@ -267,16 +267,6 @@ 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 d7db3f43d..535b75e95 100644 --- a/src/pline.c +++ b/src/pline.c @@ -582,4 +582,10 @@ 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 d54982975..0e19e1f76 100644 --- a/sys/winnt/winnt.c +++ b/sys/winnt/winnt.c @@ -475,16 +475,6 @@ 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 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 8ea315ab1..0422129fd 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 0e8e5aac93e660a001dccb66df7320023aaa36de Mon Sep 17 00:00:00 2001 From: Bart House Date: Fri, 12 Jul 2019 18:37:33 -0700 Subject: [PATCH 08/11] Fixed sign/unsigned comparisions. --- 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 100a74d3b..0c8271845 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 != ESHK(mtmp)->shoproom) + if (levl[x][y].roomno != (unsigned char) ESHK(mtmp)->shoproom) return FALSE; } else if (mtmp->ispriest && inhistemple(mtmp)) { - if (levl[x][y].roomno != EPRI(mtmp)->shroom) + if (levl[x][y].roomno != (unsigned char) EPRI(mtmp)->shroom) return FALSE; } /* current location is */ diff --git a/win/tty/topl.c b/win/tty/topl.c index bb79be26c..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(strlen(toplines) == cw->curx); + nhassert((long) strlen(toplines) == cw->curx); Strcat(toplines, " "); Strcat(toplines, bp); cw->curx += 2; From 2f3da35c6893d2a44e8281ae209f00d54eefa2f2 Mon Sep 17 00:00:00 2001 From: Bart House Date: Fri, 12 Jul 2019 18:40:34 -0700 Subject: [PATCH 09/11] Tweaks to nhassert implementation. Change to warnings on MSC build. --- include/extern.h | 2 +- include/global.h | 2 +- include/ntconf.h | 12 ++++++++++++ src/pline.c | 15 +++++++++++++-- sys/winnt/winnt.c | 17 +++++++++++++++++ 5 files changed, 44 insertions(+), 4 deletions(-) diff --git a/include/extern.h b/include/extern.h index 5812366f2..abea20a68 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 *, const char *, int)); +E void FDECL(nhassert_failed, (const char *, int)); /* ### polyself.c ### */ diff --git a/include/global.h b/include/global.h index ada34523c..1bcc2ae5d 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(#expression, __FILE__, __LINE__), 0)) + (nhassert_failed(__FILE__, __LINE__), 0)) #endif #endif /* GLOBAL_H */ diff --git a/include/ntconf.h b/include/ntconf.h index 62c269bab..0c76ed718 100644 --- a/include/ntconf.h +++ b/include/ntconf.h @@ -134,6 +134,8 @@ 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 */ @@ -270,4 +272,14 @@ 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 535b75e95..91e825963 100644 --- a/src/pline.c +++ b/src/pline.c @@ -583,9 +583,20 @@ VA_DECL(const char *, str) } /* nhassert_failed is called when an nhassert's condition is false */ -void nhassert_failed(const char * exp, const char * file, int line) +void +nhassert_failed(filepath, line) + const char * filepath; + int line; { - impossible("NHASSERT(%s) in '%s' at line %d", exp, file, 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); } /*pline.c*/ diff --git a/sys/winnt/winnt.c b/sys/winnt/winnt.c index 0e19e1f76..8d513c59e 100644 --- a/sys/winnt/winnt.c +++ b/sys/winnt/winnt.c @@ -708,6 +708,23 @@ 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 638d9f936316bf8e68783e976b0cde7193ebca0e Mon Sep 17 00:00:00 2001 From: nhmall Date: Sat, 13 Jul 2019 00:17:23 -0400 Subject: [PATCH 10/11] if prototype is declared static make function static to match Today, a compiler was encountered that considered it an error to have the prototype declared static and the function body not --- src/allmain.c | 2 +- src/apply.c | 6 +++--- src/botl.c | 4 ++-- src/cmd.c | 2 +- src/display.c | 2 +- src/hack.c | 4 ++-- src/isaac64.c | 2 ++ src/makemon.c | 2 +- src/mkmaze.c | 8 ++++---- src/mon.c | 4 ++-- src/objnam.c | 4 ++-- src/options.c | 4 ++-- src/pager.c | 22 +++++++++++----------- src/pickup.c | 2 +- src/questpgr.c | 2 +- src/shk.c | 2 +- util/makedefs.c | 4 ++-- win/tty/wintty.c | 2 +- 18 files changed, 40 insertions(+), 38 deletions(-) diff --git a/src/allmain.c b/src/allmain.c index 1ce8cad08..082447b3b 100644 --- a/src/allmain.c +++ b/src/allmain.c @@ -876,7 +876,7 @@ enum earlyarg e_arg; * optimization so that display output * can be debugged without buffering. */ -void +STATIC_OVL void debug_fields(opts) const char *opts; { diff --git a/src/apply.c b/src/apply.c index 879c6a3cb..5bc67850a 100644 --- a/src/apply.c +++ b/src/apply.c @@ -1611,7 +1611,7 @@ int x,y; && is_valid_jump_pos(x, y, jumping_is_magic, FALSE)); } -void +STATIC_OVL void display_jump_positions(state) int state; { @@ -2870,7 +2870,7 @@ static const char cant_reach[] = "can't reach that spot from here."; /* find pos of monster in range, if only one monster */ -boolean +STATIC_OVL boolean find_poleable_mon(pos, min_range, max_range) coord *pos; int min_range, max_range; @@ -2926,7 +2926,7 @@ int x, y; && distu(x, y) <= polearm_range_max); } -void +STATIC_OVL void display_polearm_positions(state) int state; { diff --git a/src/botl.c b/src/botl.c index 06f0a01b5..4a856a211 100644 --- a/src/botl.c +++ b/src/botl.c @@ -561,7 +561,7 @@ static long bl_hilite_moves = 0L; static unsigned long cond_hilites[BL_ATTCLR_MAX]; static int now_or_before_idx = 0; /* 0..1 for array[2][] first index */ -void +STATIC_OVL void bot_via_windowport() { char buf[BUFSZ]; @@ -2812,7 +2812,7 @@ status_hilite_linestr_gather() } -char * +STATIC_OVL char * status_hilite2str(hl) struct hilite_s *hl; { diff --git a/src/cmd.c b/src/cmd.c index d577d8e91..8fd6d5f68 100644 --- a/src/cmd.c +++ b/src/cmd.c @@ -2576,7 +2576,7 @@ int final; } /* attributes: intrinsics and the like, other non-obvious capabilities */ -void +STATIC_OVL void attributes_enlightenment(unused_mode, final) int unused_mode UNUSED; int final; diff --git a/src/display.c b/src/display.c index 8f7207ad9..70a008a0a 100644 --- a/src/display.c +++ b/src/display.c @@ -897,7 +897,7 @@ xchar x, y; } } -int +STATIC_OVL int tether_glyph(x, y) int x, y; { diff --git a/src/hack.c b/src/hack.c index 74a13af98..95e5ea06c 100644 --- a/src/hack.c +++ b/src/hack.c @@ -1343,7 +1343,7 @@ domove() domove_attempting = 0L; } -void +STATIC_OVL void domove_core() { register struct monst *mtmp; @@ -1940,7 +1940,7 @@ domove_core() } } -void +STATIC_OVL void maybe_smudge_engr(x1,y1,x2,y2) int x1, y1, x2, y2; { diff --git a/src/isaac64.c b/src/isaac64.c index 9ccb0db55..4d19335a3 100644 --- a/src/isaac64.c +++ b/src/isaac64.c @@ -19,7 +19,9 @@ #define ISAAC64_MASK ((uint64_t)0xFFFFFFFFFFFFFFFFULL) #if (defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L) +#if !defined(HAS_INLINE) #define HAS_INLINE +#endif #else # if (defined(__GNUC__) && __GNUC__ >= 2 && !defined(inline)) # define inline __inline__ diff --git a/src/makemon.c b/src/makemon.c index 0f731c353..2350e77a0 100644 --- a/src/makemon.c +++ b/src/makemon.c @@ -1033,7 +1033,7 @@ newmextra() return mextra; } -boolean +STATIC_OVL boolean makemon_rnd_goodpos(mon, gpflags, cc) struct monst *mon; unsigned gpflags; diff --git a/src/mkmaze.c b/src/mkmaze.c index 2a11ba4ed..a9d0c1461 100644 --- a/src/mkmaze.c +++ b/src/mkmaze.c @@ -619,7 +619,7 @@ fixup_special() num_lregions = 0; } -void +STATIC_OVL void check_ransacked(s) char *s; { @@ -630,7 +630,7 @@ char *s; #define ORC_LEADER 1 static const char *orcfruit[] = { "paddle cactus", "dwarven root" }; -void +STATIC_OVL void migrate_orc(mtmp, mflags) struct monst *mtmp; unsigned long mflags; @@ -695,7 +695,7 @@ struct monst *mtmp; add_to_minv(mtmp, otmp); } } -void +STATIC_OVL void migr_booty_item(otyp, gang) int otyp; const char *gang; @@ -716,7 +716,7 @@ const char *gang; } } -void +STATIC_OVL void stolen_booty(VOID_ARGS) { char *gang, gang_name[BUFSZ]; diff --git a/src/mon.c b/src/mon.c index 2a8a7f350..862125289 100644 --- a/src/mon.c +++ b/src/mon.c @@ -45,7 +45,7 @@ const char *warnings[] = { #endif /* 0 */ -void +STATIC_OVL void sanity_check_single_mon(mtmp, chk_geno, msg) struct monst *mtmp; boolean chk_geno; @@ -2735,7 +2735,7 @@ struct monst *mtmp; return; } -void +STATIC_OVL void deal_with_overcrowding(mtmp) struct monst *mtmp; { diff --git a/src/objnam.c b/src/objnam.c index bb876dfd8..59b6397cd 100644 --- a/src/objnam.c +++ b/src/objnam.c @@ -417,7 +417,7 @@ struct obj *obj; return xname_flags(obj, CXN_NORMAL); } -char * +STATIC_OVL char * xname_flags(obj, cxn_flags) register struct obj *obj; unsigned cxn_flags; /* bitmask of CXN_xxx values */ @@ -2576,7 +2576,7 @@ const char *oldstr; return bp; } -boolean +STATIC_OVL boolean badman(basestr, to_plural) const char *basestr; boolean to_plural; /* true => makeplural, false => makesingular */ diff --git a/src/options.c b/src/options.c index 3155275ec..2f601df33 100644 --- a/src/options.c +++ b/src/options.c @@ -1602,7 +1602,7 @@ int typ; return (char *) 0; } -int +STATIC_OVL int query_msgtype() { winid tmpwin; @@ -1796,7 +1796,7 @@ const char *errmsg; return retval; } -boolean +STATIC_OVL boolean add_menu_coloring_parsed(str, c, a) char *str; int c, a; diff --git a/src/pager.c b/src/pager.c index 02c61f966..96abfef26 100644 --- a/src/pager.c +++ b/src/pager.c @@ -1409,7 +1409,7 @@ static const char *suptext2[] = { (char *) 0, }; -void +STATIC_OVL void do_supplemental_info(name, pm, without_asking) char *name; struct permonst *pm; @@ -1885,61 +1885,61 @@ docontact(VOID_ARGS) destroy_nhwindow(cwin); } -void +STATIC_OVL void dispfile_help(VOID_ARGS) { display_file(HELP, TRUE); } -void +STATIC_OVL void dispfile_shelp(VOID_ARGS) { display_file(SHELP, TRUE); } -void +STATIC_OVL void dispfile_optionfile(VOID_ARGS) { display_file(OPTIONFILE, TRUE); } -void +STATIC_OVL void dispfile_license(VOID_ARGS) { display_file(LICENSE, TRUE); } -void +STATIC_OVL void dispfile_debughelp(VOID_ARGS) { display_file(DEBUGHELP, TRUE); } -void +STATIC_OVL void hmenu_doextversion(VOID_ARGS) { (void) doextversion(); } -void +STATIC_OVL void hmenu_dohistory(VOID_ARGS) { (void) dohistory(); } -void +STATIC_OVL void hmenu_dowhatis(VOID_ARGS) { (void) dowhatis(); } -void +STATIC_OVL void hmenu_dowhatdoes(VOID_ARGS) { (void) dowhatdoes(); } -void +STATIC_OVL void hmenu_doextlist(VOID_ARGS) { (void) doextlist(); diff --git a/src/pickup.c b/src/pickup.c index fe25f8a0f..e47d989da 100644 --- a/src/pickup.c +++ b/src/pickup.c @@ -1710,7 +1710,7 @@ int x, y; return FALSE; } -int +STATIC_OVL int do_loot_cont(cobjp, cindex, ccount) struct obj **cobjp; int cindex, ccount; /* index of this container (1..N), number of them (N) */ diff --git a/src/questpgr.c b/src/questpgr.c index 7d58fd89a..5c04c6cdf 100644 --- a/src/questpgr.c +++ b/src/questpgr.c @@ -578,7 +578,7 @@ int how; putmsghistory(out_line, FALSE); } -boolean +STATIC_OVL boolean skip_pager(common) boolean common; { diff --git a/src/shk.c b/src/shk.c index 26e7b66a5..fa29b1f31 100644 --- a/src/shk.c +++ b/src/shk.c @@ -2725,7 +2725,7 @@ boolean ininv, dummy, silent; } } -void +STATIC_OVL void append_honorific(buf) char *buf; { diff --git a/util/makedefs.c b/util/makedefs.c index 42108cc79..073cbf95d 100644 --- a/util/makedefs.c +++ b/util/makedefs.c @@ -951,7 +951,7 @@ unsigned long old_rumor_offset; return rumor_offset; } -void +STATIC_OVL void do_rnd_access_file(fname) const char *fname; { @@ -1416,7 +1416,7 @@ do_date() return; } -boolean +STATIC_OVL boolean get_gitinfo(githash, gitbranch) char *githash, *gitbranch; { diff --git a/win/tty/wintty.c b/win/tty/wintty.c index 0422129fd..63861d62b 100644 --- a/win/tty/wintty.c +++ b/win/tty/wintty.c @@ -4132,7 +4132,7 @@ boolean force_update; * must be updated because they need to change. * This is now done at an individual field case-by-case level. */ -boolean +STATIC_OVL boolean check_fields(forcefields, sz) boolean forcefields; int sz[3]; From 64cc11d9b413ffdd1fa118c2826764665b286490 Mon Sep 17 00:00:00 2001 From: nhmall Date: Sat, 13 Jul 2019 00:28:51 -0400 Subject: [PATCH 11/11] makedefs doesn't use STATIC_OVL macro --- util/makedefs.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/util/makedefs.c b/util/makedefs.c index 073cbf95d..ac196f8e2 100644 --- a/util/makedefs.c +++ b/util/makedefs.c @@ -951,7 +951,7 @@ unsigned long old_rumor_offset; return rumor_offset; } -STATIC_OVL void +static void do_rnd_access_file(fname) const char *fname; { @@ -1416,7 +1416,7 @@ do_date() return; } -STATIC_OVL boolean +static boolean get_gitinfo(githash, gitbranch) char *githash, *gitbranch; {