Skip to content

Commit cdfc27a

Browse files
committed
Fix: segfault when reading NON_PM empty tin
This is yet another bug due to the failure to realize NON_PM is -1, not 0. Apparently this segfault would only happen when there is a NON_PM tin which is not spinach, which I initially considered to be an impossible case, but which turns out is actually possible when tin creation gives up trying to pick a monster. There is handling for opening and identifying such "empty" tins, so the "truthful" style of tin label will now also handle it properly.
1 parent 3e1fe5a commit cdfc27a

1 file changed

Lines changed: 8 additions & 2 deletions

File tree

src/read.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -292,13 +292,19 @@ tin_text(struct obj *tin, char* buf)
292292
if (food == HOMEMADE_TIN || !tin_msgs[msgidx]) {
293293
return (char *) 0;
294294
}
295-
if (tin->tinseed % 5 == 0 && tin->corpsenm) { /* be truthful */
295+
if (tin->tinseed % 5 == 0) { /* be truthful */
296296
msgidx = (tin->tinseed % NUM_MONST_LABELS) + LABEL_MONST_START;
297297
if (food == SPINACH_TIN) {
298298
Strcpy(format_arg, "spinach");
299-
} else {
299+
}
300+
else if (tin->corpsenm != NON_PM) {
300301
Strcpy(format_arg, mons[tin->corpsenm].pmnames[NEUTRAL]);
301302
}
303+
else {
304+
/* empty tin; not an impossible case, just very unlikely, when tin
305+
* creation fails to pick a tinnable monster 200 times */
306+
Strcpy(format_arg, "nothing");
307+
}
302308
}
303309
else { /* lie */
304310
if (msgidx == LABEL_BOGUSMON) {

0 commit comments

Comments
 (0)