Commit Graph

16252 Commits

Author SHA1 Message Date
PatR
d86e6e9717 clean up acurr()
Replace the early returns in acurr() and acurrstr(), eliminating a
bunch of casts.  I hope this doesn't reintroduce 'WIN32_BUG' (judging
by the previous workaround, I think that's extremely unlikely).

Also add an introductory comment to newhp().
2024-01-01 16:46:03 -08:00
nhmall
00af468020 add specialized voice for an audio assistant 2024-01-01 12:43:53 -05:00
nhmall
aeab3f69a6 update year in copyright to 2024 2024-01-01 11:04:26 -05:00
nhmall
76179ea0ba assert that u.ulevel is in range for use as index
Resolves #1189
2024-01-01 10:55:14 -05:00
Pasi Kallinen
95aceb1722 Remove double boom on cancelling a magical trap 2023-12-31 21:06:56 +02:00
Pasi Kallinen
780d30eca9 Wielded quarterstaff gives a small spellcasting bonus
From NetHack Fourk.
2023-12-31 17:53:03 +02:00
Pasi Kallinen
42a6a5df66 Cursed welded quarterstaff doesn't prevent spellcasting 2023-12-31 17:41:04 +02:00
PatR
cd91d0630b github issue #1180 - humans and murder
Issue reported by Umbire:  reviving a human corpse into a human
monster and then killing it entails murder penalty even when it is
hostile.

This is probably a non-issue.  Human monsters tend to not leave
human corpses, they leave shopkeeper corpses or sergeant corpses
and so forth.  Most human corpses created in normal play have
montraits attached and revive as a zombie, mummy, or vampire rather
than as a human.

This doesn't attempt to be clever, it just treats PM_HUMAN like
role monsters, not subject to 'murder'.

Closes #1180
2023-12-30 17:10:39 -08:00
PatR
b35d8d77a0 pull request #1147: WANT_SOURCE_INSTALL for linux
Pull request from entrez:  add support for 'make WANT_SOURCE_INSTALL=1'
to the linux.370 hints file, matching what macOS.370 already has.

I can't test for linux and don't bother with WANT_SOURCE_INSTALL on
OSX, so this hasn't been tried out.

Closes #1147
2023-12-30 16:42:04 -08:00
Michael Meyer
a831bf576b Add WANT_SOURCE_INSTALL to linux.370 hints file
WANT_SOURCE_INSTALL=1 can be specified when compiling to build NetHack
within the repo/source tree, rather than in the normal system install
location.  I find it useful for development on OSX, but it wasn't
present in any other hints files, so I've been using a custom hints file
on Linux for a while that adds the same option.  The code is based on
the macOS.370 hints file.
2023-12-30 16:40:54 -08:00
PatR
1cfa966871 pull request #1143 - menustyle:Full 'A' choice
Pull request from entrez:  in the class filtering menu for multi-drop
and for loot in-or-out of a container, make choosing 'A' without any
other filter choices (such as all, specific class(es), cursed, unpaid,
just-picked-up, &c) become a no-op.

I started with the pull request and then undid much of it.  It would
have been simpler to start from scratch.  If you don't have option
paranoid_confirmation:AutoAll set, when choosing 'A' for all-without-
prompting as the only selection, operate as the PR has made things
work:  effectively, 'A' by itself is ignored and the operation ends
with nothing happening.

However, if you do have paranoid_confirm:A set, then continue treating
'A' by itself as if 'A'+'a':  everything.  Since paranoid confirmation
is specified, that will be followed by a confirmation prompt.

This also adds a context-sensitive hint to the menu about how the 'A'
entry works, shown every time when 'cmdassist' is On or just once (per
session) when that is Off.

The documentation probably needs some updating.

