Commit Graph

16199 Commits

Author SHA1 Message Date
nhmall
93bcfeac29 static analyzer bit for artifact.c
src/artifact.c(1589): warning C6011: Dereferencing NULL pointer 'magr'.

The 'struct monst *magr' parameter to artifact_hit() can be Null
if 'mdef' is youmonst. mdef is nonnull.
2023-12-23 22:56:21 -05:00
nhmall
7e131649c4 static analyzer bit for rumors.c
src/rumors.c(800): warning: Dereferencing NULL pointer 'CapMons'.
2023-12-23 22:25:49 -05:00
PatR
05cf948007 fix github issue #1186 - eating Medusa's corpse
and having temporary stoning resistance timeout before finishing.

Issue reported by Umbire:  hero was able to finish eating Medusa's
corpse safely after getting the message about no longer being
protected against stoning that is given when temporary resistance
times out.

The eating code was extending temporary resistance--when eating
something protected by such--to avoid just that.  I thought this
was probably a message sequencing situation but it turns out that
the code was using touch_petrifies() to test the meal.  It should
use flesh_petrifies() instead; Medusa doesn't pass touch_petrifies().

I didn't figure that out until after rewriting how the duration is
extended.  The old way probably would have worked as desired with
the revised petrify test but I'm checking in the new version anyway.

Fixes #1186
2023-12-23 17:38:05 -08:00
PatR
35eb289cc3 "partly used candle" fix
If you wished for "lit candle" you'd get an unused candle that
is pre-lit but the feedback as it's added to inventory would be
"partly used candle (lit)".  If snuffed out immediately, it reverts
to "candle" (ie, not partly used).

This fixes the first aspect:  you will get "candle (lit)" added to
inventory.  On the next turn it changes to partly used as expected.
The second aspect, reverting to not-used-yet after being lit during
the wish is left as-is.
2023-12-23 16:15:38 -08:00
nhmall
4f96accfb1 follow-up role.c 2023-12-23 14:07:03 -05:00
nhmall
f3a9d91676 static analyzer bits in role.c
src/role.c(1543): warning: Reading invalid data from 'roles'.
src/role.c(1765): warning: Reading invalid data from 'roles'.
src/role.c(1780): warning: Reading invalid data from 'races'.
2023-12-23 13:56:56 -05:00
nhmall
e9e05db113 add a pair of shorthand macros to validate an index into an array
Two variations:

IndexOk(idx, array)       validate that idx is a valid index into the array

IndexOkT(idx, array)      validate that idx is a valid index into the
                          array, excluding the final Terminator element
2023-12-23 13:46:54 -05:00
nhmall
415f8c559b static analyzer bit for monmove.c
src/monmove.c(1820): warning: Reading invalid data from 'info'.
2023-12-22 22:43:58 -05:00
nhmall
1c867ce528 another static analyzer bit for mkobj.c
src/mkobj.c(419): warning: '((obj2))->oextra->omonst' could be '0'
                : this does not adhere to the specification for the
                  function 'memcpy'.
src/mkobj.c(421): warning: Dereferencing NULL pointer
                  '((obj2))->oextra->omonst'.
                  See line 419 for an earlier location where this can occur

The analyzer was not aware that newoextra() sets up an oextra block:
    if (!obj2->oextra)
        obj2->oextra = newoextra();

The analyzer was also not aware that newomonst() was setting up a valid
OMONST pointer.
    if (!OMONST(obj2))
        newomonst(obj2);

Add an assert(has_omonst(obj2)) before copying the content from
OMONST(obj1) into OMONST(obj2).
2023-12-22 22:30:38 -05:00
nhmall
d123cd77d1 static analyzer bit in mklev.c
src/mklev.c(137): warning: Using uninitialized memory 'ri'.

There was a for-loop assigning values to some elements of
ri[], but not all of them.

Initialize the array.
2023-12-22 22:02:18 -05:00
nhmall
4bc5e26082 static analyzer bit in files.c
src/files.c(4403): warning: Reading invalid data from 'buf'.
2023-12-22 21:47:48 -05:00
PatR
7a533a911c enhance timer sanity checks a bit
Four kinds of timers are defined but only two have ever been used.
Have sanity checking complain if the other two occur or if 'kind'
doesn't match any of the four.

