Commit Graph

16169 Commits

Author SHA1 Message Date
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
nhmall
088717ccec do not use the NONNULLxxx macros with djgpp [cross]compiler
For now, this will prevent the NONNULLxxx arguments from being
defined under a djgpp compiler or crosscompiler.

paxed reported a segfault under msdos:

nethack.exe
Exiting due to signal SIGSEGV
Page fault at eip=000c3f8c, error=0004
eax=00000000 ebx=00000000 ecx=00000000 edx=0000000f esi=00000000 edi=00000001
ebp=00589988 esp=00589970 program=C:\NH370\NETHACK.EXE
cs: sel=00a7  base=00400000  limit=0063ffff
ds: sel=00af  base=00400000  limit=0063ffff
es: sel=00af  base=00400000  limit=0063ffff
fs: sel=008f  base=00001a20  limit=0000ffff
gs: sel=00bf  base=00000000  limit=0010ffff
ss: sel=00af  base=00400000  limit=0063ffff
App stack: [00589ba8..00389ba8]  Exceptn stack: [00389af4..00387bb4]

Call frame traceback EIPs:
  0x000c3f8c _read_config_file+19
  0x0017619f _initoptions_finish+577
  0x00176371 _initoptions+157
  0x0025cec4 _pcmain+365
  0x0025d8d9 _main+41

He was able to 'git bisect' to the macro definitions change,
and confirmed that the segfault no longer occurs after this commit.

There may be further investigation on this later.
2023-12-18 11:52:16 -05:00
Pasi Kallinen
c0fdb2e8c4 Level temperature affects monster generation
Hot levels generate more fire-resistant monsters, cold
levels cold-resistant ones.
2023-12-18 13:43:41 +02:00
Pasi Kallinen
e4026d55fb Lazy evaluation of overview info
Callgrind showed recalc_mapseen was three times more expensive (in terms
of instructions read) than anything else in our codebase.  It was being
called in every vision change, re-evaluating the last seen map terrain
type for every map location in sight.

Remove updating the lastseen info in the vision code, and make a small
change so newsym() uses update_lastseentyp.

From my short tests, this seems to work correctly ...
2023-12-18 10:53:18 +02:00
nhmall
0d1be5c50b put the CI yml back the way it was 2023-12-17 19:23:37 -05:00
nhmall
0f92f9ef90 try Ubuntu 23.04 in the CI 2023-12-17 19:10:26 -05:00
nhmall
8469c349c8 Test if newer Ubuntu version available in CI 2023-12-17 18:59:30 -05:00
nhmall
e81c599e9a Revert a single file from commit 1bb854430 2023-12-17 16:32:23 -05:00
PatR
1bb8544303 even more mklev.c
This should eliminate the last analyzer complaint about maybe using
a Null pointer.  I didn't notice this one yesterday.
2023-12-17 11:02:30 -08:00
Pasi Kallinen
ea1fdc066a Split lastseentyp updating 2023-12-17 15:43:49 +02:00
Pasi Kallinen
9b8272b57f Split counting mapseen features from lastseentyp 2023-12-17 15:21:37 +02:00
nhmall
3bf2f0daee Revert "allow readobjnam arg to be nonnull"
This reverts commit 10f29a9760.
2023-12-17 07:20:35 -05:00
Mika Kuoppala
e6c4838161 sp_lvl: fix memory leak on lspo_region
If tutorial is entered, we get following leak on exit:

=================================================================
==81358==ERROR: LeakSanitizer: detected memory leaks

Direct leak of 96 byte(s) in 3 object(s) allocated from:
    #0 0x7f6996edefdf in __interceptor_malloc ../../../../src/libsanitizer/asan/asan_malloc_linux.cpp:69
        #1 0x5601c255bcbb in alloc /home/miku/src/NetHack/src/alloc.c:71

Indirect leak of 5064 byte(s) in 3 object(s) allocated from:
    #0 0x7f6996edefdf in __interceptor_malloc ../../../../src/libsanitizer/asan/asan_malloc_linux.cpp:69
        #1 0x5601c255be1e in alloc /home/miku/src/NetHack/src/alloc.c:71
	    #2 0x5601c255be1e in dupstr /home/miku/src/NetHack/src/alloc.c:236

SUMMARY: AddressSanitizer: 5160 byte(s) leaked in 6 allocation(s).

Fix this by freeing the cloned selection before returning.
2023-12-17 11:47:26 +02:00
Pasi Kallinen
a2aa4edd51 Allow SIGINT (Ctrl-C) to stop the fuzzer 2023-12-17 11:28:13 +02:00
PatR
3d27d8e998 more mklev.c
This got accidentally omitted from the previous patch.  The
clear_level_structures() prototype is in extern.h.
2023-12-16 18:43:39 -08:00
PatR
f2671fd1a7 mklev.c: somexyspace() revisited
Replace one recenly added 'croom' test with assert(croom != NULL);
keep the other one.  Mark fill_ordinary_room() as requiring that its
first argument be non-Null.  Check for malformed subroom data before
calling it.