Closes #1143
2023-12-30 16:33:27 -08:00
Michael Meyer
56d5bf50e5 Ignore loot/multidrop 'A' if no filter specified
The 'A' option in the #loot or 'D'rop menu selecting every selectable
item when used on its own has been the cause of many bag of holding
explosions and other typo-related frustration.  Now that it operates on
other filters rather than overriding them, actually require some other
filter be selected for it to have any effect.  This means that 'A' on
its own will do nothing, but 'A'+'a' will still act like 'A' alone
previously did.  I think this will reduce the rate of serious typo
accidents in games, without being intrusive and while still maintaining
'A' as a useful option (which I think it is, in it's 3.7 incarnation --
I use it all the time in combination with other filters, especially
justpicked).
2023-12-30 14:18:44 -08:00
Pasi Kallinen
c2fd027669 Typofix 2023-12-30 23:11:50 +02:00
PatR
d4dfb1765c curses menu revision
Redo menu sizing to eliminate one of the analyzer hacks.  There's no
need to loop through the menu entries a second time to find the last
one.  The first time can remember it.

Also, some routines were taking arguments with
 some_function(WINDOW *win, nhmenu *menu, ...)
and others with
 other_function(nhmenu *menu, WINDOW *win, ...).
Change them all to have the window pointer 1st and menu pointer 2nd.
2023-12-29 18:16:14 -08:00
nhmall
9d32956616 curses static analyzer bits
This is mostly just adding some Null guards ahead of
code that was already dereferencing pointers, so there
should be no change in behavior.

Also adds one validation of an array index that was
drawing a complaint.
2023-12-29 10:38:37 -05:00
nhmall
bed3b1d667 fix typo in attrib.c
Closes #1187
2023-12-29 08:34:13 -05:00
PatR
cb5e93e9e5 polymorphing into placeholder monsters
"human", "dwarf", "elf", "gnome", and "orc" are all flagged M2_NOPOLY;
so is "giant".  But dwarf and gnome are ordinary monsters and should
be eligible to be polymorph targets, so take the no-poly flag off of
them.  The others are used for corpses and not intended to be distinct
monsters.  But they are reasonable polymorph targets, so if player
with control picks any of them, choose a substitute.  The exception is
human, which already has special poly-self handling.
2023-12-29 02:29:16 -08:00
nhmall
01d6d94e30 non-Null handling for uhitm.c 2023-12-29 00:34:37 -05:00
nhmall
9d2d437d0e follow-up comment bit 2023-12-28 19:25:49 -05:00
nhmall
719919b16a revisit destroy_armor()
add a static function maybe_destroy_armor() to replace
the DESTROY_ARM() macro.

The DESTROY_ARM() macro expanded to legal code, but did include
side-effects of making assignments to local variable otmp (not an
argument to the macro), referenced local variable atmp (not an
argument to the macro), and sometimes setting the in_use field
on the impacted armor obj.

The assignment statements within the if (...) caused some compilers
and code analyzers to complain and suggest that perhaps
'=' should have been '==', which was incorrect.

The maybe_destroy_armor() function provides the
caller with information about whether the armor resisted,
so that appropriate action can be taken within the caller.
2023-12-28 19:17:43 -05:00
PatR
36c5843103 TTY_PERM_INVENT crash fix
The change 3 weeks ago for #4059 (to fix tty perm_invent memory leak)
resulted in nethack crashing during exit if built with TTY_PERM_INVENT
enabled and ending the game when perm_invent window isn't displayed.

