From 30ddfb01dbbfe3b1cfbe689c1f6a23de6f6cb746 Mon Sep 17 00:00:00 2001 From: PatR Date: Wed, 12 Dec 2018 17:54:53 -0800 Subject: [PATCH 1/7] place_monster() warning bit --- src/steed.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/steed.c b/src/steed.c index 9eaf8f4c0..a90a0ce86 100644 --- a/src/steed.c +++ b/src/steed.c @@ -1,4 +1,4 @@ -/* NetHack 3.6 steed.c $NHDT-Date: 1544608468 2018/12/12 09:54:28 $ $NHDT-Branch: NetHack-3.6.2-beta01 $:$NHDT-Revision: 1.60 $ */ +/* NetHack 3.6 steed.c $NHDT-Date: 1544666049 2018/12/13 01:54:09 $ $NHDT-Branch: NetHack-3.6.2-beta01 $:$NHDT-Revision: 1.61 $ */ /* Copyright (c) Kevin Hugo, 1998-1999. */ /* NetHack may be freely redistributed. See license for details. */ @@ -756,7 +756,7 @@ int x, y; return; } if (level.monsters[x][y]) - impossible("placing monster over another?"); + impossible("placing monster over another at <%d,%d>?", x, y); mon->mx = x, mon->my = y; level.monsters[x][y] = mon; } From a63b9f29a5f8beace02ae4bc69b924a8c9758fe4 Mon Sep 17 00:00:00 2001 From: PatR Date: Wed, 12 Dec 2018 17:55:43 -0800 Subject: [PATCH 2/7] fuzzing hero boost I watched the fuzzer run for a bit and noticed that Str and most other characteristics were steadily dropping until they hit 3 and not being recovered, so I gave the defenseless hero a chance to benefit from blessed restore ability occasionally. It hasn't helped much. Str and Con both still drop to 3. [If I had to guess, I'd go with side-effect of polymorphing, but not an intended one.] --- src/end.c | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/src/end.c b/src/end.c index cbc312598..e90745cdb 100644 --- a/src/end.c +++ b/src/end.c @@ -1,4 +1,4 @@ -/* NetHack 3.6 end.c $NHDT-Date: 1544003110 2018/12/05 09:45:10 $ $NHDT-Branch: NetHack-3.6.2-beta01 $:$NHDT-Revision: 1.156 $ */ +/* NetHack 3.6 end.c $NHDT-Date: 1544666123 2018/12/13 01:55:23 $ $NHDT-Branch: NetHack-3.6.2-beta01 $:$NHDT-Revision: 1.157 $ */ /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */ /*-Copyright (c) Robert Patrick Rankin, 2012. */ /* NetHack may be freely redistributed. See license for details. */ @@ -577,13 +577,13 @@ VA_DECL(const char *, str) ? "Program initialization has failed." : "Suddenly, the dungeon collapses."); #ifndef MICRO -#if defined(NOTIFY_NETHACK_BUGS) +#ifdef NOTIFY_NETHACK_BUGS if (!wizard) raw_printf("Report the following error to \"%s\" or at \"%s\".", DEVTEAM_EMAIL, DEVTEAM_URL); else if (program_state.something_worth_saving) raw_print("\nError save file being written.\n"); -#else +#else /* !NOTIFY_NETHACK_BUGS */ if (!wizard) { const char *maybe_rebuild = !program_state.something_worth_saving ? "." @@ -599,7 +599,7 @@ VA_DECL(const char *, str) raw_printf("Report error to \"%s\"%s", WIZARD_NAME, maybe_rebuild); } -#endif +#endif /* ?NOTIFY_NETHACK_BUGS */ /* XXX can we move this above the prints? Then we'd be able to * suppress "it may be possible to rebuild" based on dosave0() * or say it's NOT possible to rebuild. */ @@ -611,7 +611,7 @@ VA_DECL(const char *, str) raw_printf("%s", sysopt.recover); } } -#endif +#endif /* !MICRO */ { char buf[BUFSZ]; @@ -1055,7 +1055,16 @@ int how; if (iflags.debug_fuzzer) { if (!(program_state.panicking || how == PANICKED)) { savelife(how); - killer.name[0] = 0; + /* periodically restore characteristics and lost exp levels */ + if (!rn2(10)) { + struct obj *potion = mksobj(POT_RESTORE_ABILITY, TRUE, FALSE); + + bless(potion); + (void) peffects(potion); /* always -1 for restore ability */ + /* not useup(); we haven't put this potion into inventory */ + obfree(potion, (struct obj *) 0); + } + killer.name[0] = '\0'; killer.format = 0; return; } From 59dcf73ad86be8175e246c173d0ecf427fbfb782 Mon Sep 17 00:00:00 2001 From: PatR Date: Wed, 12 Dec 2018 18:49:12 -0800 Subject: [PATCH 3/7] interactive !pickup_types To use 'O' to clear a value from pickup_types with menustyle Traditional or Combination, you needed to give a value starting with 'a' (for 'all'). Accept space(s) too, similar to removing an object or monster name. --- src/options.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/options.c b/src/options.c index 3a190b9c1..d0358caf0 100644 --- a/src/options.c +++ b/src/options.c @@ -1,4 +1,4 @@ -/* NetHack 3.6 options.c $NHDT-Date: 1544396581 2018/12/09 23:03:01 $ $NHDT-Branch: NetHack-3.6.2-beta01 $:$NHDT-Revision: 1.340 $ */ +/* NetHack 3.6 options.c $NHDT-Date: 1544669347 2018/12/13 02:49:07 $ $NHDT-Branch: NetHack-3.6.2-beta01 $:$NHDT-Revision: 1.343 $ */ /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */ /*-Copyright (c) Michael Allison, 2008. */ /* NetHack may be freely redistributed. See license for details. */ @@ -2986,12 +2986,17 @@ boolean tinitial, tfrom_file; use_menu = TRUE; if (flags.menu_style == MENU_TRADITIONAL || flags.menu_style == MENU_COMBINATION) { + boolean wasspace; + use_menu = FALSE; Sprintf(qbuf, "New %s: [%s am] (%s)", fullname, ocl, *tbuf ? tbuf : "all"); getlin(qbuf, abuf); + wasspace = (abuf[0] == ' '); /* before mungspaces */ op = mungspaces(abuf); - if (abuf[0] == '\0' || abuf[0] == '\033') + if (wasspace && !abuf[0]) + ; /* one or more spaces will remove old value */ + else if (!abuf[0] || abuf[0] == '\033') op = tbuf; /* restore */ else if (abuf[0] == 'm') use_menu = TRUE; From 05c253b6d85259e208270acc1cafd75772de44f9 Mon Sep 17 00:00:00 2001 From: PatR Date: Wed, 12 Dec 2018 18:55:06 -0800 Subject: [PATCH 4/7] show autopickup in ^X feedback Gathers all the autopickup information in one place: Auto-pickup is { off | on { for 'classes' [plus thrown] | all types } [, with exceptions] }. --- doc/fixes36.2 | 1 + include/extern.h | 3 ++- src/cmd.c | 18 +++++++++++++++++- src/options.c | 5 ++--- 4 files changed, 22 insertions(+), 5 deletions(-) diff --git a/doc/fixes36.2 b/doc/fixes36.2 index 51e6bfa69..26305aacf 100644 --- a/doc/fixes36.2 +++ b/doc/fixes36.2 @@ -406,6 +406,7 @@ for ^X and enlightenment, display the information in a menu rather than a '<' (menu_previous_page) and '^' (menu_first_page) menu keys; needed for interfaces (tty) without text popup scrollbar support; end of game disclosure of attributes remains single-forward-pass +for ^X, include current state of 'autopickup' NetHack Community Patches (or Variation) Included diff --git a/include/extern.h b/include/extern.h index 81b792aa9..1c88ca32f 100644 --- a/include/extern.h +++ b/include/extern.h @@ -1,4 +1,4 @@ -/* NetHack 3.6 extern.h $NHDT-Date: 1544401264 2018/12/10 00:21:04 $ $NHDT-Branch: NetHack-3.6.2-beta01 $:$NHDT-Revision: 1.666 $ */ +/* NetHack 3.6 extern.h $NHDT-Date: 1544669659 2018/12/13 02:54:19 $ $NHDT-Branch: NetHack-3.6.2-beta01 $:$NHDT-Revision: 1.667 $ */ /* Copyright (c) Steve Creps, 1988. */ /* NetHack may be freely redistributed. See license for details. */ @@ -1729,6 +1729,7 @@ E int FDECL(fruitadd, (char *, struct fruit *)); E int FDECL(choose_classes_menu, (const char *, int, BOOLEAN_P, char *, char *)); E boolean FDECL(parsebindings, (char *)); +E void FDECL(oc_to_str, (char *, char *)); E void FDECL(add_menu_cmd_alias, (CHAR_P, CHAR_P)); E char FDECL(get_menu_cmd_key, (CHAR_P)); E char FDECL(map_menu_cmd, (CHAR_P)); diff --git a/src/cmd.c b/src/cmd.c index 67170cec7..5f484bebf 100644 --- a/src/cmd.c +++ b/src/cmd.c @@ -1,4 +1,4 @@ -/* NetHack 3.6 cmd.c $NHDT-Date: 1544050555 2018/12/05 22:55:55 $ $NHDT-Branch: NetHack-3.6.2-beta01 $:$NHDT-Revision: 1.314 $ */ +/* NetHack 3.6 cmd.c $NHDT-Date: 1544669664 2018/12/13 02:54:24 $ $NHDT-Branch: NetHack-3.6.2-beta01 $:$NHDT-Revision: 1.315 $ */ /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */ /*-Copyright (c) Robert Patrick Rankin, 2013. */ /* NetHack may be freely redistributed. See license for details. */ @@ -2019,6 +2019,22 @@ int final; enl_msg(Your_wallet, "contains ", "contained ", buf, ""); } } + + if (flags.pickup) { + char ocl[MAXOCLASSES + 1]; + + Strcpy(buf, "on"); + oc_to_str(flags.pickup_types, ocl); + Sprintf(eos(buf), " for %s%s%s", + *ocl ? "'" : "", *ocl ? ocl : "all types", *ocl ? "'" : ""); + if (flags.pickup_thrown && *ocl) /* *ocl: don't show if 'all types' */ + Strcat(buf, " plus thrown"); + if (iflags.autopickup_exceptions[AP_GRAB] + || iflags.autopickup_exceptions[AP_LEAVE]) + Strcat(buf, ", with exceptions"); + } else + Strcpy(buf, "off"); + enl_msg("Auto-pickup ", "is ", "was ", buf, ""); } /* characteristics: expanded version of bottom line strength, dexterity, &c */ diff --git a/src/options.c b/src/options.c index d0358caf0..6419c55f0 100644 --- a/src/options.c +++ b/src/options.c @@ -1,4 +1,4 @@ -/* NetHack 3.6 options.c $NHDT-Date: 1544669347 2018/12/13 02:49:07 $ $NHDT-Branch: NetHack-3.6.2-beta01 $:$NHDT-Revision: 1.343 $ */ +/* NetHack 3.6 options.c $NHDT-Date: 1544669666 2018/12/13 02:54:26 $ $NHDT-Branch: NetHack-3.6.2-beta01 $:$NHDT-Revision: 1.344 $ */ /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */ /*-Copyright (c) Michael Allison, 2008. */ /* NetHack may be freely redistributed. See license for details. */ @@ -557,7 +557,6 @@ STATIC_DCL int NDECL(count_menucolors); STATIC_DCL boolean FDECL(parse_role_opts, (BOOLEAN_P, const char *, char *, char **)); -STATIC_DCL void FDECL(oc_to_str, (char *, char *)); STATIC_DCL void FDECL(doset_add_menu, (winid, const char *, int)); STATIC_DCL void FDECL(opts_add_others, (winid, const char *, int, char *, int)); @@ -4086,7 +4085,7 @@ static NEARDATA const char *sortltype[] = { "none", "loot", "full" }; * Convert the given string of object classes to a string of default object * symbols. */ -STATIC_OVL void +void oc_to_str(src, dest) char *src, *dest; { From 0cd50847fb75a9b9e08a9dbcc362d3aef5653258 Mon Sep 17 00:00:00 2001 From: Bart House Date: Wed, 12 Dec 2018 21:46:14 -0800 Subject: [PATCH 5/7] Changes to get fuzzer working in NetHackW. --- include/extern.h | 1 + src/cmd.c | 21 +++++++++++++++++ sys/winnt/windmain.c | 5 +++- win/win32/mhdlg.c | 8 +++++++ win/win32/mhmain.c | 5 ++++ win/win32/mhmap.c | 6 ++++- win/win32/mhmenu.c | 12 ++++++++++ win/win32/mhmsg.h | 1 + win/win32/mhmsgwnd.c | 4 ++++ win/win32/mhrip.c | 5 ++++ win/win32/mhstatus.c | 5 ++++ win/win32/mhtext.c | 13 +++++++++++ win/win32/mswproc.c | 55 +++++++++++++++++++++++++++++--------------- 13 files changed, 121 insertions(+), 20 deletions(-) diff --git a/include/extern.h b/include/extern.h index 81b792aa9..c7fd71868 100644 --- a/include/extern.h +++ b/include/extern.h @@ -174,6 +174,7 @@ E boolean NDECL(status_hilite_menu); /* ### cmd.c ### */ E char NDECL(randomkey); +E void FDECL(random_response, (char * buf, int size)); E int NDECL(doconduct); E int NDECL(domonability); E char FDECL(cmd_from_func, (int NDECL((*)))); diff --git a/src/cmd.c b/src/cmd.c index 67170cec7..65bea3080 100644 --- a/src/cmd.c +++ b/src/cmd.c @@ -4421,6 +4421,27 @@ randomkey() return c; } +void random_response(char * buf, int size) +{ + int count = 0; + while (1) { + char c = randomkey(); + + if (c == '\n') + break; + + if (c == '\033') { + count = 0; + break; + } + + if (count < size) + buf[count++] = c; + } + + buf[count] = '\0'; +} + int ch2spkeys(c, start, end) char c; diff --git a/sys/winnt/windmain.c b/sys/winnt/windmain.c index d8b7c8056..15ae95d87 100644 --- a/sys/winnt/windmain.c +++ b/sys/winnt/windmain.c @@ -348,7 +348,10 @@ attempt_restore: if (discover) You("are in non-scoring discovery mode."); } - moveloop(resuming); + + // iflags.debug_fuzzer = TRUE; + + moveloop(resuming); nethack_exit(EXIT_SUCCESS); /*NOTREACHED*/ return 0; diff --git a/win/win32/mhdlg.c b/win/win32/mhdlg.c index 6bc7d4eb3..8a158bee9 100644 --- a/win/win32/mhdlg.c +++ b/win/win32/mhdlg.c @@ -25,6 +25,14 @@ INT_PTR CALLBACK GetlinDlgProc(HWND, UINT, WPARAM, LPARAM); int mswin_getlin_window(const char *question, char *result, size_t result_size) { + if (iflags.debug_fuzzer) { + random_response(result, result_size); + if (result[0] != '\0') + return IDOK; + else + return IDCANCEL; + } + INT_PTR ret; struct getlin_data data; diff --git a/win/win32/mhmain.c b/win/win32/mhmain.c index a71534703..a8742b03f 100644 --- a/win/win32/mhmain.c +++ b/win/win32/mhmain.c @@ -529,6 +529,11 @@ onMSNHCommand(HWND hWnd, WPARAM wParam, LPARAM lParam) child = GetNHApp()->windowlist[msg_param->wid].win; } break; + + case MSNH_MSG_RANDOM_INPUT: + nhassert(0); // unexpected + break; + } } diff --git a/win/win32/mhmap.c b/win/win32/mhmap.c index b883cd7bd..18bca2571 100644 --- a/win/win32/mhmap.c +++ b/win/win32/mhmap.c @@ -722,7 +722,11 @@ onMSNHCommand(HWND hWnd, WPARAM wParam, LPARAM lParam) } } break; - } /* end switch(wParam) */ + case MSNH_MSG_RANDOM_INPUT: + nhassert(0); // unexpected + break; + + } /* end switch(wParam) */ } /* on WM_CREATE */ diff --git a/win/win32/mhmenu.c b/win/win32/mhmenu.c index 5e38d0235..34fe28a1a 100644 --- a/win/win32/mhmenu.c +++ b/win/win32/mhmenu.c @@ -687,6 +687,18 @@ onMSNHCommand(HWND hWnd, WPARAM wParam, LPARAM lParam) ZeroMemory(data->menu.prompt, sizeof(data->menu.prompt)); } } break; + + case MSNH_MSG_RANDOM_INPUT: { + char c = randomkey(); + if (c == '\n') + PostMessage(hWnd, WM_COMMAND, MAKELONG(IDOK, 0), 0); + else if (c == '\033') + PostMessage(hWnd, WM_COMMAND, MAKELONG(IDCANCEL, 0), 0); + else + PostMessage(GetDlgItem(hWnd, IDC_TEXT_CONTROL), WM_CHAR, c, 0); + + } break; + } } /*-----------------------------------------------------------------------------*/ diff --git a/win/win32/mhmsg.h b/win/win32/mhmsg.h index 7eb65d0c0..4fd04af01 100644 --- a/win/win32/mhmsg.h +++ b/win/win32/mhmsg.h @@ -21,6 +21,7 @@ #define MSNH_MSG_CARET 110 #define MSNH_MSG_GETTEXT 111 #define MSNH_MSG_UPDATE_STATUS 112 +#define MSNH_MSG_RANDOM_INPUT 113 typedef struct mswin_nhmsg_add_wnd { winid wid; diff --git a/win/win32/mhmsgwnd.c b/win/win32/mhmsgwnd.c index 505b40f36..58df28c63 100644 --- a/win/win32/mhmsgwnd.c +++ b/win/win32/mhmsgwnd.c @@ -416,6 +416,10 @@ onMSNHCommand(HWND hWnd, WPARAM wParam, LPARAM lParam) } } break; + case MSNH_MSG_RANDOM_INPUT: + nhassert(0); // unexpected + break; + } /* switch( wParam ) */ } diff --git a/win/win32/mhrip.c b/win/win32/mhrip.c index 79ad05342..f00004f09 100644 --- a/win/win32/mhrip.c +++ b/win/win32/mhrip.c @@ -282,6 +282,11 @@ onMSNHCommand(HWND hWnd, WPARAM wParam, LPARAM lParam) data->window_text = NULL; break; } + + case MSNH_MSG_RANDOM_INPUT: + nhassert(0); // unexpected + break; + } } diff --git a/win/win32/mhstatus.c b/win/win32/mhstatus.c index d5bfda092..20b09f094 100644 --- a/win/win32/mhstatus.c +++ b/win/win32/mhstatus.c @@ -219,6 +219,11 @@ StatusWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) data->status_lines = msg_data->status_lines; InvalidateRect(hWnd, NULL, TRUE); } break; + + case MSNH_MSG_RANDOM_INPUT: + nhassert(0); // unexpected + break; + } /* end switch( wParam ) { */ } break; diff --git a/win/win32/mhtext.c b/win/win32/mhtext.c index 8c1c2b32f..14092d52f 100644 --- a/win/win32/mhtext.c +++ b/win/win32/mhtext.c @@ -212,6 +212,19 @@ onMSNHCommand(HWND hWnd, WPARAM wParam, LPARAM lParam) _tcscat(data->window_text, TEXT("\r\n")); break; } + + case MSNH_MSG_RANDOM_INPUT: { + char c = randomkey(); + if (c == '\n') + PostMessage(hWnd, WM_COMMAND, MAKELONG(IDOK, 0), 0); + else if (c == '\033') + PostMessage(hWnd, WM_COMMAND, MAKELONG(IDCANCEL, 0), 0); + else + PostMessage(GetDlgItem(hWnd, IDC_TEXT_CONTROL), WM_CHAR, c, 0); + + } + break; + } } diff --git a/win/win32/mswproc.c b/win/win32/mswproc.c index 85f427725..0a6cde13d 100644 --- a/win/win32/mswproc.c +++ b/win/win32/mswproc.c @@ -2102,14 +2102,24 @@ mswin_main_loop() { MSG msg; - while (!mswin_have_input() && GetMessage(&msg, NULL, 0, 0) != 0) { - if (GetNHApp()->regNetHackMode - || !TranslateAccelerator(msg.hwnd, GetNHApp()->hAccelTable, - &msg)) { - TranslateMessage(&msg); - DispatchMessage(&msg); - } - } + while (!mswin_have_input()) { + if (!iflags.debug_fuzzer || PeekMessage(&msg, NULL, 0, 0, FALSE)) { + if(GetMessage(&msg, NULL, 0, 0) != 0) { + if (GetNHApp()->regNetHackMode + || !TranslateAccelerator(msg.hwnd, GetNHApp()->hAccelTable, + &msg)) { + TranslateMessage(&msg); + DispatchMessage(&msg); + } + } else { + /* WM_QUIT */ + break; + } + } else { + nhassert(iflags.debug_fuzzer); + NHEVENT_KBD(randomkey()); + } + } } /* clean up and quit */ @@ -2222,16 +2232,25 @@ mswin_popup_display(HWND hWnd, int *done_indicator) SetFocus(hWnd); /* go into message loop */ - while (IsWindow(hWnd) && (done_indicator == NULL || !*done_indicator) - && GetMessage(&msg, NULL, 0, 0) != 0) { - if (!IsDialogMessage(hWnd, &msg)) { - if (!TranslateAccelerator(msg.hwnd, GetNHApp()->hAccelTable, - &msg)) { - TranslateMessage(&msg); - DispatchMessage(&msg); - } - } - } + while (IsWindow(hWnd) && (done_indicator == NULL || !*done_indicator)) { + if (!iflags.debug_fuzzer || PeekMessage(&msg, NULL, 0, 0, FALSE)) { + if(GetMessage(&msg, NULL, 0, 0) != 0) { + if (!IsDialogMessage(hWnd, &msg)) { + if (!TranslateAccelerator(msg.hwnd, GetNHApp()->hAccelTable, + &msg)) { + TranslateMessage(&msg); + DispatchMessage(&msg); + } + } + } else { + /* WM_QUIT */ + break; + } + } else { + nhassert(iflags.debug_fuzzer); + PostMessage(hWnd, WM_MSNH_COMMAND, MSNH_MSG_RANDOM_INPUT, 0); + } + } } void From f9beca06dcbe6c3088a4182883dce0342c02f436 Mon Sep 17 00:00:00 2001 From: nhmall Date: Thu, 13 Dec 2018 01:36:36 -0500 Subject: [PATCH 6/7] core code style --- src/cmd.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/cmd.c b/src/cmd.c index 15c099e99..013c99416 100644 --- a/src/cmd.c +++ b/src/cmd.c @@ -4437,7 +4437,10 @@ randomkey() return c; } -void random_response(char * buf, int size) +void +random_response(buf, sz) +char *buf; +int sz; { int count = 0; while (1) { @@ -4451,7 +4454,7 @@ void random_response(char * buf, int size) break; } - if (count < size) + if (count < sz) buf[count++] = c; } From cf7536b1675f0b6074775c4ca984ffdde76c058c Mon Sep 17 00:00:00 2001 From: PatR Date: Thu, 13 Dec 2018 02:12:31 -0800 Subject: [PATCH 7/7] random_response() buffer overflow 'sz' is the size of the buffer; 'if (count < sz) buf[count++] = c;' can fill the entire buffer, leaving count==sz, so buf[count] = '\0'; would be out of bounds. Formatting was way off. Indentation these days should be multiples of 4 spaces, never tabs. --- src/cmd.c | 32 +++++++++++++++----------------- win/win32/mhdlg.c | 16 ++++++++-------- 2 files changed, 23 insertions(+), 25 deletions(-) diff --git a/src/cmd.c b/src/cmd.c index 013c99416..579e4810b 100644 --- a/src/cmd.c +++ b/src/cmd.c @@ -1,4 +1,4 @@ -/* NetHack 3.6 cmd.c $NHDT-Date: 1544669664 2018/12/13 02:54:24 $ $NHDT-Branch: NetHack-3.6.2-beta01 $:$NHDT-Revision: 1.315 $ */ +/* NetHack 3.6 cmd.c $NHDT-Date: 1544695944 2018/12/13 10:12:24 $ $NHDT-Branch: NetHack-3.6.2-beta01 $:$NHDT-Revision: 1.318 $ */ /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */ /*-Copyright (c) Robert Patrick Rankin, 2013. */ /* NetHack may be freely redistributed. See license for details. */ @@ -4442,23 +4442,21 @@ random_response(buf, sz) char *buf; int sz; { - int count = 0; - while (1) { - char c = randomkey(); + char c; + int count = 0; - if (c == '\n') - break; - - if (c == '\033') { - count = 0; - break; - } - - if (count < sz) - buf[count++] = c; - } - - buf[count] = '\0'; + for (;;) { + c = randomkey(); + if (c == '\n') + break; + if (c == '\033') { + count = 0; + break; + } + if (count < sz - 1) + buf[count++] = c; + } + buf[count] = '\0'; } int diff --git a/win/win32/mhdlg.c b/win/win32/mhdlg.c index 8a158bee9..bb92d5318 100644 --- a/win/win32/mhdlg.c +++ b/win/win32/mhdlg.c @@ -1,4 +1,4 @@ -/* NetHack 3.6 mhdlg.c $NHDT-Date: 1432512812 2015/05/25 00:13:32 $ $NHDT-Branch: master $:$NHDT-Revision: 1.25 $ */ +/* NetHack 3.6 mhdlg.c $NHDT-Date: 1544695946 2018/12/13 10:12:26 $ $NHDT-Branch: NetHack-3.6.2-beta01 $:$NHDT-Revision: 1.30 $ */ /* Copyright (C) 2001 by Alex Kompel */ /* NetHack may be freely redistributed. See license for details. */ @@ -25,13 +25,13 @@ INT_PTR CALLBACK GetlinDlgProc(HWND, UINT, WPARAM, LPARAM); int mswin_getlin_window(const char *question, char *result, size_t result_size) { - if (iflags.debug_fuzzer) { - random_response(result, result_size); - if (result[0] != '\0') - return IDOK; - else - return IDCANCEL; - } + if (iflags.debug_fuzzer) { + random_response(result, (int) result_size); + if (result[0] != '\0') + return IDOK; + else + return IDCANCEL; + } INT_PTR ret; struct getlin_data data;