impossible fix - potentially invalid feedback

From a bug report, the message displayed to the screen by
impossible() might be different from the one written into paniclog, if it
had argument subsitution/formatting.  I couldn't reproduce that myself,
but stdarg.h/varargs.h is tricky stuff and I think that passing the va_list
to a routine which steps through it requires that va_start be called again
if you're going to use the va_list a second time.  This changes impossible()
to handle its arguments only once, like panic().
This commit is contained in:
nethack.rankin
2013-02-09 01:33:37 +00:00
parent 6847b78316
commit 1183aa6805
2 changed files with 8 additions and 7 deletions

View File

@@ -302,17 +302,17 @@ raw_printf VA_DECL(const char *, line)
/*VARARGS1*/
void
impossible VA_DECL(const char *, s)
char pbuf[2*BUFSZ];
VA_START(s);
VA_INIT(s, const char *);
if (program_state.in_impossible)
panic("impossible called impossible");
panic("impossible called impossible");
program_state.in_impossible = 1;
{
char pbuf[BUFSZ];
Vsprintf(pbuf,s,VA_ARGS);
paniclog("impossible", pbuf);
}
vpline(s,VA_ARGS);
Vsprintf(pbuf, s, VA_ARGS);
pbuf[BUFSZ-1] = '\0'; /* sanity */
paniclog("impossible", pbuf);
pline("%s", pbuf);
pline("Program in disorder - perhaps you'd better #quit.");
program_state.in_impossible = 0;
VA_END();