This exits cleanly with or without perm_invent being shown and avoids
the memory leak which triggered the prior change.
2023-12-28 14:25:39 -08:00
Pasi Kallinen
073b0c90f3 Recalc mapseen when a special room is entered 2023-12-28 18:58:53 +02:00
nhmall
9f5f4b3c32 fix broken 'make install' with hints/linux.370 2023-12-28 11:45:36 -05:00
PatR
624eeeb58c non-Null handling for alloc.c
I wasn't very systematic but I think I eventually got everything.
Most alloc.c declarations are in global.h rather than extern.h.
2023-12-27 18:15:37 -08:00
nhmall
caf436934e NONNULLxxx for several files
src/date.c
src/mdlib.c
src/timeout.c
src/u_init.c
src/vault.c
src/version.c
src/windows.c
2023-12-27 20:11:59 -05:00
nhmall
e69c98c14a Windows follow-up: minimize pragma scope
Avoid disruption to mingw32-x64 build, by placing
some Visual Studio pragmas in #ifdef _MSC_VER
conditional blocks.
2023-12-27 15:00:08 -05:00
nhmall
3eb0fab317 Windows error checking and warnings 2023-12-27 14:56:03 -05:00
nhmall
0927726900 static analyzer bit for trap.c
src/trap.c(5794): warning: Dereferencing NULL pointer 'which'.
2023-12-27 11:13:22 -05:00
nhmall
d51e92d4bd static analyzer bit for symbols.c
src/symbols.c(532): warning: Dereferencing NULL pointer.
                             'tmpsp' contains the same NULL value as 'lastsp' did.
2023-12-27 11:10:35 -05:00
nhmall
aedbebad18 static analyzer bit for shknam.c
src/shknam.c(530): warning: Dereferencing NULL pointer 'shname'.
2023-12-27 11:05:38 -05:00
nhmall
6e654cb9a5 static analyzer bits for restore.c
src/restore.c(275): warning: Dereferencing NULL pointer. 'otmp' contains the
                             same NULL value as 'first' did.
src/restore.c(402): warning: Dereferencing NULL pointer. 'mtmp' contains the
                             same NULL value as 'first' did.
2023-12-27 11:03:25 -05:00
nhmall
e9ced6e2f9 static analyzer bit for priest.c
src/priest.c(865): warning: Dereferencing NULL pointer '((priest))->mextra->emin'.
2023-12-27 11:02:09 -05:00
nhmall
11c2586bdb static analyzer bit for pickup.c
src/pickup.c(3266): warning: Dereferencing NULL pointer 'otmp'.
2023-12-27 10:59:36 -05:00
nhmall
2f5fc70f02 static analyzer bits for pager.c
src/pager.c(209): warning: Dereferencing NULL pointer 'otmp'.
2023-12-27 10:56:00 -05:00
nhmall
e138f497ff static analyzer bits for bones.c
src/bones.c(646): warning: Using uninitialized memory 'oldbonesid'.
src/bones.c(646): warning: String 'oldbonesid' might not be zero-terminated.

Also help prevent a buffer overflow on corrupt or ill-formed bones.
2023-12-27 10:49:21 -05:00
nhmall
80afc96def comment follow-up 2023-12-27 10:44:50 -05:00
nhmall
6d8c37b754 static analyzer bit for do_name.c
src/do_name.c(1494): warning C28183: 'aname' could be '0'
2023-12-27 10:40:02 -05:00
nhmall
5e6d2cd6b5 static analyzer bit for makemon.c
src/makemon.c(907): warning: Dereferencing NULL pointer '((mon))->mextra'.
2023-12-27 09:04:33 -05:00
PatR
0e70fc5844 unfix unnaming types of objects
The prior commit makes the code clearer so I'm not reverting it,
but the old code was not accessing freed memory so I am removing the
fixes entry.  The static analyzer's complaint is bogus.  Freeing the
memory that held a user-assigned type name did not affect whether
that pointer could be tested for being Null.  Its stale value wasn't
being dereferenced.
2023-12-27 05:48:28 -08:00
PatR
97272d3627 fix unnaming types of objects
docall() would access freed memory if the player used space(s) as
a fake object type name in order to remove an existing name without
giving any new one.

3.4.3 had this bug too; I didn't go farther back.
2023-12-27 04:59:44 -08:00
nhmall
94b59cbd35 static analyzer bit for read.c
src/read.c(2889): warning: Dereferencing NULL pointer 'sobj'.

