Commit 488cc92
committed
Fix: multiple issues in allmain.c found via code review.
Mixed bag of defensive fixes, one potential crash, and cleanup
landed in moveloop() and argcheck():
* src/allmain.c: in the pet-overage untaming loop, skip monsters
with isminion set. EDOG() expands to mextra->edog, which is
NULL for monsters that carry emin instead, so the abuse read
at `rn2(EDOG(weakdog)->abuse + 1)` would NULL-deref. Not
currently reachable on Astral (EvilHack spawns the Red Horse
via MM_EDOG rather than a guardian angel with emin), but
matches the canonical `mtame && !isminion` invariant used at
mon.c:107 and ~16 other sites.
* src/allmain.c: in the Gauntlets of Purity force-disarm block,
clear u.twoweap before dropping both weapons. dropz() clears
the uwep/uswapwep globals but never touches u.twoweap, so the
two-weapon path was leaving a stale u.twoweap=TRUE with both
weapon slots NULL. Any later guard of the form
`u.twoweap && uswapwep->...` (flees_light, the elf/orc
regen checks in this same function, weapon property reads)
would NULL-deref on the next read.
* src/allmain.c: add set_malign() after clearing mpeaceful in
the pet-overage untame path, and after the tame/peaceful
branch in the banes anger block. setmangry() early-returns
when mtame is still set, so in both cases malign was never
resynced after the transition to hostile.
* src/allmain.c: add (void) casts to the six dropx() calls in
the Gauntlets of Purity block. dropx() returns boolean (TRUE
when flooreffects destroyed the object) and was being
silently discarded; no immediate UAF since nothing dereferences
the object afterwards, but aligns with the surrounding
(void) Shield_off() / (void) Gloves_off() style and the
convention established by prior dropy/dropx audits.
* src/allmain.c: fix -version:foo error path in argcheck() to
return 2 (exit) instead of TRUE (continue), matching the
success path and the other exit-on-error arguments. Previous
behavior printed the diagnostic and then launched the game,
scrolling the error off-screen.
* src/allmain.c: ARG_WINDOWS case without an extended_opt now
returns 1, matching the "found and skip" contract documented
at the top of argcheck(). Previously fell through the switch
and returned FALSE despite a successful match.
* src/allmain.c: retype debug_fields() parameter from
`const char *` to `char *` to match its actual behavior - the
body writes through the pointer at both the comma-splitting
site and the trailing-whitespace strip. Callers pass argv, so
the cast-through-const was harmless but dishonest. Drop the
`(char *)` cast on the eos() call now that it is unneeded.
* src/allmain.c: convert the `while` loop at the top of
debug_fields() to `if`. After `*op++ = 0` cuts the string at
the first comma, opts has no further commas, so the loop
always exits after one iteration - the comma-list walk is
actually driven by the recursive debug_fields(op) call.
* src/allmain.c: cache elf_can_regen() and orc_can_regen()
per-iteration. Each helper does a full worn-inventory scan
for iron/mithril and was being called up to three times per
player turn in the regen-state gate block.
* src/allmain.c: remove stray `;` after the switch in
argcheck(). Harmless empty statement.1 parent de3c433 commit 488cc92
2 files changed
Lines changed: 50 additions & 30 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
5210 | 5210 | | |
5211 | 5211 | | |
5212 | 5212 | | |
| 5213 | + | |
5213 | 5214 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
17 | 17 | | |
18 | 18 | | |
19 | 19 | | |
20 | | - | |
| 20 | + | |
21 | 21 | | |
22 | 22 | | |
23 | 23 | | |
| |||
371 | 371 | | |
372 | 372 | | |
373 | 373 | | |
| 374 | + | |
374 | 375 | | |
375 | 376 | | |
376 | 377 | | |
377 | 378 | | |
378 | 379 | | |
379 | | - | |
| 380 | + | |
| 381 | + | |
| 382 | + | |
| 383 | + | |
380 | 384 | | |
381 | 385 | | |
382 | 386 | | |
| |||
413 | 417 | | |
414 | 418 | | |
415 | 419 | | |
| 420 | + | |
416 | 421 | | |
417 | 422 | | |
418 | 423 | | |
| |||
760 | 765 | | |
761 | 766 | | |
762 | 767 | | |
| 768 | + | |
| 769 | + | |
| 770 | + | |
763 | 771 | | |
764 | 772 | | |
765 | 773 | | |
| |||
856 | 864 | | |
857 | 865 | | |
858 | 866 | | |
859 | | - | |
860 | | - | |
861 | | - | |
862 | | - | |
863 | | - | |
864 | | - | |
865 | | - | |
866 | | - | |
| 867 | + | |
| 868 | + | |
| 869 | + | |
| 870 | + | |
| 871 | + | |
| 872 | + | |
| 873 | + | |
| 874 | + | |
| 875 | + | |
| 876 | + | |
| 877 | + | |
| 878 | + | |
867 | 879 | | |
868 | | - | |
869 | | - | |
870 | | - | |
871 | | - | |
872 | | - | |
873 | | - | |
874 | | - | |
| 880 | + | |
| 881 | + | |
| 882 | + | |
| 883 | + | |
| 884 | + | |
| 885 | + | |
| 886 | + | |
| 887 | + | |
875 | 888 | | |
876 | 889 | | |
877 | 890 | | |
| |||
903 | 916 | | |
904 | 917 | | |
905 | 918 | | |
906 | | - | |
907 | | - | |
| 919 | + | |
| 920 | + | |
| 921 | + | |
| 922 | + | |
| 923 | + | |
| 924 | + | |
908 | 925 | | |
909 | 926 | | |
910 | 927 | | |
911 | 928 | | |
912 | 929 | | |
913 | | - | |
914 | | - | |
| 930 | + | |
| 931 | + | |
915 | 932 | | |
916 | 933 | | |
917 | 934 | | |
918 | 935 | | |
919 | | - | |
| 936 | + | |
920 | 937 | | |
921 | 938 | | |
922 | 939 | | |
923 | | - | |
| 940 | + | |
924 | 941 | | |
925 | 942 | | |
926 | 943 | | |
| |||
1485 | 1502 | | |
1486 | 1503 | | |
1487 | 1504 | | |
1488 | | - | |
| 1505 | + | |
1489 | 1506 | | |
1490 | 1507 | | |
1491 | 1508 | | |
| |||
1507 | 1524 | | |
1508 | 1525 | | |
1509 | 1526 | | |
1510 | | - | |
| 1527 | + | |
1511 | 1528 | | |
1512 | 1529 | | |
1513 | 1530 | | |
| |||
1526 | 1543 | | |
1527 | 1544 | | |
1528 | 1545 | | |
| 1546 | + | |
1529 | 1547 | | |
1530 | 1548 | | |
1531 | 1549 | | |
1532 | 1550 | | |
1533 | 1551 | | |
1534 | | - | |
| 1552 | + | |
1535 | 1553 | | |
1536 | 1554 | | |
1537 | 1555 | | |
| |||
1549 | 1567 | | |
1550 | 1568 | | |
1551 | 1569 | | |
1552 | | - | |
| 1570 | + | |
1553 | 1571 | | |
1554 | 1572 | | |
1555 | 1573 | | |
1556 | 1574 | | |
1557 | | - | |
| 1575 | + | |
| 1576 | + | |
| 1577 | + | |
1558 | 1578 | | |
1559 | | - | |
1560 | 1579 | | |
1561 | 1580 | | |
1562 | 1581 | | |
| |||
1565 | 1584 | | |
1566 | 1585 | | |
1567 | 1586 | | |
1568 | | - | |
| 1587 | + | |
1569 | 1588 | | |
1570 | 1589 | | |
1571 | 1590 | | |
| |||
0 commit comments