Handle when print_paddr tries to print invalid strings
In the PunyInform libary there's an object, CheapScenery
that lhave code like below:
default:
#ifdef SceneryReply;
if(SceneryReply ofclass string)
print_ret (string) SceneryReply;
i = location.&cheap_scenery;
w1 = self.number;
if(SceneryReply(i-->w1, i-->(w1 + 1)))
rtrue;
#endif;
"No need to concern yourself with that.";
The SceneryReply
can both be a string or a routine, which makes the compiler to compile this unreachable code print_ret (string) SceneryReply;
in the case it is a routine. When TXD tries to decompile this it throw a message to stderr
, Warning: printing of nonexistent string
. The decompiled snippet looks like below:
Routine 43b4, 2 locals
43b5: 41 f9 01 43 JE Ge9,#01 [FALSE] 43ba
43b9: b1 RFALSE
43ba: e0 07 42 6c 10 bf 04 00 CALL_VS 109b0 (#10bf,#04) -> -(SP)
43c2: a0 00 c7 JZ (SP)+ [TRUE] 43ca
43c5: 8d 10 bf PRINT_PADDR 42fc
43c8: bb NEW_LINE
43c9: b0 RTRUE
43ca: e0 23 41 f1 10 00 4a 01 CALL_VS 107c4 (G00,#004a) -> L00
43d2: 51 fb 08 ff GET_PROP Geb,#08 -> Gef
43d6: 2d 02 ff STORE L01,Gef
43d9: 54 02 01 00 ADD L01,#01 -> -(SP)
43dd: 6f 01 00 00 LOADW L00,(SP)+ -> -(SP)
43e1: 6f 01 02 00 LOADW L00,L01 -> -(SP)
43e5: e0 2b 10 bf 00 00 00 CALL_VS 42fc ((SP)+,(SP)+) -> -(SP)
43ec: a0 00 41 JZ (SP)+ [FALSE] RTRUE
43ef: b3 ... PRINT_RET "No need to concern yourself
with that."
It would be better if it printed print_paddr [invalid string: 42fc]
This can be done by changing this snippet in txd.c
case STATIC:
if (decode.first_pass == 0) {
addr = (unsigned long) code_scaler * value +
(unsigned long) story_scaler * header.strings_offset;
string = lookup_string (addr);
if (string != 0)
tx_printf ("%c%03d", (option_inform) ? 's' : 'S', (int) string);
else {
#ifndef TXD_DEBUG
(void) fprintf (stderr,
"\nWarning: printing of nonexistent string\n");
#endif
tx_printf ("%lx", addr);
}
}
to
case STATIC:
if (decode.first_pass == 0) {
addr = (unsigned long) code_scaler * value +
(unsigned long) story_scaler * header.strings_offset;
string = lookup_string (addr);
if (string != 0)
tx_printf ("%c%03d", (option_inform) ? 's' : 'S', (int) string);
else
tx_printf ("[invalid string: %lx]", addr);
}