Also, replacing a perfectly normal use of isok() with an inline test
just to pacify static analysis feels like a slippery slope, so handle
that a little differently.

I reordered the shrink_glob timer to put all object timers together.
Unfortunately that warrants incrementing EDITLEVEL which invalidates
existing save files.
2023-12-22 17:48:51 -08:00
nhmall
18efc74db2 static analyzer bit in mkobj.c
src/mkobj.c(2211): warning: Reading invalid data from 'gl.level.objects[x]'.
2023-12-22 19:32:07 -05:00
nhmall
a03a614883 include assert.h in cstd.h
Three src files already were including it, and another was
about to be added, so include it in include/cstd.h.
2023-12-22 19:24:09 -05:00
nhmall
48c067a6e9 follow-up bit options.c 2023-12-22 19:01:57 -05:00
nhmall
0cde312437 static analyzer bit in options.c
src/options.c(711): warning: Reading invalid data from 'roleoptvals[roleoptindx]'.

Validate the roleoptvals[][] array indexes to appease the static
analyzer.
2023-12-22 17:41:06 -05:00
nhmall
d6f036f329 static analyzer bit in timeout.c
src/timeout.c(2033): warning: Reading invalid data from 'gl.level.locations'.

Analyzer couldn't tell that isok(x, y) had validated x and y to be
safe indexes into gl.level.locations[x][y].

Code it a bit differently, so that the static analyzer becomes perfectly
aware that the indexes are, indeed, in range.
2023-12-22 17:18:40 -05:00
nhmall
fcc91cec94 static analyzer bit in uhitm.c
src/uhitm.c(1172): warning: Reading invalid data from 'mons'.

Analyzer wasn't happy with the index into mons[] array only
being validated by '!= -1'.

Update the check for the index to include the full array
index range, including ensuring that it is also '< NUMMONS'.
2023-12-22 16:30:24 -05:00
nhmall
51bf9dd76d comment typo 2023-12-22 14:57:50 -05:00
nhmall
de8d1ef0d1 Merge branch 'NetHack-3.7' of https://rodney.nethack.org:20040/git/NHsource into NetHack-3.7 2023-12-22 14:38:33 -05:00
nhmall
746d00d170 assess wizard.c static functions for nonnull
No nonnull return attributes were appropriate for wizard.c section
of include/extern.h either.
2023-12-22 14:35:59 -05:00
nhmall
34d6cf105e zap.c, write.c, worn.c, worm.c nonnull returns 2023-12-22 13:54:51 -05:00
nhmall
92250aa15d assess worm.c static functions for nonnull 2023-12-22 13:18:04 -05:00
nhmall
741d2929b4 assess worn.c static functions for nonnull 2023-12-22 13:10:39 -05:00
nhmall
2542f9bada follow-up correction 2023-12-22 11:42:19 -05:00
nhmall
c1fc52e644 assess write.c static functions for nonnull 2023-12-22 10:38:38 -05:00
nhmall
10e7f61380 assess zap.c static functions for nonnull 2023-12-22 10:34:15 -05:00
PatR
0ab44ba89c pager.c: flagging pointer args non vs non-null
Yesterday I said that I'd done all of pager.c and part of objnam.c,
but I was talking about the prototypes in extern.h.  This does more
of the same, this time for the local prototypes in pager.c so "all of
pager.c" should be accurate now.
2023-12-21 09:47:52 -08:00
Pasi Kallinen
5b5e547791 Restful sleep gives a warning message 2023-12-21 09:41:47 +02:00
Pasi Kallinen
5a60c37676 One more NO_NNARGS bit 2023-12-21 07:50:04 +02:00
nhmall
c3ce08b794 NO_NONNULLS -> NO_NNARGS
I find:
    extern char *an(const char *) NONNULL NO_NNARGS;

slightly better than this:
    extern char *an(const char *) NONNULL NO_NONNULLS;
