Commit Graph

15 Commits

Author SHA1 Message Date
PatR
8073c40477 redo nowrap_add()
Yahoo!'s mailer delivered the report about nowrap_add() to my spam
folder, apparently because it thinks that the signature attachments
"may contain harmful content".  :-(

nowrap_add() checks for signed overflow after the fact, so after
undefined behavior if that happens.

This rewrites nowrap_add() and moves it from end.c to integer.h.

I haven't generated any values big enough to exercise it, but the
algorithm is straightforward so I'll take it on faith.
2024-07-07 17:34:37 -07:00
PatR
05cbbc7181 fix PR #1254 - avoid signed integer overflow
Pull request from mkuoppal:  avoid integer overflow when user types
digits and they're combined into a number by successively multiplying
intermediate value by 10 and adding new digit.  Needed to avoid
triggering undefined behavior if the value overflows the largest
signed integer (actually long int).

This is a much more general fix than the code in the pull request,
which imposed an arbitrary limit for one aspect of tty input.

I'm not convinced that integer.h was the right place to add the new
AppendLongDigit() macro.  I may not have caught all the places where
it is needed.  files.c accumulates a value from digits but uses
unsigned int, so overflow won't trigger undefined behavior (although
it presumably ends up with a different value than what was intended).
options.c and coloratt.c accumulate smaller integers and have a limit
on the number of digits they'll use, so can't overflow.

Fixes #1254
2024-06-09 14:17:14 -07:00
RainRat
a3658f85ac fix typos 2024-02-28 20:15:56 -08:00
nhmall
84baa5d7d4 comment update 2022-07-01 08:36:03 -04:00
nhmall
465db21c79 typedef follow-up 2022-07-01 08:23:31 -04:00
nhmall
ac9ba38449 file header bump from "NetHack 3.6" to "NetHack 3.7" 2020-08-03 22:07:36 -04:00
PatR
df3df3cb6f revise integer.h for vms
The VMS compiler supports C99 and defines __STDC_VERSION__ to the
corresponding value, but it doesn't supply <stdint.h> so isaac64.c
wouldn't compile.  It does supply another header containing what is
needed.
2019-03-06 11:37:52 -08:00
nhmall
446b0e69d5 add a descriptive comment to integer.h 2019-01-30 08:30:02 -05:00
nhmall
f2071a66f7 fix a likely typo/transcription error in integer.h 2019-01-29 22:12:09 -05:00
Patric Mueller
b7edc7f8e8 Workaround for including stdint.h on older GCC versions
GCC doesn't set __STDC_VERSION__ for older versions. It is verified to
be set by default on 5.3.0.

Older versions set __INT64_MAX__ though (oldest version tested is
4.5.4).

If compilation with older GCC versions is required, set -std=c99. Even
3.4.6 is supported with this setting.
2019-01-29 15:10:01 +01:00
nhmall
6c114640f5 some system-specific adjustments for RNG routines
move some system-specific seed-related stuff from hacklib.c to
a system-specific source file and #define SYS_RANDOM_SEED to
utilize it during build.

Windows changes for random seed generation using
crypto next gen (CNG) api routines.

Corresponding vms changes due to disentangling of VMS and
unix when the unix seed bits got moved (untested).
2019-01-28 10:02:08 +01:00
Patric Mueller
f9433b2a87 integrate isaac64 into nethack
Also removed the float code from isaac64 as they are not used in
NetHack.
2019-01-28 10:02:08 +01:00
Patric Mueller
b3fde3eb41 fix check for stdc version in include/integer.h 2019-01-28 10:02:08 +01:00
keni
0f58af6f37 add missing copyright info 2018-04-25 16:54:50 -04:00
nhmall
83c58f009e Another file for support of Ray Chason's patch 2016-03-05 15:38:44 -05:00