]> granicus.if.org Git - nethack/commitdiff
impossible fix - potentially invalid feedback
authornethack.rankin <nethack.rankin>
Sat, 9 Feb 2013 01:33:37 +0000 (01:33 +0000)
committernethack.rankin <nethack.rankin>
Sat, 9 Feb 2013 01:33:37 +0000 (01:33 +0000)
     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().

doc/fixes35.0
src/pline.c

index cdd75913c96f84afc331da241c8472ab05f7f90d..1b15c59fe4af48cb567902216bf4006c9e321e11 100644 (file)
@@ -847,6 +847,7 @@ when a monster zapped by polymorph drops inventory because of its new form,
 entering an untended shop while blind gave an inappropriate message
 engraving feedback about partial text when weapon became too dull to finish
        was lacking sentence-ending period
+impossible() might display inaccurate feedback after updating paniclog
 
 
 Platform- and/or Interface-Specific Fixes
index 53029c8dc73d370d5d726e66018304ac351a4259..d4cdb9c43ffbdb053cbe90e5da1bb92952b0591d 100644 (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();