2023-12-20 22:26:16 -05:00
nhmall
ab74019dcb another fetch-lua follow-up 2023-12-20 22:04:22 -05:00
nhmall
e9bd28d0d8 fetch-lua follow-up 2023-12-20 21:31:58 -05:00
nhmall
a18333633f fetch-lua update
Try the mirror if the primary fails
2023-12-20 21:17:13 -05:00
nhmall
92d3d6ed5f comment bit 2023-12-20 20:07:33 -05:00
nhmall
d0e43523d7 useupall really won't handle a NULL pointer
Revert useupall() prototype back to NONNULLARG1, as it was.
The callers in nhlua.c check gi.invent to be nonnull before
calling useupall().
2023-12-20 19:31:39 -05:00
PatR
a696cb8d90 some NONNULLs
Update the prototypes of some functions which return a pointer that
will never be NULL.  Only covers pager.c and part of objnam.c.
2023-12-20 15:55:21 -08:00
nhmall
07ef4583ce functions passed a chain explicitly NO_NONNULLS
Some functions are passed an obj or monst chain,
and  the callers typically don't check them
against 0, so mark them explicitly as NO_NONNULLS

(NO_NONNULLS expands to nothing, but it flags that
some null arg analysis has been done)
2023-12-20 18:48:50 -05:00
nhmall
d292ad7d17 update util/.gitignore 2023-12-20 18:48:17 -05:00
nhmall
0dafde4079 more nonnull follow-up 2023-12-20 15:53:51 -05:00
Pasi Kallinen
488afffcd7 Fix NONNULL for hitting bare handed 2023-12-20 20:09:50 +02:00
PatR
0713b91beb recalc_mapseen() followup
Update several places where lazy lastseentyp[] might be an issue.

I think it isn't updated in a timely fashion when newsym() shows
a spot covered by an object or trap, but didn't manage to find any
cases where that caused a problem.  This is more in the nature of
a precaution.
2023-12-20 03:17:29 -08:00
Pasi Kallinen
60dc6343e4 Moving monsters disturb buried zombies 2023-12-20 11:17:23 +02:00
Pasi Kallinen
3c94b276a2 Amulet of unchanging cannot be polymorphed 2023-12-19 17:13:52 +02:00
nhmall
99db2433d6 update tested versions of Visual Studio 2023-12-18 2023-12-18 23:10:34 -05:00
PatR
5e9358b331 makedefs: check input files for non-ASCII chars
If MAKEDEFS_FILTER_NONASCII is defined (which config.h now does by
default), it will check data.base, rumors.*, and {various}.txt for
characters outside the range of ' ' through '~'.  If it finds any, it
will warn about them and change them to '#'.

Tab handling is incomplete; the files that use tabs for indentation
will allow tabs anywhere, even though that's not wanted.  That could
be fixed but doesn't seem particularly urgent.  This is more about
spotting and repairing the special 3-char punctuation characters that
crept into data.base fairly recently.
2023-12-18 17:16:33 -08:00
nhmall
90fcce8903 follow-up to only attempt unzip if download was ok 2023-12-18 14:59:01 -05:00
nhmall
c197dfe29b include symify.exe in the NetHack msdos package
Before using this updated packaging you will need
to do the following (one time):
    sh sys/msdos/fetch-cross-compiler.sh

And you'll need to update your Makefiles as follows.

On Linux:
    sh sys/msdos/setup.sh sys/unix/hints/linux.370

or on macOS;
    sh sys/msdos/setup.sh sys/unix/hints/macOS.370

Create the msdos package with:
    make CROSS_TO_MSDOS=1 package
2023-12-18 14:48:10 -05:00
nhmall
daa677f1a3 Revert "don't use the NONNULLxxx macros with djgpp"
This reverts commit 088717ccec.

The source of the issue was found and corrected in 08a1e6816.

msdos tested okay
2023-12-18 12:59:55 -05:00
nhmall
08a1e68166 remove incorrect NONNULLARG1 on read_config_file 2023-12-18 12:40:31 -05:00