Plus miscellaneous reformatting.
2023-12-16 18:38:29 -08:00
nhmall
10f29a9760 allow readobjnam arg to be nonnull
Have it key on &do_random_str instead of NULL,
and modify makewish() in zap.c for the new protocol.
2023-12-16 19:30:34 -05:00
nhmall
3e83d23b19 skip calling somexyspace() if mkroom ptr is NULL 2023-12-16 18:30:35 -05:00
Pasi Kallinen
0a8f919ff3 Make monsters not use camera when hero resists blindness 2023-12-16 23:34:16 +02:00
PatR
ae80e7db47 fix analyzer complaints about Knox level
Fix some of the extreme verbosity for null vs non-null triggered
by mklev.c.  dungeon_branch() never returns Null.

'#include <assert.h>' should probably be moved out of multiple .c
files and into cstd.h or some such but this doesn't do that.
2023-12-16 13:26:17 -08:00
nhmall
caa8aa7f60 reinstate obj guard on _see_with_infrared macro
Checking the callers:
newsym() the use of see_with_infrared() is guarded by
    } else if ((mon = m_at(x, y)) != 0 [...]

do_mgivenname() the use of see_with_infrared is guarded by !mtmp:
        && (!mtmp
            || (!sensemon(mtmp)
                && (!(cansee(cx, cy) || see_with_infrared(mtmp))

howmonseen(mon) dereferences mon in other places, so it would
    segfault if mon were NULL; howmonseen has NONNULLARG1.
2023-12-16 12:55:09 -05:00
nhmall
294ce9b59d reinstate removal of mon guard from is_safemon()
callers were checked:
domove_attackmon_at(mtmp, x, y, displaceu) has mtmp declared nonnull;
    there are dereferences of mtmp in the first line of code in
    the function.

In domove_core():
    The 1st occurrence of is_safemon(mtmp) is guarded by if (mtmp) { }.
    The 2nd occurrence of is_safemon(mtmp) is inside an if (mtmp) { } block.
    The 3rd occurrence of is_safemon(mtmp) was just remediated by 987be7e8.

In lookaround():
    The only occurrence of is_safemon(mtmp) is inside an
        if ((mtmp = m_at(x, y)) != 0 [...] { } block.

In do_attack(mtmp), in uhitm.c:
    The parameter is declared NONNULLARG1, and the 1st line of
    code contains a dereference with mtmp->data, which would
    segfault if mtmp were NULL.
2023-12-16 12:37:49 -05:00
nhmall
987be7e8e5 a pair of domove_core() blocks
Following line 2425 of hack.c, in domove_core():
    mtmp = m_at(x, y);
mtmp can be null.

There were two if blocks following that, both of which
only make sense when mtmp is not null.

One of them was explicitly checking for mtmp being non-null,
and the other was avoiding catastrophe by relying on a
hidden check buried within an _is_safepet(mon) macro.

Place both of those blocks into an
    if (mtmp) { }
block.

99% of the diff is just indentation.
2023-12-16 11:38:55 -05:00
nhmall
5d4a4ca7fb Revert "remove mon guard from _see_with_infrared(mon),_is_safemon(mon)"
This reverts commit 91fdc1104a while an
issue is investigated further..
2023-12-16 11:11:30 -05:00
nhmall
c5a5b55c15 nonnull for some static functions during recent analysis 2023-12-16 10:51:59 -05:00
nhmall
516d428c40 update commented-out macro in artifact.c 2023-12-16 10:32:25 -05:00
nhmall
9aa87aee05 static analyzer bit
Make it really obvious to the analyzer that we're only
calling canseemon(mcarry) when mcarry is not null.
2023-12-16 10:04:13 -05:00
nhmall
3eed55471b another artifact.c tweak
Use 'AFTER_LAST_ARTIFACT instead of SIZE(artilist)
2023-12-16 08:34:09 -05:00
nhmall
91fdc1104a remove mon guard from _see_with_infrared(mon),_is_safemon(mon)
*/
 #define _see_with_infrared(mon) \
-    (!Blind && Infravision && mon && infravisible(mon->data) \
+    (!Blind && Infravision && infravisible(mon->data) \
      && couldsee(mon->mx, mon->my))

 /*
@@ -157,7 +157,7 @@
  * definition here is convenient.  No longer limited to pets.
  */
 #define _is_safemon(mon) \
-    (flags.safe_dog && (mon) &
2023-12-16 08:00:38 -05:00
nhmall
70dcab833d remove obj guard from stone_missile(obj) macro
Checking the callers:
toss_up() would have segfaulted prior to use of stone_missile() if obj were NULL.
thitu() now has a guard prior to use of stone_missile()
ohitmon() would have crashed from earlier dereference otmp->dknown if it were NULL,
   otmp arg is declared nonnull
thitm() now has a guard prior to use of stone_missile().
hmon_hitmon_do_hit() null obj takes a different code path than the code path
    using stone_missile(); comment asserting that added
2023-12-16 07:58:44 -05:00
Pasi Kallinen
0099098d35 Silence some nonnull complaints 2023-12-16 14:03:16 +02:00