fix reported crash of TTY_PERM_INVENT segfaulting
Options processing can be early, even before ttyDisplay is allocated. If we find that TTY_PERM_INVENT initialization is happening too early, just set a marker (iflags.perm_invent_pending) to try again a bit later. The changes in win/share are just to be able to sucessfully reproduce the original issue on Windows. It was easily reproduced on Unix, just by building with TTY_PERM_INVENT in include/config.h and setting OPTIONS=perm_invent in config file.
This commit is contained in:
@@ -510,13 +510,23 @@ safe_update_inventory(int arg UNUSED)
|
||||
return;
|
||||
}
|
||||
|
||||
#ifdef WIN32CON
|
||||
extern win_request_info *tty_ctrl_nhwindow(winid window UNUSED,
|
||||
int request UNUSED,
|
||||
win_request_info *wri UNUSED);
|
||||
#endif
|
||||
|
||||
win_request_info *
|
||||
safe_ctrl_nhwindow(
|
||||
winid window UNUSED,
|
||||
int request UNUSED,
|
||||
win_request_info *wri UNUSED)
|
||||
{
|
||||
#ifdef WIN32CON
|
||||
return (*tty_ctrl_nhwindow)(window, request, wri);
|
||||
#else
|
||||
return (win_request_info *) 0;
|
||||
#endif
|
||||
}
|
||||
|
||||
/**************************************************************
|
||||
|
||||
+30
-15
@@ -2861,22 +2861,29 @@ tty_ctrl_nhwindow(
|
||||
wri->tocore = zero_tocore;
|
||||
tty_ok = assesstty(ttyinvmode, &offx, &offy, &rows, &cols, &maxcol,
|
||||
&minrow, &maxrow);
|
||||
wri->tocore.needrows = (int) (minrow + 1 + ROWNO + StatusRows());
|
||||
wri->tocore.needcols = (int) tty_perminv_mincol;
|
||||
wri->tocore.haverows = (int) ttyDisplay->rows;
|
||||
wri->tocore.havecols = (int) ttyDisplay->cols;
|
||||
if (!tty_ok) {
|
||||
#ifdef RESIZABLE
|
||||
/* terminal isn't big enough right now but player might resize it
|
||||
and then use 'm O' to try to set 'perm_invent' again */
|
||||
wri->tocore.tocore_flags |= too_small;
|
||||
#else
|
||||
wri->tocore.tocore_flags |= prohibited;
|
||||
#endif
|
||||
if (!tty_ok && rows == 0 && cols == 0) {
|
||||
/* something is terribly wrong, possibly too early in startup */
|
||||
wri->tocore.tocore_flags |= too_early;
|
||||
} else {
|
||||
maxslot = (maxrow - 2) * (!inuse_only ? 2 : 1);
|
||||
wri->tocore.maxslot = maxslot;
|
||||
}
|
||||
wri->tocore.needrows = (int) (minrow + 1 + ROWNO + StatusRows());
|
||||
wri->tocore.needcols = (int) tty_perminv_mincol;
|
||||
wri->tocore.haverows = (int) ttyDisplay->rows;
|
||||
wri->tocore.havecols = (int) ttyDisplay->cols;
|
||||
if (!tty_ok) {
|
||||
#ifdef RESIZABLE
|
||||
/* terminal isn't big enough right now but player might
|
||||
* resize it and then use 'm O' to try to set 'perm_invent'
|
||||
* again
|
||||
*/
|
||||
wri->tocore.tocore_flags |= too_small;
|
||||
#else
|
||||
wri->tocore.tocore_flags |= prohibited;
|
||||
#endif
|
||||
} else {
|
||||
maxslot = (maxrow - 2) * (!inuse_only ? 2 : 1);
|
||||
wri->tocore.maxslot = maxslot;
|
||||
}
|
||||
}
|
||||
#endif /* TTY_PERM_INVENT */
|
||||
break;
|
||||
case set_menu_promptstyle:
|
||||
@@ -3542,6 +3549,14 @@ assesstty(
|
||||
show_gold = (invmode & InvShowGold) != 0 && !inuse_only;
|
||||
int perminv_minrow = tty_perminv_minrow + (show_gold ? 1 : 0);
|
||||
|
||||
if (!ttyDisplay) {
|
||||
/* too early */
|
||||
*offx = *offy = *rows = *cols = 0;
|
||||
*maxcol = 0;
|
||||
*minrow = *maxrow = 0;
|
||||
return !(*rows < perminv_minrow || *cols < tty_perminv_mincol);
|
||||
}
|
||||
|
||||
*offx = 0;
|
||||
/* topline + map rows + status lines */
|
||||
*offy = 1 + ROWNO + StatusRows(); /* 1 + 21 + (2 or 3) */
|
||||
|
||||
Reference in New Issue
Block a user