Commit Graph

6618 Commits

Author SHA1 Message Date
Dean Luick
5eaf028c0f Re-fix altar compiler warning
Implement a better fix for commit 2f4f7d22d ("Fix align type
mixup wth align mask") which was reverted in commit 4e35e8b5a
("Revert "Fix align type mixup wth align mask"").

In the present code, the field align in both struct altar and
struct monster is not an aligntyp, but an align mask with extra flags.
Change the type to match its actual use and improve the naming.

Consolidate duplicated code into a single routine.

Change the return type of induced_align() to be unsigned to match
amask usage.

Change the special level align mask values to be separate from
the normal align mask values.
2021-02-07 22:25:25 -06:00
PatR
ebc2dfdcf2 display_pickinv
A formatting bit that grew a little.  An end of line comment that
spans on two or more lines
  foo(); /* call
            foo() */
will confuse clang-format if the continuation lines don't begin
with an asterisk
  foo(); /* call
          * foo() */
Instead of just doing that, I changed display_pickinv() to add a
comment for each of its arguments.
2021-02-07 14:58:08 -08:00
PatR
eb0588583f potion dipping tweak
Update some code from four weeks ago.  One of two hold_potion()
calls was followed by update_inventory() but the other wasn't.
Have hold_potion() do that itself.  I'm not sure that this is
needed and haven't convinced myself that it's not.
2021-02-06 16:34:41 -08:00
nhmall
4e0a1e0462 during engraving, spaces were counted instead of non-spaces
2015 commit 27d8b631cd incorrectly altered a test

	/* Chop engraving down to size if necessary */
	if (len > maxelen) {
	    for (sp = ebuf; (maxelen && *sp); sp++)
->		if (!isspace(*sp)) maxelen--;
	    if (!maxelen && *sp) {
		*sp = (char)0;
		if (multi) nomovemsg = "You cannot write any more.";

was changed to:

	/* Chop engraving down to size if necessary */
        if (len > maxelen) {
	    for (sp = ebuf; (maxelen && *sp); sp++)
->		if (*sp == ' ') maxelen--;
	    if (!maxelen && *sp) {
		*sp = (char)0;
		if (multi) nomovemsg = "You cannot write any more.";

Fixes #457
2021-02-06 18:49:16 -05:00
nhmall
4e35e8b5a6 Revert "Fix align type mixup wth align mask"
This reverts commit 2f4f7d22d3
for now while the matter is investigated further.

Also closes #459
2021-02-06 14:54:54 -05:00
Pasi Kallinen
d817564a6a Lua: set and get config options
Still needs more work, especially the error handling.
2021-02-06 19:02:25 +02:00
Pasi Kallinen
9e550ccb07 Fix BIND segfault
Recent commit that added terminator entry to default_menu_cmd_info
caused a segfault when trying to BIND keys.
2021-02-05 11:14:14 +02:00
nhmall
b14c47132f more cross-compile warning bits
maximize warnings for NetHack sources
minimize warnings for Lua and pdcurses which we won't be changing
2021-02-04 19:42:07 -05:00
PatR
304d74515a some options tidying
Somehow several arrays of compound option values ended up in
between defining menu_cmd_t and using menu_cmd_t.  Reorder them.

Also, add a terminator to the list of menu commands so that it
could potentially be used manipulated from other source files
that don't have access to the array size.
2021-02-04 01:35:58 -08:00
PatR
52ae2b9df3 prevent lua crash upon init failure
panic() instead, so not much help to the player.
2021-02-03 17:09:35 -08:00
nhmall
7900632b50 Qt c++ function name shadow warnings
We have a struct called mkroom and a function called mkroom()
so c++ complains about the mkroom() function hiding the
initializer for the struct.

Similarly, we have a struct called attack and a function
called attack().

There may be a more elegant way of eliminating those two
warnings, but renaming mkroom() to do_mkroom() and
attack() to do_attack() was straightforward enough.
2021-02-03 10:55:07 -05:00
keni
4c16f74b7f Merge branch 'NetHack-3.7' of https://rodney.nethack.org:20040/git/NHsource into NetHack-3.7 2021-02-02 20:46:54 -05:00
keni
97141cd421 src/end.c: improve backtrace text spacing (see #K3259) 2021-02-02 20:45:45 -05:00
nhmall
9684b75f54 whitelist some macOS clang format-nonliteral warnings 2021-02-02 19:50:07 -05:00
nhmall
5b1d668c44 enable -Wformat-nonliteral for linux and equivalent for windows compilers
Whitelist all the verified existing triggers:
makedefs.c: In function ‘name_file’
attrib.c: one compiler balks at a ? b : c for fmtstring
cmd.c: In function ‘extcmd_via_menu’
cmd.c: In function ‘wiz_levltyp_legend’
do.c: In function ‘goto_level’
do_name.c: In function ‘coord_desc’
dungeon.c: In function ‘overview_stats’
eat.c:  one compiler balks at a ? b : c for fmtstring
end.c:  one compiler balks at a ? b : c for fmtstring
engrave.c: In function ‘engr_stats’
hack:c one compiler balks at a ? b : c for fmtstring
hacklib.c: one compiler balks at a ? b : c for fmtstring
insight.c: one compiler balks at a ? b : c for fmtstring
invent.c: In function ‘let_to_name’
light.c: In function ‘light_stats’
mhitm.c: In function ‘missmm’
options.c: In function ‘handler_symset’
options.c: In function ‘basic_menu_colors’
options.c: In function ‘optfn_o_autopickup_exceptions’
options.c: In function ‘optfn_o_menu_colors’
options.c: In function ‘optfn_o_message_types’
options.c: In function ‘optfn_o_status_cond’
options.c: In function ‘optfn_o_status_hilites’
options.c: In function ‘doset’
options.c: In function ‘doset_add_menu’
options.c: In function ‘show_menu_controls’
options.c: In function ‘handle_add_list_remove’
pager.c: In function ‘do_supplemental_info’
pager.c: In function ‘dohelp’
region.c: In function ‘region_stats’
rumors.c: sscanf usage
sounds.c: In function ‘domonnoise’
spell.c: In function ‘dospellmenu’
timeout.c: In function ‘timer_stats’
topten.c: In function ‘outentry’, fscanf, sscanf, fprintf usage
windows.c: In function ‘genl_status_update’
zap.c: one compiler balks at a ? b : c for fmtstring
win/curses/cursstat.c: In function ‘curses_status_update’
win/tty/wintty.c: In function ‘tty_status_update’
win/win32/mswproc.c: In function ‘mswin_status_update’
2021-02-02 19:03:12 -05:00
nhmall
d79365c6b0 add format string arg to Sprintf in hack.c 2021-02-02 17:20:41 -05:00
nhmall
a165538331 warning fix - missing format string in botl.c 2021-02-02 16:06:25 -05:00
nhmall
13394d12e5 resolve a warning in sounds.c
sounds.c: In function ‘add_sound_mapping’:
sounds.c:1381:33: warning: ‘sprintf’ may write a terminating nul past the end of the destination [-Wformat-overflow=]
 1381 |         Sprintf(filespec, "%s/%s", sounddir, filename);
      |                                 ^
In file included from ../include/config.h:631,
                 from ../include/hack.h:10,
                 from sounds.c:5:
../include/global.h:274:24: note: ‘sprintf’ output 2 or more bytes (assuming 257) into a destination of size 256
  274 | #define Sprintf (void) sprintf
sounds.c:1381:9: note: in expansion of macro ‘Sprintf’
 1381 |         Sprintf(filespec, "%s/%s", sounddir, filename);
      |         ^~~~~~~
2021-02-01 20:02:12 -05:00
nhmall
9566752c08 clear some more format-overflow warnings
clear some -Wformat-overflow warnings being experienced with
i586-pc-msdosdjgpp-gcc (GCC) 10.2.0 cross-compiler

--
Warnings log:

botl.c: In function 'status_hilite_menu_add':
botl.c:3661:38: warning: ' or ' directive writing 4 bytes into a region of size between 1 and 80 [-Wformat-overflow=]
 3661 |                     Sprintf(obuf, "%s or %s",
      |                                      ^~~~
In file included from ../include/config.h:631,
                 from ../include/hack.h:10,
                 from botl.c:6:
../include/global.h:274:24: note: 'sprintf' output between 5 and 163 bytes into a destination of size 80
  274 | #define Sprintf (void) sprintf
botl.c:3661:21: note: in expansion of macro 'Sprintf'
 3661 |                     Sprintf(obuf, "%s or %s",
      |                     ^~~~~~~

do_name.c: In function 'getpos_menu':
do_name.c:594:37: warning: 'sprintf' may write a terminating nul past the end of the destination [-Wformat-overflow=]
  594 |             Sprintf(fullbuf, "%s%s%s", firstmatch,
      |                                     ^
In file included from ../include/config.h:631,
                 from ../include/hack.h:10,
                 from do_name.c:6:
../include/global.h:274:24: note: 'sprintf' output 1 or more bytes (assuming 257) into a destination of size 256
  274 | #define Sprintf (void) sprintf
do_name.c:594:13: note: in expansion of macro 'Sprintf'
  594 |             Sprintf(fullbuf, "%s%s%s", firstmatch,
      |             ^~~~~~~

dungeon.c: In function 'print_dungeon':
dungeon.c:2172:27: warning: '%s' directive writing up to 1407 bytes into a region of size 256 [-Wformat-overflow=]
 2172 |             Sprintf(buf, "%s: %s %d", dptr->dname, descr, dptr->depth_start);
      |                           ^~
In file included from ../include/config.h:631,
                 from ../include/hack.h:10,
                 from dungeon.c:6:
../include/global.h:274:24: note: 'sprintf' output between 10 and 1427 bytes into a destination of size 256
  274 | #define Sprintf (void) sprintf
dungeon.c:2172:13: note: in expansion of macro 'Sprintf'
 2172 |             Sprintf(buf, "%s: %s %d", dptr->dname, descr, dptr->depth_start);
      |             ^~~~~~~
dungeon.c:2169:27: warning: '%s' directive writing up to 1407 bytes into a region of size 256 [-Wformat-overflow=]
 2169 |             Sprintf(buf, "%s: %s %d to %d", dptr->dname, makeplural(descr),
      |                           ^~
dungeon.c:2169:26: note: directive argument in the range [-2147483647, 2147483646]
 2169 |             Sprintf(buf, "%s: %s %d to %d", dptr->dname, makeplural(descr),
      |                          ^~~~~~~~~~~~~~~~~
In file included from ../include/config.h:631,
                 from ../include/hack.h:10,
                 from dungeon.c:6:
../include/global.h:274:24: note: 'sprintf' output 10 or more bytes (assuming 1427) into a destination of size 256
  274 | #define Sprintf (void) sprintf
dungeon.c:2169:13: note: in expansion of macro 'Sprintf'
 2169 |             Sprintf(buf, "%s: %s %d to %d", dptr->dname, makeplural(descr),
      |             ^~~~~~~
dungeon.c: In function 'print_mapseen':
dungeon.c:3185:33: warning: '%s' directive writing up to 255 bytes into a region of size 249 [-Wformat-overflow=]
 3185 |         Sprintf(outbuf, " (play %s to open or close drawbridge)", tmp);
      |                                 ^~                                ~~~
In file included from ../include/config.h:631,
                 from ../include/hack.h:10,
                 from dungeon.c:6:
../include/global.h:274:24: note: 'sprintf' output between 37 and 292 bytes into a destination of size 256
  274 | #define Sprintf (void) sprintf
dungeon.c:3185:9: note: in expansion of macro 'Sprintf'
 3185 |         Sprintf(outbuf, " (play %s to open or close drawbridge)", tmp);
      |         ^~~~~~~
dungeon.c:3350:35: warning: '%s' directive writing up to 255 bytes into a region of size 240 [-Wformat-overflow=]
 3350 |         Sprintf(buf, "%sThe castle%s.", PREFIX, tunesuffix(mptr, tmpbuf));
      |                                   ^~
In file included from ../include/config.h:631,
                 from ../include/hack.h:10,
                 from dungeon.c:6:
../include/global.h:274:24: note: 'sprintf' output between 18 and 273 bytes into a destination of size 256
  274 | #define Sprintf (void) sprintf
dungeon.c:3350:9: note: in expansion of macro 'Sprintf'
 3350 |         Sprintf(buf, "%sThe castle%s.", PREFIX, tunesuffix(mptr, tmpbuf));
      |         ^~~~~~~

explode.c:541:69: warning: '%s' directive writing up to 255 bytes into a region of size 236 [-Wformat-overflow=]
  541 |                     Sprintf(g.killer.name, "caught %sself in %s own %s", uhim(),
      |                                                                     ^~
In file included from ../include/config.h:631,
                 from ../include/hack.h:10,
                 from explode.c:5:
../include/global.h:274:24: note: 'sprintf' output 21 or more bytes (assuming 276) into a destination of size 256
  274 | #define Sprintf (void) sprintf
explode.c:541:21: note: in expansion of macro 'Sprintf'
  541 |                     Sprintf(g.killer.name, "caught %sself in %s own %s", uhim(),
      |                     ^~~~~~~

hacklib.c: In function 'yyyymmddhhmmss':
hacklib.c:1034:28: warning: '%02d' directive writing between 2 and 11 bytes into a region of size between 4 and 11 [-Wformat-overflow=]
 1034 |     Sprintf(datestr, "%04ld%02d%02d%02d%02d%02d", datenum, lt->tm_mon + 1,
      |                            ^~~~
hacklib.c:1034:22: note: directive argument in the range [-2147483647, 2147483647]
 1034 |     Sprintf(datestr, "%04ld%02d%02d%02d%02d%02d", datenum, lt->tm_mon + 1,
      |                      ^~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from ../include/config.h:631,
                 from ../include/hack.h:10,
                 from hacklib.c:7:
../include/global.h:274:24: note: 'sprintf' output between 15 and 67 bytes into a destination of size 15
  274 | #define Sprintf (void) sprintf
hacklib.c:1034:5: note: in expansion of macro 'Sprintf'
 1034 |     Sprintf(datestr, "%04ld%02d%02d%02d%02d%02d", datenum, lt->tm_mon + 1,
      |     ^~~~~~~
2021-02-01 16:36:17 -05:00
nhmall
e25b16e844 more warnings.h - macOS issue
It turns out that macOS barked when a POP was issued without
a prior PUSH, so since the DISABLE_WARNING_CONDEXPR_IS_CONSTANT
expanded to an empty macro on that platform.

Include a corresponding
RESTORE_WARNING_CONDEXPR_IS_CONSTANT macro for use with that
particular warning.
2021-02-01 13:37:04 -05:00
nhmall
a6631e3bb0 suppress a particular warning for an individual function; useful for non-gcc
Microsoft and other non-GNU compilers don't recognize gcc tricks
like  /*NOTREACHED*/ to suppress individual warnings. clang recognizes most
of them because it tries to be gcc-compatible. Because of that, a lot of
potentially useful warnings have had to be completely suppressed in the
past in all source files when using the non-gcc compatible compilers.

Now that the code is C99, take advantage of a way to suppress warnings for
individual functions, a big step up from suppressing the warnings
altogether.

Unfortunately, it does require a bit of ugliness caused by the
insertion of some macros in a few spots, but I'm not aware of
a cleaner alternative that still allows warnings to be enabled
in general, while suppressing a warning for known white-listed
instances.

Prior to the warning-tiggering function, place whichever one of
the following is needed to suppress the warning being encountered:

DISABLE_WARNING_UNREACHABLE_CODE
DISABLE_WARNING_CONDEXPR_IS_CONSTANT

After the warning-triggering function, place this:

RESTORE_WARNINGS

Under the hood, the compiler-appropriate warning-disabling
mechanics involve the use of C99 _Pragma, which can be used
in macros.

For unrecognized or inappropriate compilers, or if
DISABLE_WARNING_PRAGMAS is defined, the macros expand
to nothing.
2021-02-01 12:54:19 -05:00
nhmall
0835ae1542 Merge branch 'copperwater-pr455-2' into NetHack-3.7 2021-02-01 09:40:11 -05:00
PatR
0b1f5ea45e outdated vs Unix 'make depend'
After the most recent round of moving old stuff to 'outdated',
src/windows.c contained two references to non-existent files.
That broke 'make depend'.  Updating it to turn those two into
comments seems risky because someone might add an include for
some new interface later in the file.  So comment them out in
the source instead.  Also, redo previous 'make depend' update
from about three weeks ago to do the same thing.
2021-01-31 13:05:32 -08:00
nhmall
5ec6a3f341 follow-up bit for QSORTCALLBACK entries 2021-01-31 14:06:56 -05:00
nhmall
41fc278cfb CFDECLSPEC -> QSORTCALLBACK
also remove one inappropriate use of CFDECLSPEC
2021-01-31 13:58:19 -05:00
Bart House
a54a8c6854 Remove awful kludges dealing with command counts. 2021-01-30 19:06:27 -08:00
PatR
38e69519d1 fix #K3257 - lichens' sticky attack holds hero
in the air.  can_reach_floor() was changed relatively recently
to return False if hero was held by a monster.  It wasn't
necessarily because the monster was lifting him or her off the
floor though.  Restricted movement could produce same effect.

Change the new behavior to only happen when holder has used a
hug attack, so that being held by a fungus or mimic doesn't
prevent access to the floor.

This may need to be revisited because the idea that the hero's
arms have been pinned by a hugging monster contradicts the
ability to attack that monster.  However, it matches the long-
standing inability to attack any other adjacent monster in
that circumstance.
2021-01-30 17:19:17 -08:00
PatR
aacea63f7c squeaky board message grammar bit
"You hear a [BCDG] note squeak in the distance" is ok, but
"you hear a [AEF] note squeak in the distance" isn't.

Squeaky board notes already had correct a/an handling but that
particular message explicitly suppressed it.
2021-01-30 16:42:36 -08:00
nhmall
a0874c414d Merge branch 'extract-from-minvent' of https://github.com/copperwater/NetHack into copperwater-pr455-2 2021-01-30 15:24:07 -05:00
Pasi Kallinen
10cd5af500 Move other options into the options array 2021-01-30 18:43:21 +02:00
nhmall
5e5df4f6b9 remove an old #pragma from sp_lev.c that isn't actually accomplishing anything 2021-01-30 11:25:27 -05:00
copperwater
ee7664684a Unify code for extracting an object from a monster's inventory
The code for doing this (basically an obj_extract_self() call plus
handling if the object was worn or wielded) was duplicated all over, and
inconsistent - for instance, though all of them updated the monster's
misc_worn_check to indicate it was no longer wearing something in
whatever slot, only one call also set the bit that flags the monster to
consider putting on other gear afterwards.

Under a new function, extract_from_minvent, all this extra handling is
checked in one function, which can simply replace the obj_extract_self
call.

A few callers (such as stealing) have some common code *after* the
object is extracted and some other things happen such as message
printing, such as calling mselftouch if the object was worn
gloves. extract_from_minvent does not handle these cases.
2021-01-29 19:19:03 -05:00
PatR
e8d44b8329 extcmdlist[] bit 2021-01-29 12:33:20 -08:00
PatR
30ab63165f extcmdlist[] formatting
Reformat the list of commands, making all of them take two lines
(except for a couple that need more) even if they fit on one.

Put "#wizmgender" into alphabetical order.  I don't think we need
it anymore, but if we keep the functionality then it should be
demoted from a command to a wizard mode boolean option.

Also wrap a handful of lines wider than the formatting threshold.
2021-01-29 10:48:35 -08:00
Dean Luick
3da8dca836 Add missing fields in extcmdlist[] in cmd.c
This eliminates a compiler initializer warning.
2021-01-29 11:41:12 -06:00
Dean Luick
2f4f7d22d3 Fix align type mixup wth align mask
Fix two cases of missed conversion of an alignment to an align mask.

Change induced_align()'s return type to unsigned int since it returns
an align mask (unsigned), not an align type (signed).
2021-01-29 09:31:08 -06:00
Dean Luick
8ddab09cab Fix set but not used warnings 2021-01-28 21:11:21 -06:00
PatR
407acbf987 fix class discovery for fully discovered class
This was caused by a post-3.6 change I made when adding sorting
capability to '`' (and to '\' but that wasn't affected).  Cited
case was lack of "water" when all potions had been discovered.
Some other classes (but not all) were vulnerable too.
2021-01-28 17:10:18 -08:00
PatR
41956e5798 fix #K3255 - "death wand"
Prevent a wish request of "death wand" (as alternate spelling
for "wand of death") from matching "Death" monster and yielding
a random wand.

"death finger" and "death finger spellbook" produce a "spellbook
of finger of death" even without a similar fix.
2021-01-28 17:00:13 -08:00
nhmall
5bd95649de fix some warnings seen by Microsoft Visual Studio compiler
../src/nhlsel.c(467) : warning C4701: potentially uninitialized local variable 'x1' used
../src/nhlsel.c(591) : warning C4701: potentially uninitialized local variable 'x' used
../src/nhlsel.c(467) : warning C4701: potentially uninitialized local variable 'y1' used
../src/nhlsel.c(591) : warning C4701: potentially uninitialized local variable 'y' used
../src/nhlsel.c(469) : warning C4701: potentially uninitialized local variable 'x2' used
../src/nhlsel.c(469) : warning C4701: potentially uninitialized local variable 'y2' used
2021-01-28 09:45:16 -05:00
Pasi Kallinen
b502a7d9b2 Remove leftover variables 2021-01-28 12:44:45 +02:00
nhmall
9d93e1e52a follow-up bits 2021-01-27 21:04:51 -05:00
nhmall
f963c5aca7 switch source tree from k&r to c99 2021-01-26 21:06:16 -05:00
nhmall
939f20e2ea fix warning differently mklev.c 2021-01-26 08:48:38 -05:00
nhmall
62f25fd000 clear five warnings for "set but not used" variables
Note: the line numbers referenced in the warning messages below are not in sync
with the NetHack-3.7 branch and should be disregarded

files.c: In function 'get_saved_games':
files.c:1168:9: warning: unused variable 'n' [-Wunused-variable]
 1168 |     int n, j = 0;
      |         ^

mhitm.c: In function 'mdamagem':
mhitm.c:843:13: warning: variable 'cancelled' set but not used [-Wunused-but-set-variable]
  843 |     boolean cancelled;
      |             ^~~~~~~~~

mhitu.c: In function 'hitmu':
mhitu.c:943:9: warning: variable 'uncancelled' set but not used [-Wunused-but-set-variable]
  943 |     int uncancelled;
      |         ^~~~~~~~~~~

mklev.c: In function 'place_branch':
mklev.c:1214:20: warning: variable 'br_room' set but not used [-Wunused-but-set-variable]
 1214 |     struct mkroom *br_room;
      |                    ^~~~~~~

monmove.c: In function 'm_move':
monmove.c:874:43: warning: variable 'doorbuster' set but not used [-Wunused-but-set-variable]
  874 |     boolean can_open = 0, can_unlock = 0, doorbuster = 0;
      |                                           ^~~~~~~~~~
2021-01-25 12:57:47 -05:00
PatR
8a965b8cf9 \#wizintrinsic timeout values
Tell/remind wizard mode player how to specify timeout amounts
when using #wizintrinsic to set temporary timeouts.
2021-01-24 13:55:19 -08:00
PatR
8af63bf1a4 fix github issue #447 - casting area-effect spell
at self when blind.  Spell targetting would let player pick
hero's own spot but casting would reject it when blind because
hero didn't sense any monster there.  The player wanted to cast
skilled fireball at self to cure being turned into slime but
wasn't allowed.  (Targetting an adjacent spot would work for
fireball, but is only feasible when telepathy reveals a monster
there.)

While testing the one-line fix, I noticed that the message line
(tty) showed stale data (autodescribe info for target spot) as
the fireball I cast (when not blind) bounced around the vicinity.
Normally that's cleared when a message is issued or the when the
next command is requested, but skilled fireball causes multiple
explosion animations before either of those situations.
2021-01-24 13:00:44 -08:00
PatR
35b343b50b options parsing one more time
Manually created and maintained prototypes for optfn_FOO()
aren't needed once the conditionals in optlist.h and options.c
match each other.
2021-01-23 18:46:03 -08:00
PatR
8affbf5a24 options parsing madness
I should have reenabled curses before committing an earlier change;
it broke compile.

Make all optfn_FOO() be static in options.c;
fix newly added prototype for optfn_cursesgraphics();
fix conditionals for optfn_palette(), both prototype and function.

Also, add missing prototype for a sound routine.
2021-01-23 15:42:00 -08:00
PatR
ab74ed2c20 SELECTSAVED handling
By default, enable the SELECTSAVED option for everyone instead
of just for Windows or Qt.  And make Qt obey the 'selectsaved'
run-time option.

It can be disabled in config.h if necessary.
2021-01-23 15:02:11 -08:00