Commit Graph

9437 Commits

Author SHA1 Message Date
janne-hmp
22d26b7653 Saving a bones file should not free memory; the function really_done will be using that information after the call to savebones, resulting in a heap-use-after-free error (and possibly later in a double-free in nh_terminate if things get that far). 2024-01-22 16:31:51 -08:00
PatR
fabc9033aa loadstone bit
If your inventory is full and you aren't already carrying a loadstone,
you can pick one up into the overflow slot.  But if you are already
carrying one and the one you're trying to pick up won't merge with it
(only criterium that matters would be BUC state, I think), you can't
pick it up and get a message saying so.  If loadstone isn't known
yet, the message always referred to it as "gray stone" rather than
"stone called <whatever-you-called-it>".
2024-01-22 13:25:32 -08:00
PatR
7c1512fa99 avoid strnlen()
Replace the single strnlen() use with strlen() so as not to require
something from posix.1 (2008) when we supposedly only require c99.

If someone manages to produce a string that's longer than will fit
within size_t, strlen()'s length count will wrap and Strlen_() might
not notice.  Since size_t has to be at least 32 bits, that doesn't
seem like something to worry about.

If checking for size_t overflow is considered essential, we should
just switch to counting the length via an in-line loop that imposes
a similar limit to strnlen().
2024-01-22 12:59:51 -08:00
nhmall
7f8c7dda64 Merge branch 'rotten-rottables' of https://github.com/bitofhope/NetHack into NetHack-3.7 2024-01-22 11:08:30 -05:00
Pasi Kallinen
baeb1d925f Change some ints to coordxy 2024-01-22 17:02:40 +02:00
PatR
5d90499148 doname bounds checking bits
When ready to return, check for overlooked overflow (shouldn't happen)
and panic, or report the first excessively long but not overflown
description to paniclog, similar to xname.

Make ConcUpdate() more robust by not needing bp_eos to be previously
set.  Less efficient but I think that boat has left the barn?  :=}

Fix a comment typo.
2024-01-21 17:43:55 -08:00
Pasi Kallinen
96902f4ff0 Split populating a random maze 2024-01-21 22:48:41 +02:00
PatR
13ff565a67 github issue #1201 - Forcefighting webs
Issue reported by Umbire:  suggestion to always destroy adjacent webs
via 'F'<dir> if wielding Sting or Fire Brand.

Sting already did that; this adds Fire Brand.

This also augments the #untrap command when wielding either of those,
or any other blade.  And rephrases successful untrap message
"You remove {the or your} {bear trap or webbing} from Fido." to
"You extract Fido from {the or your} {bear trap or web}." since the
trap remains intact.

Forcefight and #untrap against webs ought to be reconciled to remove
[some of] their differences and/or share code.  But not by me...

Closes #1201
2024-01-21 11:58:44 -08:00
nhmall
81b45f92c8 static analyzer bit in sounds.c 2024-01-21 14:09:46 -05:00
PatR
9e640fb14e gcc warning fix
Avoid two new warnings in xname_flags() about strncpy() not supplying
a terminating '\0'.  That's exactly why strncpy() was being used.

The gcc manual lists -Wno-stringop-truncation to suppress the warning
but not -Wstringup-truncation to voluntarily enable it, so the pragma
stuff in warnings.h probably won't work for this.  Just switch from
strncpy() to memcpy() instead even though it seems like obfuscation.
2024-01-21 11:01:45 -08:00
nhmall
d4f04fbdc8 static analyzer bit in options.c
Analyzer didn't like the use of strchr on an incomplete type.
Move the guts into a function in o_init.c.
2024-01-21 13:38:25 -05:00
nhkeni
6f47094b8d Add a sanity check to nhl_init() 2024-01-21 12:44:05 -05:00
nhmall
0b684339ef more vestiges of C(color) 2024-01-21 11:12:13 -05:00
PatR
1a2b2a8cae object formatting fix for charged rings
The bounds checking code for object formatting had a typo that left
out the space between +N and <ring of type>.
2024-01-21 07:58:25 -08:00
nhmall
8f35e33a2e follow-up nonnull in u_init.c
u_init.c had had assessments for nonnull arguments on
its local functions carried out already.

A couple of new static functions added earlier today immediately
dereference their args, so declare those as nonnull.