The analyzer doesn't know that the one caller that passes a NULL
sobj argument, angrygods(), checks !Punished before doing so.
Use a NULL guard before dereferencing sobj so that it doesn't
matter anyway.
2023-12-26 23:42:23 -05:00
nhmall
90d1e30ebd follow-up to display.c, add a comment 2023-12-26 13:48:56 -05:00
nhmall
9da895f285 fix build if UNBUFFERED_GLYPHINFO is defined
The reason this wasn't caught sooner was because the version
of the Glyphinfo_at(x,y,glyph) macro, that was defined when
UNBUFFERED_GLYPHINFO is not defined (when glyphinfo's are
buffered - the default), does not use the 3rd argument at
all.
2023-12-26 13:34:55 -05:00
nhmall
7b20c1fc98 static analyzer bit for weapon.c
src/weapon.c(451): warning: Dereferencing NULL pointer 'uleft'.

The analyzer couldn't tell that a STRANGE_OBJECT not being made of
SILVER material, was sufficient to guard against dereference of
NULL uleft or uright in the l_ag and r_ag assignments.

Test and dereference each once to set indicator booleans, and use
the booleans afterwards.
2023-12-26 11:27:34 -05:00
PatR
0a10fcbb43 fix #4071 - new timer sanity false positive
New timed sanity checking trying to validate a timer's map location
can't locate a timed object (in this case, an egg with a hatch timer)
inside a container carried by a migrating monster.

The case of the object being carried directly by a migrating monster
was handled, but one inside a container wasn't.
2023-12-26 05:49:33 -08:00
nhmall
36e8e504c2 another static analyzer bit for wield.c
src/wield.c(745): warning: Dereferencing NULL pointer 'obj'.
See line 685 for an earlier location where this can occur

In wield_tool(), the comparisons against uwep were intended
for when uwep wasn't null.

gcc/clang analyzers now have some awareness of obj arg being
notnull for wield_tool() since the extern.h prototypes
were changed to declare that, but other compilers/analyzers
do not necessarily have that information, and this:
    'if (obj == uwep)'
would be a match if both were NULL.
2023-12-24 15:38:06 -05:00
nhmall
3bc8af9836 static analyzer bit for wield.c
src/wield.c(254): warning: Dereferencing NULL pointer 'wep'.
See line 190 for an earlier location where this can occur

This seems to be a case where an unnecessary null test (A) caused
the analyzer to call into question whether or not wep
is null at (B):

    if (!wep) {
    } else if (wep->otyp == CORPSE && cant_wield_corpse(wep)) {
    } else if (uarms && bimanual(wep)) {
    } else if (!retouch_object(&wep, FALSE)) {
    } else {
        /* Weapon WILL be wielded after this point */
        if (will_weld(wep)) {
        } else {
        }
        if (was_twoweap && !u.twoweap && flags.verbose) {
        }
        /* KMH -- Talking artifacts are finally implemented */
A ==>   if (wep && wep->oartifact) {
        }
        if (artifact_light(wep) && !wep->lamplit) {
        }
B ==>   if (wep->unpaid) {
        }
    }

Removing the extraneous wep test from (A) resolves the complaint.
2023-12-24 14:47:08 -05:00
PatR
036d2a929f Fumbling while riding
Being stuck on a cursed saddle overrides Fumbling if hero would have
fallen off steed.
2023-12-24 00:54:48 -08:00
nhmall
a30c5ceba2 static analyzer bit for makemon.c
src/makemon.c(918): warning: Dereferencing NULL pointer '((mon))->mextra'.
2023-12-24 00:40:48 -05:00
nhmall
fbf8e0d5bc static analyzer warnings for mon.c
src/mon.c(2370): warning: Dereferencing NULL pointer '((mtmp2))->mextra->epri'.
src/mon.c(2375): warning: Dereferencing NULL pointer '((mtmp2))->mextra->eshk'.
src/mon.c(2380): warning: Dereferencing NULL pointer '((mtmp2))->mextra->emin'.
src/mon.c(2385): warning: Dereferencing NULL pointer '((mtmp2))->mextra->edog'.
src/mon.c(4419): warning: Dereferencing NULL pointer 'ga.animal_list'.
2023-12-24 00:36:21 -05:00