This also gives a more self-describing name to one arg.
2024-01-21 09:48:36 -05:00
Pasi Kallinen
f889478262 Split ini_inv obj wear/wield/learn 2024-01-21 14:34:21 +02:00
Pasi Kallinen
2f5851e394 Split ini_inv object field adjustments 2024-01-21 14:16:06 +02:00
Pasi Kallinen
f1bf2418ff Split ini_inv obj race substitutions 2024-01-21 14:02:09 +02:00
Pasi Kallinen
d2e7bfa6cd Split out ini_inv filtered mkobj 2024-01-21 13:46:20 +02:00
Pasi Kallinen
8615401278 Split out initial STR and CON boost if inventory too heavy 2024-01-21 12:51:46 +02:00
Pasi Kallinen
311e82a9cc Split init attr minor variation 2024-01-21 12:45:13 +02:00
Pasi Kallinen
1d4cdf09f6 Split u_init race specific stuff 2024-01-21 12:38:06 +02:00
Pasi Kallinen
2e56598779 Split u_init role specific stuff 2024-01-21 12:34:43 +02:00
Pasi Kallinen
a46e41816b Split freeing proto_dungeon data 2024-01-21 12:17:06 +02:00
Pasi Kallinen
0eb96d7ed6 Split special level location fixup 2024-01-21 12:11:22 +02:00
Pasi Kallinen
f34a07a3d2 Split out castle tune init 2024-01-21 11:55:29 +02:00
Pasi Kallinen
0e64fddec1 Split out dungeon parsing 2024-01-21 11:51:15 +02:00
PatR
593a93d254 obj->how_lost fix
PR #1140 added checking the thrown, stolen, and dropped flags of an
item when testing whether it would merge (at my suggestion...) with
a stack in the target list (hero's invent).  That interferred with
picking it back up--whether via autopickup or explicit pickup--while
inventory was full even when the item would otherwise be mergable.

There was some trial and error involved when trying to figure where
to put the fix but things seem to be working.

This replaces a static analyzer workaround and could possibly bring
its unwarranted complaint back.
2024-01-21 01:17:18 -08:00
Pasi Kallinen
5bf258629a Split up hero attribute init 2024-01-21 10:41:57 +02:00
PatR
7b1ec30d0d bounds checking by doname() and xname()
Try harder to prevent buffer overflow when formatting objects.
I don't have any test cases where overflow has been happening so
don't really know whether this works reliably.  And it doesn't try
to check prefix construction by doname().  [Yet?]
2024-01-20 17:53:44 -08:00
Pasi Kallinen
414ee6eba7 Split setting up dungeon depth 2024-01-20 16:25:13 +02:00
Pasi Kallinen
1c0662ddd7 Split setting up dungeon entry level 2024-01-20 16:18:06 +02:00
Pasi Kallinen
d5fba06837 Split dungeon branch parsing 2024-01-20 16:00:02 +02:00
Pasi Kallinen
57747535af Add m_next2u, analogous to m_next2m and next2u 2024-01-19 21:53:25 +02:00
Pasi Kallinen
ce34239885 Zero init the NhRect 2024-01-19 18:19:56 +02:00
Pasi Kallinen
2212cf27ec Lua: Allow creating gas clouds
Use the gas clouds in the Clouds themeroom.
Use the existing visible_region_at() in the vision code.
2024-01-19 17:59:43 +02:00
nhkeni
bacfa6ef40 More lua setup cleanup
Stop (poorly) tracking the amount of memory in use and get
 it from Lua instead.
Simplify nhl_alloc.
2024-01-17 15:04:40 -05:00
Pasi Kallinen
5d28e24477 Some lua state allocator fixes
Run GC on the themeroom lua states, as they're not freed
until end of game.

Allocate the exact amount of data we use instead of padding it.

Free our state data after closing the lua state; doing it
the other way is the way to madness, which was kept at bay
by the padded allocation amount.
2024-01-17 17:41:44 +02:00
PatR
6b8079a16f secondary damage for monster spell attacks
Have monster spells
| "shower of missiles" (AT_MAGC+AD_MAGM: Angels, Yeenoghu)
scuff an engraving at the hero's spot if there is one,
| "frost" (AT_MAGC+AD_COLD: only Asmodeus)
freeze water and lava terrain,
| "flames" (AT_MAGC+AD_FIRE: moot, no monster has this attack)
burn items on the floor at the hero's spot and melt ice terrain,
| "pillar of flame" (AT_MAGC+AD_CLRC+randomly chosen clerical spell)
which already burns floor items, melt ice too, and
| "lightning" (same casters as pillar of flame)
give a tiny chance of destroying iron bars.  The chance to hit bars
is low and the hero has to be targeted while located on an iron bars
spot so probably won't happen before the sun burns out, but only
needed one extra line of code.

Only the first two have been thoroughly tested.
2024-01-16 14:01:38 -08:00
PatR
a5c7fede99 mcastu()'s monst->mspec_used usage
Replace some suspicious mixing of signed and unsigned.
2024-01-16 10:19:00 -08:00
bitofhope
11381d631c Rephrase "rotten" non-rottable items 2024-01-16 11:27:46 +02:00
nhmall
c134a128ac rephrase rotten metal
Resolves #1202
2024-01-15 17:58:11 -05:00
PatR
8111a7aff2 covetous monster tactics on completely full level
If a covetous monster tried to teleport adjacent to the hero but the
level was too full to move it from its current spot, it would be
sent off level to wait for the hero to leave and return instead just
staying put.
2024-01-15 14:25:06 -08:00
Pasi Kallinen
1c16ef68eb Fix spot_monsters giving a segfault in some cases 2024-01-15 20:53:24 +02:00
PatR
40e919dbf9 github issue #1200 - erronenous engraving feedback
Issue reported by chappg:  if a monster or object covered an engraving,
examining that monster or object with farlook would include the text
of the engraving even though it wasn't the thing being examined.

The report was for a bones level but that only mattered because it was
a ghost on top of a grave (and the engraving on its headstone) that was
being examined; bones data itself wasn't pertinent.  It would happen
with any engraving once the spot was mapped as an engraving or a grave
provided that something else was currently displayed at the location.

Bug was introduced by commit 389f03e90e
two months ago.  Mea culpa.

Closes #1200
2024-01-15 02:56:26 -08:00
PatR
e4534d60e3 more Forcefighting webs
Hero attempting to cut an adjacent web can so with secondary weapon
if dual wielding and primary isn't a blade.

Mostly message handling for the 'neither weapon is a blade' situation.
2024-01-14 16:58:43 -08:00
Pasi Kallinen
ccfcc32843 Message location for monster wielding an item 2024-01-14 17:43:27 +02:00
Pasi Kallinen
679c312d4d Message location for monster hurling a potion 2024-01-14 17:21:48 +02:00
nhmall
bbb7523a04 vestiges of C(color) 2024-01-14 08:57:28 -05:00
Pasi Kallinen
3160112ece Accessibility: Show a message when monster is spotted
Adds a new boolean option, spot_monsters.  If on, every time
the hero notices a monster which was out of sight before,
a message is given.  Combine with accessiblemsg to get the
monster location:

(3north): You see a newt.

Breaks saves and bones.
2024-01-14 13:33:02 +02:00