Compare commits

...

19 Commits

Author SHA1 Message Date
Landon Curt Noll
f1a4cb6313 update GitHub workflows to use actions/checkout@v5 2025-08-17 12:26:37 -07:00
Landon Curt Noll
59d47e80fb checkpoint test .github/workflows/dependency-review.yml 2025-08-17 12:17:23 -07:00
Landon Curt Noll
95793c3150 checkpoint on string realloc bug fix attempt
In preparation to fix issue #47, we:

Fix a minor typo in `Makefile.config`.

Move `stringindex(char *format, char *test)` from `str.c` into `codegen.c`
as static function.

Expand `STR_TABLECHUNK` from `1<<10` to `1<<16`.

Identify with an XXX comment, a problematic `realloc()` call in the
`addstr(STRINGHEAD *hp, char *str)` function of `str.c`.

Move the `charstr(int ch)` in `str.c` above the only function that uses
it, `addliteral(char *str)`, and make it a static function.

Improved comments about return values for `str.c` functions that
work on STRINGHEAD pointers.
2025-08-17 02:18:10 -07:00
Landon Curt Noll
077ba65285 Release v2.16.0.0
The following are the changes in this release:

    Starting with calc version 2.16.0.0, the ability to perform arithmetic
    on addresses of values in calc objects has been greatly restricted.

    Most arithmetic on of value addresses could easily cause calc to
    crash.  For example, prior to calc version 2.16.0.0, the following
    command was likely to crash calc:

        calc '*((&.)+1e9)'

    Subtracting two value addresses is permitted, however there is NO
    guarantee that the address of a value will remain consistent across
    calc runs.  Addresses of values depend on the circumstances of when
    the calc values were formed.

    The above restrictions and caveats apply to addresses of values.
    Such restrictions and caveats to NOT apply to the addresses of
    octets, NOR to the addresses within strings.  If isptr(x) == 2, then
    x is value-pointer and the above mentioned restrictions and caveats apply.

    See "help address" for more information on value address arithmetic.

    Added E_INVALID_DEREF (10610) error code to indicate the invalid
    dereferencing a non-variable.

    Added E_INVALID_ADDR_OP (10611) error code to indicate an invalid
    arithmetic address operation.

    We plan to let this most recent change settle down before performing
    the calc v2 to calc v3 fork.  Therefore, version 2.16.1.0 will form
    the basis for the calc v2 to calc v3 fork.
2025-08-14 18:34:32 -07:00
Landon Curt Noll
f912da9427 checkpoint adding missing edit to Makefile.config 2025-08-14 18:26:47 -07:00
Landon Curt Noll
753b101e54 prep for 2.16.0.0 release with value address arithmetic restrictions 2025-08-14 18:23:07 -07:00
Landon Curt Noll
db83b7383f prep CHANGES for the next release of calc 2025-08-13 12:53:21 -07:00
Landon Curt Noll
d9245844aa removed use of have_memmv.c and HAVE_MEMMOVE, prep for version 2.15.1.2
Removed use of HAVE_MEMMOVE as well have_memmv.c.  Removed the
building and including of have_memmv.h.  Removed the memmove()
function in blkcpy.c, used when HAVE_MEMMOVE was NOT defined.
The libc memmove(3) function as defined by <string.h> is now
required to compile calc because the replacement code in
blkcpy.c q was problematic, especially when regions overlap.
The HAVE_MEMMOVE make symbol was removed from Makefile.config.
Thanks to GitHub user @skeeto for reporting this problem.
2025-08-13 12:42:45 -07:00
Landon Curt Noll
8542143463 Merge pull request #161 from skeeto/fix-missing-includes
Add includes to alloc.h for CONST and E_FUNC
2025-08-13 10:50:56 -07:00
Christopher Wellons
50cb6ec798 Add includes to alloc.h for CONST and E_FUNC 2025-08-07 20:13:18 -04:00
Landon Curt Noll
41951e2c09 Merge pull request #159 from Gusted/patch-1 2025-06-15 20:00:28 -07:00
Gusted
b9cee333b2 Update description of log2's help page 2025-06-15 21:30:01 +02:00
Landon Curt Noll
e35bb7ffa6 update CHANGES
Declare version 2.16.0.0 will form the basis for the calc v2 to calc v3 fork.
2025-04-27 20:45:54 -07:00
Landon Curt Noll
c5b64c373b Update README.md
Fix typo
2025-04-24 01:34:48 -07:00
Landon Curt Noll
4017579aeb prep CHANGES for the next release of calc 2025-04-23 19:33:56 -07:00
Landon Curt Noll
88fb6a4e47 prep CHANGES for the next release of calc 2025-04-23 19:31:51 -07:00
Landon Curt Noll
7eb7e9de1f change VERSION from 2.15.1.0 to 2.15.1.1 2025-04-23 19:30:21 -07:00
Landon Curt Noll
42d5749da2 prep CHANGES for the next release of calc
Change Makefile.config to, if not using not HomeBrew, then try to
detect macports and/or using /opt/local/{lib,include}.

Changed version from 2.15.1.0 to 2.15.1.1.

Put full date range (1989-2025) of calc source into version.h.
2025-04-23 19:28:55 -07:00
Landon Curt Noll
bbcbb76369 improve security policy 2025-03-16 22:20:17 -07:00
23 changed files with 368 additions and 410 deletions

View File

@@ -40,7 +40,7 @@ jobs:
steps:
- name: Checkout repository
uses: actions/checkout@v4
uses: actions/checkout@v5
- name: Setup node
uses: actions/setup-node@v4
with:

14
.github/workflows/dependency-review.yml vendored Normal file
View File

@@ -0,0 +1,14 @@
name: 'Dependency Review'
on: [pull_request]
permissions:
contents: read
jobs:
dependency-review:
runs-on: ubuntu-latest
steps:
- name: 'Checkout Repository'
uses: actions/checkout@v5
- name: 'Dependency Review'
uses: actions/dependency-review-action@v4

3
.gitignore vendored
View File

@@ -90,8 +90,6 @@ have_gettime
have_gettime.h
have_inttypes.h
have_limits.h
have_memmv
have_memmv.h
have_newstr
have_newstr.h
have_offscl
@@ -162,7 +160,6 @@ ll_tmp
longbits
longbits.h
Makefile.our
memmv_tmp
newstr_tmp
NOTES
offscl_tmp

56
CHANGES
View File

@@ -1,3 +1,57 @@
The following are the changes from calc version 2.15.1.2 to 2.16.0.0:
Starting with calc version 2.16.0.0, the ability to perform arithmetic
on addresses of values in calc objects has been greatly restricted.
Most arithmetic on of value addresses could easily cause calc to
crash. For example, prior to calc version 2.16.0.0, the following
command was likely to crash calc:
calc '*((&.)+1e9)'
Subtracting two value addresses is permitted, however there is NO
guarantee that the address of a value will remain consistent across
calc runs. Addresses of values depend on the circumstances of when
the calc values were formed.
The above restrictions and caveats apply to addresses of values.
Such restrictions and caveats to NOT apply to the addresses of
octets, NOR to the addresses within strings. If isptr(x) == 2, then
x is value-pointer and the above mentioned restrictions and caveats apply.
See "help address" for more information on value address arithmetic.
Added E_INVALID_DEREF (10610) error code to indicate the invalid
dereferencing a non-variable.
Added E_INVALID_ADDR_OP (10611) error code to indicate an invalid
arithmetic address operation.
We plan to let this most recent change settle down before performing
the calc v2 to calc v3 fork. Therefore, version 2.16.1.0 will form
the basis for the calc v2 to calc v3 fork.
The following are the changes from calc version 2.15.1.2 to 2.15.1.2:
Removed use of HAVE_MEMMOVE as well have_memmv.c. Removed the
building and including of have_memmv.h. Removed the memmove()
function in blkcpy.c, used when HAVE_MEMMOVE was NOT defined.
The libc memmove(3) function as defined by <string.h> is now
required to compile calc because the replacement code in
blkcpy.c q was problematic, especially when regions overlap.
The HAVE_MEMMOVE make symbol was removed from Makefile.config.
Thanks to GitHub user @skeeto for reporting this problem.
The following are the changes from calc version 2.15.1.1 to 2.15.1.1:
Change Makefile.config to, if not using not HomeBrew, then try to
detect macports and/or using /opt/local/{lib,include}.
Put full date range (1989-2025) of calc source into version.h.
The following are the changes from calc version 2.15.0.7 to 2.15.1.0:
Converted all ASCII tabs to ASCII spaces using a 8 character
@@ -8,8 +62,6 @@ The following are the changes from calc version 2.15.0.7 to 2.15.1.0:
Fixed trailblank. It was pruning . in its find search.
Added check for ASCII tabs is non-Makefiles.
This version will form the basis for the calc v2 to calc v3 fork.
The following are the changes from calc version 2.15.0.6 to 2.15.0.7:

119
Makefile
View File

@@ -2,7 +2,7 @@
#
# calc - arbitrary precision calculator
#
# Copyright (C) 1999-2018,2021-2023 Landon Curt Noll
# Copyright (C) 1999-2018,2021-2025 Landon Curt Noll
#
# Suggestion: Read the HOWTO.INSTALL file.
#
@@ -173,7 +173,7 @@ LIB_H_SRC= alloc.h attribute.h banned.h blkcpy.h block.h bool.h byteswap.h \
BUILD_H_SRC= align32.h args.h charbit.h conf.h endian_calc.h errsym.h fposval.h \
have_arc4random.h have_ban_pragma.h have_const.h have_environ.h \
have_fgetsetpos.h have_fpos_pos.h have_getpgid.h have_getprid.h \
have_getsid.h have_gettime.h have_inttypes.h have_limits.h have_memmv.h \
have_getsid.h have_gettime.h have_inttypes.h have_limits.h \
have_newstr.h have_offscl.h have_posscl.h have_rusage.h have_statfs.h \
have_stdbool.h have_stdint.h have_stdlib.h have_strdup.h have_string.h \
have_strlcat.h have_strlcpy.h have_sys_mount.h have_sys_param.h \
@@ -191,7 +191,7 @@ BUILD_C_SRC=
UTIL_C_SRC= align32.c charbit.c chk_c.c endian.c fposval.c have_arc4random.c \
have_ban_pragma.c have_const.c have_environ.c have_fgetsetpos.c \
have_fpos_pos.c have_getpgid.c have_getprid.c have_getsid.c \
have_gettime.c have_memmv.c have_newstr.c have_offscl.c have_posscl.c \
have_gettime.c have_newstr.c have_offscl.c have_posscl.c \
have_rusage.c have_statfs.c have_stdvs.c have_strdup.c have_strlcat.c \
have_strlcpy.c have_uid_t.c have_unused.c have_ustat.c have_varvs.c \
longbits.c
@@ -207,7 +207,7 @@ UTIL_MISC_SRC= fposval.h.def
#
UTIL_OBJS= endian.o longbits.o have_newstr.o have_uid_t.o \
have_const.o fposval.o have_fgetsetpos.o have_fpos_pos.o \
try_strarg.o have_stdvs.o have_varvs.o have_posscl.o have_memmv.o \
try_strarg.o have_stdvs.o have_varvs.o have_posscl.o \
have_ustat.o have_getsid.o have_getpgid.o have_environ.o \
have_gettime.o have_getprid.o ver_calc.o have_rusage.o have_strdup.o \
have_unused.o have_ban_pragma.o have_strlcpy.o have_strlcat.o \
@@ -216,7 +216,7 @@ UTIL_OBJS= endian.o longbits.o have_newstr.o have_uid_t.o \
# these temp files may be created (and removed) during the build of BUILD_C_SRC
#
UTIL_TMP= ll_tmp fpos_tmp fposval_tmp const_tmp uid_tmp newstr_tmp vs_tmp \
memmv_tmp offscl_tmp posscl_tmp newstr_tmp \
offscl_tmp posscl_tmp newstr_tmp \
getsid_tmp gettime_tmp getprid_tmp rusage_tmp strdup_tmp
# these utility executables may be created in the process of
@@ -1234,7 +1234,7 @@ have_fpos_pos.h: have_fpos_pos.c have_fgetsetpos.h have_posscl.h have_string.h \
fposval.h: fposval.c have_fgetsetpos.h have_fpos_pos.h have_offscl.h have_posscl.h \
endian_calc.h banned.h have_ban_pragma.h fposval.h.def alloc.h \
have_newstr.h have_memmv.h have_string.h have_const.h have_string.h \
have_newstr.h have_string.h have_const.h have_string.h \
have_unused.h have_stdbool.h ${MK_SET}
${Q} ${RM} -f fposval_tmp $@
${H} echo 'forming $@'
@@ -1622,46 +1622,6 @@ have_newstr.h: have_newstr.c banned.h have_ban_pragma.h have_string.h ${MK_SET}
${TRUE}; \
fi
have_memmv.h: have_memmv.c banned.h have_ban_pragma.h have_string.h ${MK_SET}
${Q} ${RM} -f have_memmv have_memmv.o memmv_tmp $@
${H} echo 'forming $@'
${Q} echo '/*' > $@
${Q} echo ' * DO NOT EDIT -- generated by the Makefile rule $@' >> $@
${Q} echo ' */' >> $@
${Q} echo '' >> $@
${Q} echo '' >> $@
${Q} echo '#if !defined(CALC_HAVE_MEMMV_H)' >> $@
${Q} echo '#define CALC_HAVE_MEMMV_H' >> $@
${Q} echo '' >> $@
${Q} echo '' >> $@
${Q} echo '/* do we have or want memmove()? */' >> $@
${Q} ${RM} -f have_memmv.o have_memmv
-${Q} ${LCC} ${ICFLAGS} ${HAVE_MEMMOVE} have_memmv.c -c ${S} \
|| ${TRUE}
-${Q} ${LCC} ${ILDFLAGS} have_memmv.o -o have_memmv${EXT} ${S} \
|| ${TRUE}
-${Q} ./have_memmv${EXT} > memmv_tmp ${E} \
|| ${TRUE}
-${Q} if [ -s memmv_tmp ]; then \
${CAT} memmv_tmp >> $@; \
else \
echo '#undef HAVE_MEMMOVE /* no */' >> $@; \
fi
${Q} echo '' >> $@
${Q} echo '' >> $@
${Q} echo '#endif /* !CALC_HAVE_MEMMV_H */' >> $@
${Q} ${RM} -f have_memmv have_memmv.o memmv_tmp
${H} echo '$@ formed'
-@if [ -z "${Q}" ]; then \
echo ''; \
echo '=-=-= start of $@ =-=-='; \
${CAT} $@; \
echo '=-=-= end of $@ =-=-='; \
echo ''; \
else \
${TRUE}; \
fi
have_ustat.h: have_ustat.c banned.h have_ban_pragma.h ${MK_SET}
${Q} ${RM} -f ustat_tmp $@
${H} echo 'forming $@'
@@ -2207,7 +2167,7 @@ errsym.h: errcode${EXT}
fi
errcode${EXT}: errtbl.c attribute.h bool.h errtbl.h have_const.h have_stdbool.h have_newstr.h \
have_memmv.h endian_calc.h longbits.h ${MK_SET}
endian_calc.h longbits.h ${MK_SET}
${RM} -f $@
${LCC} ${ICFLAGS} ${ILDFLAGS} -DERRCODE_SRC errtbl.c -o $@
@@ -2650,7 +2610,7 @@ version:
@echo ${VERSION}
ver_calc${EXT}: version.c strl.c have_string.h have_const.h have_newstr.h \
have_strlcpy.h have_memmv.h have_strlcat.h endian_calc.h longbits.h \
have_strlcpy.h have_strlcat.h endian_calc.h longbits.h \
have_unused.h charbit.h have_stdbool.h
${RM} -f $@
${LCC} ${ICFLAGS} -DCALC_VER ${ILDFLAGS} version.c strl.c -o $@
@@ -2922,7 +2882,6 @@ env:
@echo 'HAVE_GETTIME=${HAVE_GETTIME}'; echo ''
@echo 'HAVE_INTTYPES_H=${HAVE_INTTYPES_H}'; echo ''
@echo 'HAVE_LIMITS_H=${HAVE_LIMITS_H}'; echo ''
@echo 'HAVE_MEMMOVE=${HAVE_MEMMOVE}'; echo ''
@echo 'HAVE_NEWSTR=${HAVE_NEWSTR}'; echo ''
@echo 'HAVE_OFFSCL=${HAVE_OFFSCL}'; echo ''
@echo 'HAVE_POSSCL=${HAVE_POSSCL}'; echo ''
@@ -3248,7 +3207,7 @@ prep:
${Q}echo '=-=-=-=-=-= end of ${MAKE} chk =-=-=-=-=-='
${Q}echo
@${Q}if ! ./chk_tree >/dev/null 2>&1; then \
echo almost satifactory except for chk_tree; \
echo almost satisfactory except for chk_tree; \
else \
echo All is OK; \
fi
@@ -4082,7 +4041,6 @@ addop.o: hash.h
addop.o: have_ban_pragma.h
addop.o: have_const.h
addop.o: have_limits.h
addop.o: have_memmv.h
addop.o: have_newstr.h
addop.o: have_stdbool.h
addop.o: have_stdlib.h
@@ -4124,7 +4082,6 @@ assocfunc.o: hash.h
assocfunc.o: have_ban_pragma.h
assocfunc.o: have_const.h
assocfunc.o: have_limits.h
assocfunc.o: have_memmv.h
assocfunc.o: have_newstr.h
assocfunc.o: have_stdbool.h
assocfunc.o: have_stdlib.h
@@ -4159,7 +4116,6 @@ blkcpy.o: have_ban_pragma.h
blkcpy.o: have_const.h
blkcpy.o: have_fgetsetpos.h
blkcpy.o: have_limits.h
blkcpy.o: have_memmv.h
blkcpy.o: have_newstr.h
blkcpy.o: have_stdbool.h
blkcpy.o: have_stdlib.h
@@ -4190,7 +4146,6 @@ block.o: hash.h
block.o: have_ban_pragma.h
block.o: have_const.h
block.o: have_limits.h
block.o: have_memmv.h
block.o: have_newstr.h
block.o: have_stdbool.h
block.o: have_stdlib.h
@@ -4218,7 +4173,6 @@ byteswap.o: errtbl.h
byteswap.o: have_ban_pragma.h
byteswap.o: have_const.h
byteswap.o: have_limits.h
byteswap.o: have_memmv.h
byteswap.o: have_newstr.h
byteswap.o: have_stdbool.h
byteswap.o: have_stdlib.h
@@ -4250,7 +4204,6 @@ calc.o: hash.h
calc.o: have_ban_pragma.h
calc.o: have_const.h
calc.o: have_limits.h
calc.o: have_memmv.h
calc.o: have_newstr.h
calc.o: have_stdbool.h
calc.o: have_stdlib.h
@@ -4309,7 +4262,6 @@ codegen.o: hash.h
codegen.o: have_ban_pragma.h
codegen.o: have_const.h
codegen.o: have_limits.h
codegen.o: have_memmv.h
codegen.o: have_newstr.h
codegen.o: have_stdbool.h
codegen.o: have_stdlib.h
@@ -4347,7 +4299,6 @@ comfunc.o: errtbl.h
comfunc.o: have_ban_pragma.h
comfunc.o: have_const.h
comfunc.o: have_limits.h
comfunc.o: have_memmv.h
comfunc.o: have_newstr.h
comfunc.o: have_stdbool.h
comfunc.o: have_stdlib.h
@@ -4372,7 +4323,6 @@ commath.o: errtbl.h
commath.o: have_ban_pragma.h
commath.o: have_const.h
commath.o: have_limits.h
commath.o: have_memmv.h
commath.o: have_newstr.h
commath.o: have_stdbool.h
commath.o: have_stdlib.h
@@ -4401,7 +4351,6 @@ config.o: hash.h
config.o: have_ban_pragma.h
config.o: have_const.h
config.o: have_limits.h
config.o: have_memmv.h
config.o: have_newstr.h
config.o: have_stdbool.h
config.o: have_stdlib.h
@@ -4440,7 +4389,6 @@ const.o: hash.h
const.o: have_ban_pragma.h
const.o: have_const.h
const.o: have_limits.h
const.o: have_memmv.h
const.o: have_newstr.h
const.o: have_stdbool.h
const.o: have_stdlib.h
@@ -4473,7 +4421,6 @@ custom.o: hash.h
custom.o: have_ban_pragma.h
custom.o: have_const.h
custom.o: have_limits.h
custom.o: have_memmv.h
custom.o: have_newstr.h
custom.o: have_stdbool.h
custom.o: have_stdlib.h
@@ -4509,7 +4456,6 @@ errtbl.o: func.h
errtbl.o: hash.h
errtbl.o: have_const.h
errtbl.o: have_limits.h
errtbl.o: have_memmv.h
errtbl.o: have_newstr.h
errtbl.o: have_stdbool.h
errtbl.o: have_stdlib.h
@@ -4546,7 +4492,6 @@ file.o: have_const.h
file.o: have_fgetsetpos.h
file.o: have_fpos_pos.h
file.o: have_limits.h
file.o: have_memmv.h
file.o: have_newstr.h
file.o: have_stdbool.h
file.o: have_stdlib.h
@@ -4576,7 +4521,6 @@ fposval.o: have_const.h
fposval.o: have_fgetsetpos.h
fposval.o: have_fpos_pos.h
fposval.o: have_limits.h
fposval.o: have_memmv.h
fposval.o: have_newstr.h
fposval.o: have_offscl.h
fposval.o: have_posscl.h
@@ -4610,7 +4554,6 @@ func.o: have_ban_pragma.h
func.o: have_const.h
func.o: have_fgetsetpos.h
func.o: have_limits.h
func.o: have_memmv.h
func.o: have_newstr.h
func.o: have_rusage.h
func.o: have_stdbool.h
@@ -4657,7 +4600,6 @@ hash.o: hash.h
hash.o: have_ban_pragma.h
hash.o: have_const.h
hash.o: have_limits.h
hash.o: have_memmv.h
hash.o: have_newstr.h
hash.o: have_stdbool.h
hash.o: have_stdlib.h
@@ -4709,10 +4651,6 @@ have_getsid.o: have_unistd.h
have_gettime.o: banned.h
have_gettime.o: have_ban_pragma.h
have_gettime.o: have_gettime.c
have_memmv.o: banned.h
have_memmv.o: have_ban_pragma.h
have_memmv.o: have_memmv.c
have_memmv.o: have_string.h
have_newstr.o: banned.h
have_newstr.o: have_ban_pragma.h
have_newstr.o: have_newstr.c
@@ -4787,7 +4725,6 @@ help.o: hash.h
help.o: have_ban_pragma.h
help.o: have_const.h
help.o: have_limits.h
help.o: have_memmv.h
help.o: have_newstr.h
help.o: have_stdbool.h
help.o: have_stdlib.h
@@ -4821,7 +4758,6 @@ hist.o: hash.h
hist.o: have_ban_pragma.h
hist.o: have_const.h
hist.o: have_limits.h
hist.o: have_memmv.h
hist.o: have_newstr.h
hist.o: have_stdbool.h
hist.o: have_stdlib.h
@@ -4862,7 +4798,6 @@ input.o: hash.h
input.o: have_ban_pragma.h
input.o: have_const.h
input.o: have_limits.h
input.o: have_memmv.h
input.o: have_newstr.h
input.o: have_stdbool.h
input.o: have_stdlib.h
@@ -4906,7 +4841,6 @@ label.o: hash.h
label.o: have_ban_pragma.h
label.o: have_const.h
label.o: have_limits.h
label.o: have_memmv.h
label.o: have_newstr.h
label.o: have_stdbool.h
label.o: have_stdlib.h
@@ -4944,7 +4878,6 @@ lib_calc.o: hash.h
lib_calc.o: have_ban_pragma.h
lib_calc.o: have_const.h
lib_calc.o: have_limits.h
lib_calc.o: have_memmv.h
lib_calc.o: have_newstr.h
lib_calc.o: have_stdbool.h
lib_calc.o: have_stdlib.h
@@ -4982,7 +4915,6 @@ lib_util.o: errtbl.h
lib_util.o: have_ban_pragma.h
lib_util.o: have_const.h
lib_util.o: have_limits.h
lib_util.o: have_memmv.h
lib_util.o: have_newstr.h
lib_util.o: have_stdbool.h
lib_util.o: have_stdlib.h
@@ -5009,7 +4941,6 @@ listfunc.o: hash.h
listfunc.o: have_ban_pragma.h
listfunc.o: have_const.h
listfunc.o: have_limits.h
listfunc.o: have_memmv.h
listfunc.o: have_newstr.h
listfunc.o: have_stdbool.h
listfunc.o: have_stdlib.h
@@ -5048,7 +4979,6 @@ matfunc.o: hash.h
matfunc.o: have_ban_pragma.h
matfunc.o: have_const.h
matfunc.o: have_limits.h
matfunc.o: have_memmv.h
matfunc.o: have_newstr.h
matfunc.o: have_stdbool.h
matfunc.o: have_stdlib.h
@@ -5083,7 +5013,6 @@ math_error.o: hash.h
math_error.o: have_ban_pragma.h
math_error.o: have_const.h
math_error.o: have_limits.h
math_error.o: have_memmv.h
math_error.o: have_newstr.h
math_error.o: have_stdbool.h
math_error.o: have_stdlib.h
@@ -5117,7 +5046,6 @@ obj.o: hash.h
obj.o: have_ban_pragma.h
obj.o: have_const.h
obj.o: have_limits.h
obj.o: have_memmv.h
obj.o: have_newstr.h
obj.o: have_stdbool.h
obj.o: have_stdlib.h
@@ -5159,7 +5087,6 @@ opcodes.o: have_ban_pragma.h
opcodes.o: have_const.h
opcodes.o: have_fgetsetpos.h
opcodes.o: have_limits.h
opcodes.o: have_memmv.h
opcodes.o: have_newstr.h
opcodes.o: have_stdbool.h
opcodes.o: have_stdlib.h
@@ -5191,7 +5118,6 @@ pix.o: endian_calc.h
pix.o: have_ban_pragma.h
pix.o: have_const.h
pix.o: have_limits.h
pix.o: have_memmv.h
pix.o: have_newstr.h
pix.o: have_stdbool.h
pix.o: have_stdlib.h
@@ -5219,7 +5145,6 @@ poly.o: hash.h
poly.o: have_ban_pragma.h
poly.o: have_const.h
poly.o: have_limits.h
poly.o: have_memmv.h
poly.o: have_newstr.h
poly.o: have_stdbool.h
poly.o: have_stdlib.h
@@ -5243,7 +5168,6 @@ prime.o: endian_calc.h
prime.o: have_ban_pragma.h
prime.o: have_const.h
prime.o: have_limits.h
prime.o: have_memmv.h
prime.o: have_newstr.h
prime.o: have_stdbool.h
prime.o: have_stdlib.h
@@ -5269,7 +5193,6 @@ qfunc.o: errtbl.h
qfunc.o: have_ban_pragma.h
qfunc.o: have_const.h
qfunc.o: have_limits.h
qfunc.o: have_memmv.h
qfunc.o: have_newstr.h
qfunc.o: have_stdbool.h
qfunc.o: have_stdlib.h
@@ -5296,7 +5219,6 @@ qio.o: errtbl.h
qio.o: have_ban_pragma.h
qio.o: have_const.h
qio.o: have_limits.h
qio.o: have_memmv.h
qio.o: have_newstr.h
qio.o: have_stdbool.h
qio.o: have_stdlib.h
@@ -5322,7 +5244,6 @@ qmath.o: errtbl.h
qmath.o: have_ban_pragma.h
qmath.o: have_const.h
qmath.o: have_limits.h
qmath.o: have_memmv.h
qmath.o: have_newstr.h
qmath.o: have_stdbool.h
qmath.o: have_stdlib.h
@@ -5347,7 +5268,6 @@ qmod.o: errtbl.h
qmod.o: have_ban_pragma.h
qmod.o: have_const.h
qmod.o: have_limits.h
qmod.o: have_memmv.h
qmod.o: have_newstr.h
qmod.o: have_stdbool.h
qmod.o: have_stdlib.h
@@ -5372,7 +5292,6 @@ qtrans.o: errtbl.h
qtrans.o: have_ban_pragma.h
qtrans.o: have_const.h
qtrans.o: have_limits.h
qtrans.o: have_memmv.h
qtrans.o: have_newstr.h
qtrans.o: have_stdbool.h
qtrans.o: have_stdlib.h
@@ -5400,7 +5319,6 @@ quickhash.o: hash.h
quickhash.o: have_ban_pragma.h
quickhash.o: have_const.h
quickhash.o: have_limits.h
quickhash.o: have_memmv.h
quickhash.o: have_newstr.h
quickhash.o: have_stdbool.h
quickhash.o: have_stdlib.h
@@ -5434,7 +5352,6 @@ sample_many.o: hash.h
sample_many.o: have_ban_pragma.h
sample_many.o: have_const.h
sample_many.o: have_limits.h
sample_many.o: have_memmv.h
sample_many.o: have_newstr.h
sample_many.o: have_stdbool.h
sample_many.o: have_stdlib.h
@@ -5468,7 +5385,6 @@ sample_rand.o: hash.h
sample_rand.o: have_ban_pragma.h
sample_rand.o: have_const.h
sample_rand.o: have_limits.h
sample_rand.o: have_memmv.h
sample_rand.o: have_newstr.h
sample_rand.o: have_stdbool.h
sample_rand.o: have_stdlib.h
@@ -5500,7 +5416,6 @@ seed.o: have_getprid.h
seed.o: have_getsid.h
seed.o: have_gettime.h
seed.o: have_limits.h
seed.o: have_memmv.h
seed.o: have_newstr.h
seed.o: have_rusage.h
seed.o: have_statfs.h
@@ -5538,7 +5453,6 @@ sha1.o: hash.h
sha1.o: have_ban_pragma.h
sha1.o: have_const.h
sha1.o: have_limits.h
sha1.o: have_memmv.h
sha1.o: have_newstr.h
sha1.o: have_stdbool.h
sha1.o: have_stdlib.h
@@ -5569,7 +5483,6 @@ size.o: hash.h
size.o: have_ban_pragma.h
size.o: have_const.h
size.o: have_limits.h
size.o: have_memmv.h
size.o: have_newstr.h
size.o: have_stdbool.h
size.o: have_stdlib.h
@@ -5603,7 +5516,6 @@ str.o: hash.h
str.o: have_ban_pragma.h
str.o: have_const.h
str.o: have_limits.h
str.o: have_memmv.h
str.o: have_newstr.h
str.o: have_stdbool.h
str.o: have_stdlib.h
@@ -5625,7 +5537,6 @@ strl.o: banned.h
strl.o: decl.h
strl.o: have_ban_pragma.h
strl.o: have_const.h
strl.o: have_memmv.h
strl.o: have_newstr.h
strl.o: have_string.h
strl.o: have_strlcat.h
@@ -5651,7 +5562,6 @@ symbol.o: hash.h
symbol.o: have_ban_pragma.h
symbol.o: have_const.h
symbol.o: have_limits.h
symbol.o: have_memmv.h
symbol.o: have_newstr.h
symbol.o: have_stdbool.h
symbol.o: have_stdlib.h
@@ -5688,7 +5598,6 @@ token.o: hash.h
token.o: have_ban_pragma.h
token.o: have_const.h
token.o: have_limits.h
token.o: have_memmv.h
token.o: have_newstr.h
token.o: have_stdbool.h
token.o: have_stdlib.h
@@ -5725,7 +5634,6 @@ value.o: have_ban_pragma.h
value.o: have_const.h
value.o: have_fgetsetpos.h
value.o: have_limits.h
value.o: have_memmv.h
value.o: have_newstr.h
value.o: have_stdbool.h
value.o: have_stdlib.h
@@ -5762,7 +5670,6 @@ version.o: hash.h
version.o: have_ban_pragma.h
version.o: have_const.h
version.o: have_limits.h
version.o: have_memmv.h
version.o: have_newstr.h
version.o: have_stdbool.h
version.o: have_stdlib.h
@@ -5793,7 +5700,6 @@ zfunc.o: errtbl.h
zfunc.o: have_ban_pragma.h
zfunc.o: have_const.h
zfunc.o: have_limits.h
zfunc.o: have_memmv.h
zfunc.o: have_newstr.h
zfunc.o: have_stdbool.h
zfunc.o: have_stdlib.h
@@ -5817,7 +5723,6 @@ zio.o: errtbl.h
zio.o: have_ban_pragma.h
zio.o: have_const.h
zio.o: have_limits.h
zio.o: have_memmv.h
zio.o: have_newstr.h
zio.o: have_stdbool.h
zio.o: have_stdlib.h
@@ -5842,7 +5747,6 @@ zmath.o: have_ban_pragma.h
zmath.o: have_const.h
zmath.o: have_inttypes.h
zmath.o: have_limits.h
zmath.o: have_memmv.h
zmath.o: have_newstr.h
zmath.o: have_stdbool.h
zmath.o: have_stdint.h
@@ -5868,7 +5772,6 @@ zmod.o: errtbl.h
zmod.o: have_ban_pragma.h
zmod.o: have_const.h
zmod.o: have_limits.h
zmod.o: have_memmv.h
zmod.o: have_newstr.h
zmod.o: have_stdbool.h
zmod.o: have_stdlib.h
@@ -5893,7 +5796,6 @@ zmul.o: errtbl.h
zmul.o: have_ban_pragma.h
zmul.o: have_const.h
zmul.o: have_limits.h
zmul.o: have_memmv.h
zmul.o: have_newstr.h
zmul.o: have_stdbool.h
zmul.o: have_stdlib.h
@@ -5921,7 +5823,6 @@ zprime.o: hash.h
zprime.o: have_ban_pragma.h
zprime.o: have_const.h
zprime.o: have_limits.h
zprime.o: have_memmv.h
zprime.o: have_newstr.h
zprime.o: have_stdbool.h
zprime.o: have_stdlib.h
@@ -5955,7 +5856,6 @@ zrand.o: hash.h
zrand.o: have_ban_pragma.h
zrand.o: have_const.h
zrand.o: have_limits.h
zrand.o: have_memmv.h
zrand.o: have_newstr.h
zrand.o: have_stdbool.h
zrand.o: have_stdlib.h
@@ -5988,7 +5888,6 @@ zrandom.o: hash.h
zrandom.o: have_ban_pragma.h
zrandom.o: have_const.h
zrandom.o: have_limits.h
zrandom.o: have_memmv.h
zrandom.o: have_newstr.h
zrandom.o: have_stdbool.h
zrandom.o: have_stdlib.h

View File

@@ -2,7 +2,7 @@
#
# Makefile.config - Calc configuration and compile configuration values
#
# Copyright (C) 2023 Landon Curt Noll
# Copyright (C) 2023,2025 Landon Curt Noll
#
# Suggestion: Read the HOWTO.INSTALL file.
#
@@ -436,18 +436,6 @@ HAVE_ARC4RANDOM=
HAVE_NEWSTR=
#HAVE_NEWSTR= -DHAVE_NO_NEWSTR
# Determine if we have memmove()
#
# If HAVE_MEMMOVE is empty, this Makefile will run the have_memmv program
# to determine if memmove() is supported. If HAVE_MEMMOVE is set to
# -DHAVE_NO_MEMMOVE, then calc will use internal functions to simulate
# the memory move function that does correct overlapping memory moves.
#
# If in doubt, leave HAVE_MEMMOVE empty and this Makefile will figure it out.
#
HAVE_MEMMOVE=
#HAVE_MEMMOVE= -DHAVE_NO_MEMMOVE
# Determine if we have ustat()
#
# If HAVE_USTAT is empty, this Makefile will run the have_ustat program
@@ -1112,6 +1100,9 @@ READLINE_EXTRAS= -lhistory -lncurses
#READLINE_LIB= -L${PREFIX}/lib -lreadline
#READLINE_EXTRAS= -lhistory -lncurses
#
#READLINE_LIB= -L/opt/local/lib -lreadline
#READLINE_EXTRAS= -lhistory -lncurses
#
# For Apple OS X: install fink from http://fink.sourceforge.net
# and then do a 'fink install readline' and then use:
#
@@ -1130,6 +1121,7 @@ READLINE_EXTRAS= -lhistory -lncurses
READLINE_INCLUDE=
#READLINE_INCLUDE= -I/usr/gnu/include
#READLINE_INCLUDE= -I${PREFIX}/include
#READLINE_INCLUDE= -I/opt/local/include
# Handle the case where macOS is being used with HomeBrew
# # and using the readline, history, and ncurses libraries.
@@ -1137,6 +1129,16 @@ READLINE_INCLUDE=
ifneq ($(HOMEBREW_PREFIX),)
READLINE_LIB:= -L${HOMEBREW_PREFIX}/opt/readline/lib -lreadline
READLINE_INCLUDE:= -I${HOMEBREW_PREFIX}/opt/readline/include
# If not HomeBrew, then try to detect macports and/or using /opt/local/{lib,include}
#
else # perhaps macports and/or using /opt/local/{lib,include} ?
ifneq ($(wildcard /opt/local/lib/*),)
READLINE_LIB:= -L/opt/local/lib -lreadline
endif
ifneq ($(wildcard /opt/local/incliude/*),)
READLINE_INCLUDE:= -I/opt/local/include
endif
endif # ($(HOMEBREW_PREFIX),)
# If $PAGER is not set, use this program to display a help file
@@ -1243,11 +1245,11 @@ EXT=
# The calc version in the form of x.y.z.w
#
VERSION= 2.15.1.0
VERSION= 2.16.0.0
# The calc major version in the form of x.y.z
#
VER= 2.15.1
VER= 2.16.0
# Names of shared libraries with versions
#
@@ -1356,7 +1358,7 @@ COMMON_LDFLAGS= ${EXTRA_LDFLAGS}
# For more info see: https://github.com/google/sanitizers/wiki/AddressSanitizer
# See also: https://developer.apple.com/documentation/xcode/diagnosing-memory-thread-and-crash-issues-early
#
# The following Address Sanitizer (ASAN) are common to both REHL9.2 (Linux) and macOS 14.0.
# The following Address Sanitizer (ASAN) are common to both RHEL9.2 (Linux) and macOS 14.0.
#
# By default, the Address Sanitizer is NOT enabled, not compiled into calc.
# To enable the Address Sanitizer, uncomment the appropriate lines in Makefile.local !!!

View File

@@ -8,7 +8,7 @@ on Debian: sudo apt install calc
on RHEL: sudo dnf install calc
on Ubuntu: sudo apt install calc
via Termux: apt install calc
via src: sudo make clobber all chk instsll
via src: sudo make clobber all chk install
```
## TL;DR Run calc
@@ -283,3 +283,8 @@ help unexpected
It contains information about differences between C and calc
that may surprise C programmers.
# Reporting Security Issues
To report a security issue, please visit "[Reporting Security Issues](https://github.com/lcn2/calc/security/policy)".

View File

@@ -1,4 +1,16 @@
# Security Policy
# Reporting Security Issues
We take security bugs seriously. We appreciate your efforts to responsibly
disclose your findings, and will make every effort to acknowledge your
contributions for any verified security issues when they have been fixed.
To report a security issue, click on: "[Open a draft security advisory](https://github.com/lcn2/calc/security/advisories/new)"
We will send a response indicating the next steps in handling your
report. After the initial reply to your report, we will keep you informed
of the progress towards a fix and full announcement, and may ask for
additional information or guidance.
## Supported Versions
@@ -9,11 +21,3 @@ If the most recent stable of calc is also supported with security updates.
FYI: please review the BUGS file, or enter the calc command:
; help BUGS
## Reporting a Vulnerability
Please create a calc GitHub repo issue:
https://github.com/lcn2/calc/issues
Click on ((New issue)) and follow the issue template.

19
alloc.h
View File

@@ -1,7 +1,7 @@
/*
* alloc - storage allocation and storage debug macros
*
* Copyright (C) 1999-2007,2014 David I. Bell
* Copyright (C) 1999-2007,2014,2025 David I. Bell
*
* Calc is open software; you can redistribute it and/or modify it under
* the terms of the version 2.1 of the GNU Lesser General Public License
@@ -29,13 +29,15 @@
#if defined(CALC_SRC) /* if we are building from the calc source tree */
# include "decl.h"
# include "have_newstr.h"
# include "have_string.h"
# include "have_memmv.h"
# include "have_const.h"
#else
# include <calc/decl.h>
# include <calc/have_newstr.h>
# include <calc/have_string.h>
# include <calc/have_memmv.h>
# include <calc/have_const.h>
#endif
#ifdef HAVE_STRING_H
@@ -75,15 +77,4 @@ E_FUNC int strcmp();
#define strchr(s, c) index(s, c)
#endif /* HAVE_NEWSTR */
#if !defined(HAVE_MEMMOVE)
# undef MEMMOVE_SIZE_T
#if defined(FORCE_STDC) || \
(defined(__STDC__) && __STDC__ != 0) || defined(__cplusplus)
# define MEMMOVE_SIZE_T size_t
# else
# define MEMMOVE_SIZE_T long
# endif
E_FUNC void *memmove(void *s1, CONST void *s2, MEMMOVE_SIZE_T n);
#endif
#endif /* !INCLUDE_ALLOC_H */

View File

@@ -1,7 +1,7 @@
/*
* blkcpy - general values and related routines used by the calculator
*
* Copyright (C) 1999-2007,2021-2023 Landon Curt Noll and Ernest Bowen
* Copyright (C) 1999-2007,2021-2023,2025 Landon Curt Noll and Ernest Bowen
*
* Primary author: Landon Curt Noll
*
@@ -924,62 +924,6 @@ copyostr2blk(char *str,long ssi,long num,BLOCK *dblk,long dsi,bool noreloc)
dblk->datalen = newlen;
return 0;
}
#if !defined(HAVE_MEMMOVE)
/*
* memmove - simulate the memory move function that deals with overlap
*
* Copying between objects that overlap will take place correctly.
*
* given:
* s1 destination
* s2 source
* n octet count
*
* returns:
* s1
*/
void *
memmove(void *s1, CONST void *s2, MEMMOVE_SIZE_T n)
{
/*
* firewall
*/
if (s1 == NULL || s2 == NULL) {
math_error("bogus memmove NULL ptr");
not_reached();
}
if (n <= 0) {
/* neg or 0 count does nothing */
return s1;
}
if ((char *)s1 == (char *)s2) {
/* copy to same location does nothing */
return s1;
}
/*
* determine if we need to deal with overlap copy
*/
if ((char *)s1 > (char *)s2 && (char *)s1 < (char *)s2+n) {
/*
* we have to copy backwards ... slowly
*/
while (n-- > 0) {
((char *)s1)[n] = ((char *)s2)[n];
}
} else {
/*
* safe ... no overlap problems
*/
(void) memcpy(s1, s2, n);
}
return s1;
}
#endif
/*

View File

@@ -7916,7 +7916,7 @@ print '180: define g7500e(a,b) = *a = b'
*/
define test_ptr()
{
local a, b, c, A, B, B1, B2, M, L, p, q, p0, q0;
local a, b, c, A, B, B1, B2, M, L, p, q, r, p0, q0;
print '7500: Beginning test_ptr';
@@ -8042,22 +8042,21 @@ define test_ptr()
p = &M[0], *p = 5;
print '7587: p = &M[0], *p = 5;';
vrfy(M[0] == 5, '7588: M[0] == 5');
*++p = 6;
print '7589: *++p = 6;';
vrfy(M[1] == 6, '7590: M[1] == 6');
q = p++;
print '7591: q = p++;';
q = &M[1], *q = 6;
print '7589: q = &M[1], *q = 6;';
vrfy(M[1] == 6, '7588: M[1] == 6');
vrfy(M[0] == 5, '7588: M[0] == 5');
vrfy(q == &M[1], '7592: q == &M[1]');
vrfy(p == &M[2], '7593: p == &M[2]');
vrfy(p == &M[0], '7593: p == &M[0]');
quomod(17,5,*q,*p);
print '7594: quomod(17,5,*p,*q);';
vrfy(M[1] == 3 && M[2] == 2, '7595: M[1] == 3 && M[2] == 2');
vrfy(M[1] == 3 && M[0] == 2, '7595: M[1] == 3 && M[0] == 2');
swap(*p, *q);
print '7596: swap(*p, *q);';
vrfy(M[1] == 2 && M[2] == 3, '7597: M[1] == 2 && M[2] == 3');
vrfy(M[1] == 2 && M[0] == 3, '7597: M[1] == 2 && M[0] == 3');
A = *M = {7,8};
print '7598: A = *M = {7,8};';
vrfy(M == (mat[4] = {5,2,3,4}), '7599: M == (mat[4] = {5,2,3,4})');
vrfy(M == (mat[4] = {3,2,3,4}), '7599: M == (mat[4] = {3,2,3,4})');
vrfy(A == (mat[4] = {7,8,3,4}), '7600: A == (mat[4] = {7,8,3,4})');
/* Values which point to themselves */
@@ -8069,46 +8068,64 @@ define test_ptr()
print '7603: A = &B, B = &A;';
vrfy(**A == A && ***A == B, '7604: **A == A && ***A == B');
/* Testing functions that return pointers */
/* verify arithmetic value address operation restrictions */
M[3] = 7;
print '7605: M[3] = 7;';
vrfy(*g7500b(&M[1], 2) == 7, '7606: *g7500b(&M[1], 2) == 7');
*g7500b(&M[1], 2) = 8;
print '7607: *g7500b(&M[1], 2) = 8;';
vrfy(M[3] == 8, '7608: M[3] == 8');
M[3] = list(9,10);
print '7609: M[3] = list(9,10);';
vrfy((*g7500b(&M[1], 2))[[1]] == 10,
'7610: (*g7500b(&M[1], 2))[[1]] == 10');
M = mat[10] = {0,1,2,3,4,5,6,7,8,9};
print '7605: M = mat[10] = {0,1,2,3,4,5,6,7,8,9};';
/* NOTE: The next set of tests will trigger 10 errors by design */
ecnt += 10;
print '7606: ecnt += 10';
p = &M[3];
print '7607: p = &M[3]';
++p;
print '7608: ++p';
vrfy(p == error("E_INVALID_ADDR_OP"),
'7609: p == error("E_INVALID_ADDR_OP")');
p = &M[4];
print '7610: p = &M[4]';
p++;
print '7611: p++';
vrfy(p == error("E_INVALID_ADDR_OP"),
'7612: p == error("E_INVALID_ADDR_OP")');
p = &M[5];
print '7613: p = &M[5]';
q = &M[8];
print '7614: q = &M[8]';
vrfy(q+5 == error("E_INVALID_ADDR_OP"),
'7615: q+5 == error("E_INVALID_ADDR_OP")');
vrfy(q-7 == error("E_INVALID_ADDR_OP"),
'7616: q-7 == error("E_INVALID_ADDR_OP")');
vrfy(p+q == error("E_INVALID_ADDR_OP"),
'7617: p+q == error("E_INVALID_ADDR_OP")');
r = p-q;
print '7618: r = p-q;';
/* Testing number and string pointers */
a = 24, b = 4 * 6, c = 4!;
print '7611: a = 24, b = 4 * 6, c= 4!;';
vrfy(isptr(&*a) == 4, '7612: isptr(&*a) == 4');
vrfy(&*a == &24, '7613: &*a == &24');
vrfy(&*a == &*b, '7614: &*a == &*b');
vrfy(&*a != &*c, '7615: &*a != &*c');
print '7619: a = 24, b = 4 * 6, c= 4!;';
vrfy(isptr(&*a) == 4, '7620: isptr(&*a) == 4');
vrfy(&*a == &24, '7621: &*a == &24');
vrfy(&*a == &*b, '7622: &*a == &*b');
vrfy(&*a != &*c, '7623: &*a != &*c');
a = b = "abc", c = strcat("a", "bc");
print '7616: a = b = "abc", c = strcat("a", "bc");';
vrfy(isptr(&*a) == 3, '7617: isptr(&*a) == 3');
vrfy(&*a == &"abc", '7618: &*a == &"abc"');
vrfy(&*a == &*b, '7619: &*a == &*b');
vrfy(&*a != &*c, '7620: &*a != &*c');
print '7624: a = b = "abc", c = strcat("a", "bc");';
vrfy(isptr(&*a) == 3, '7625: isptr(&*a) == 3');
vrfy(&*a == &"abc", '7626: &*a == &"abc"');
vrfy(&*a == &*b, '7627: &*a == &*b');
vrfy(&*a != &*c, '7628: &*a != &*c');
a = c;
print '7621: a = c;';
vrfy(&*a == &*c, '7622: &*a == &*c');
print '7629: a = c;';
vrfy(&*a == &*c, '7630: &*a == &*c');
/* Verifying null-ness of freed numbers */
c = 4!, p = &*c, free(c);
print '7623: c = 4!, p = &*c, free(c)';
vrfy(isnull(*p), '7624: isnull(*p)');
print '7631: c = 4!, p = &*c, free(c)';
vrfy(isnull(*p), '7632: isnull(*p)');
print '7625: Ending test_ptr';
print '7633: Ending test_ptr';
}
print '181: parsed test_ptr()';
@@ -9165,8 +9182,8 @@ read -once "test8900.special";
print '8902: about to run test8900(1,,8903)';
testnum = test8900(1,,8903);
print "8941: ecnt ==", ecnt;
print '8942: ecnt = 214;'
ecnt = 214;
print '8942: ecnt = 224;'
ecnt = 224;
/*

View File

@@ -1,7 +1,7 @@
/*
* codegen - module to generate opcodes from the input tokens
*
* Copyright (C) 1999-2007,2017,2021-2023 David I. Bell and Ernest Bowen
* Copyright (C) 1999-2007,2017,2021-2023,2025 David I. Bell and Ernest Bowen
*
* Primary author: David I. Bell
*
@@ -2425,6 +2425,40 @@ getfilename(char *name, size_t namelen, bool *once)
}
/*
* Useful routine to return the index of one string within another one
* which has the format: "str1\000str2\000str3\000...strn\0\0". Index starts
* at one for the first string. Returns zero if the string being checked
* is not contained in the formatted string.
*
* Be sure to use \000 instead of \0. ANSI-C compilers interpret "foo\0foo..."
* as "foo\017oo...".
*
* given:
* format string formatted into substrings
* test string to be found in formatted string
*/
S_FUNC long
stringindex(char *format, char *test)
{
long index; /* found index */
size_t len; /* length of current piece of string */
size_t testlen; /* length of test string */
testlen = strlen(test);
index = 1;
while (*format) {
len = strlen(format);
if ((len == testlen) && (*format == *test) &&
(strcmp(format, test) == 0))
return index;
format += (len + 1);
index++;
}
return 0;
}
/*
* Read the show command to display useful information
*/

View File

@@ -2,7 +2,7 @@
#
# custom - makefile for calc custom routines
#
# Copyright (C) 1999-2006,2014,2017-2018,2021,2023 Landon Curt Noll
# Copyright (C) 1999-2006,2014,2017-2018,2021,2023,2025 Landon Curt Noll
#
# Suggestion: Read the ../HOWTO.INSTALL file.
#
@@ -728,7 +728,6 @@ c_argv.o: ../hash.h
c_argv.o: ../have_ban_pragma.h
c_argv.o: ../have_const.h
c_argv.o: ../have_limits.h
c_argv.o: ../have_memmv.h
c_argv.o: ../have_newstr.h
c_argv.o: ../have_stdbool.h
c_argv.o: ../have_stdlib.h
@@ -761,7 +760,6 @@ c_devnull.o: ../hash.h
c_devnull.o: ../have_ban_pragma.h
c_devnull.o: ../have_const.h
c_devnull.o: ../have_limits.h
c_devnull.o: ../have_memmv.h
c_devnull.o: ../have_newstr.h
c_devnull.o: ../have_stdbool.h
c_devnull.o: ../have_stdlib.h
@@ -795,7 +793,6 @@ c_help.o: ../hash.h
c_help.o: ../have_ban_pragma.h
c_help.o: ../have_const.h
c_help.o: ../have_limits.h
c_help.o: ../have_memmv.h
c_help.o: ../have_newstr.h
c_help.o: ../have_stdbool.h
c_help.o: ../have_stdlib.h
@@ -829,7 +826,6 @@ c_pmodm127.o: ../hash.h
c_pmodm127.o: ../have_ban_pragma.h
c_pmodm127.o: ../have_const.h
c_pmodm127.o: ../have_limits.h
c_pmodm127.o: ../have_memmv.h
c_pmodm127.o: ../have_newstr.h
c_pmodm127.o: ../have_stdbool.h
c_pmodm127.o: ../have_stdlib.h
@@ -862,7 +858,6 @@ c_pzasusb8.o: ../hash.h
c_pzasusb8.o: ../have_ban_pragma.h
c_pzasusb8.o: ../have_const.h
c_pzasusb8.o: ../have_limits.h
c_pzasusb8.o: ../have_memmv.h
c_pzasusb8.o: ../have_newstr.h
c_pzasusb8.o: ../have_stdbool.h
c_pzasusb8.o: ../have_stdlib.h
@@ -896,7 +891,6 @@ c_register.o: ../hash.h
c_register.o: ../have_ban_pragma.h
c_register.o: ../have_const.h
c_register.o: ../have_limits.h
c_register.o: ../have_memmv.h
c_register.o: ../have_newstr.h
c_register.o: ../have_stdbool.h
c_register.o: ../have_stdlib.h
@@ -932,7 +926,6 @@ c_sysinfo.o: ../hash.h
c_sysinfo.o: ../have_ban_pragma.h
c_sysinfo.o: ../have_const.h
c_sysinfo.o: ../have_limits.h
c_sysinfo.o: ../have_memmv.h
c_sysinfo.o: ../have_newstr.h
c_sysinfo.o: ../have_stdbool.h
c_sysinfo.o: ../have_stdlib.h
@@ -970,7 +963,6 @@ custtbl.o: ../hash.h
custtbl.o: ../have_ban_pragma.h
custtbl.o: ../have_const.h
custtbl.o: ../have_limits.h
custtbl.o: ../have_memmv.h
custtbl.o: ../have_newstr.h
custtbl.o: ../have_stdbool.h
custtbl.o: ../have_stdlib.h

View File

@@ -759,6 +759,8 @@ CONST struct errtbl error_table[] =
{ 10607, "E_LOG_5", "Cannot calculate log of 0" },
{ 10608, "E_LOG2_4", "Cannot calculate log base 2 of 0" },
{ 10609, "E_LOGN_6", "Cannot calculate log base n of 0" },
{ 10610, "E_INVALID_DEREF", "Dereferencing a non-variable" },
{ 10611, "E_INVALID_ADDR_OP", "Invalid arithmetic address operation" },
/* IMPORTANT NOTE: add new entries above here and be sure their errnum numeric value is consecutive! */
/* The next NULL entry must be last */

View File

@@ -1,7 +1,7 @@
/*
* fposval - Determine information about the file position type
*
* Copyright (C) 1999,2021,2023 Landon Curt Noll
* Copyright (C) 1999,2021,2023,2025 Landon Curt Noll
*
* Calc is open software; you can redistribute it and/or modify it under
* the terms of the version 2.1 of the GNU Lesser General Public License
@@ -71,7 +71,6 @@
#include "have_fpos_pos.h"
#include "alloc.h"
#include "have_unused.h"
#include "have_memmv.h"
#include "zmath.h"

View File

@@ -1,73 +0,0 @@
/*
* have_memmv - Determine if we have memmove()
*
* Copyright (C) 1999,2021 Landon Curt Noll
*
* Calc is open software; you can redistribute it and/or modify it under
* the terms of the version 2.1 of the GNU Lesser General Public License
* as published by the Free Software Foundation.
*
* Calc is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General
* Public License for more details.
*
* A copy of version 2.1 of the GNU Lesser General Public License is
* distributed with calc under the filename COPYING-LGPL. You should have
* received a copy with calc; if not, write to Free Software Foundation, Inc.
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* Under source code control: 1997/04/16 02:02:34
* File existed as early as: 1997
*
* chongo <was here> /\oo/\ http://www.isthe.com/chongo/
* Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/
*/
/*
* usage:
* have_memmv
*
* Not all systems with memcpy() have memmove() functions, so this may not
* compile on your system.
*
* This prog outputs several defines:
*
* HAVE_MEMMOVE
* defined ==> use memmove()
* undefined ==> use internal slow memmove() instead
*/
#include <stdio.h>
#include "have_string.h"
#ifdef HAVE_STRING_H
# include <string.h>
#endif
#include "banned.h" /* include after system header <> includes */
#define MOVELEN 3
char src[] = "chongo was here";
char dest[MOVELEN+1];
int
main(void)
{
#if defined(HAVE_NO_MEMMOVE)
printf("#undef HAVE_MEMMOVE /* no */\n");
#else /* HAVE_NO_MEMMOVE */
(void) memmove(dest, src, MOVELEN);
printf("#define HAVE_MEMMOVE /* yes */\n");
#endif /* HAVE_NO_MEMMOVE */
/* exit(0); */
return 0;
}

View File

@@ -113,7 +113,7 @@ DESCRIPTION
(the case of f(0) is exceptional since 27 + 0 simply copies the 27
rather than creating a new number value). Here it is clearly more
efficient to use
efficient to use:
; A = B = C = f(2);
@@ -125,11 +125,74 @@ DESCRIPTION
and number-pointer respectively, and 0 otherwise.
The output when addresses are printed consists of a description (o_ptr,
v_ptr, s_ptr, n_ptr) followed by : and the address printed in
%p format.
v_ptr, s_ptr, n_ptr) followed by : and the address printed in %p format.
Iteration of & is not permitted; &&X causes a "non-variable operand"
scan error.
Iteration of & is not permitted; &(&X) causes a "Addressing
non-addressable type" scan error.
RESTRICTIONS ON VALUE ADDRESS ARITHMETIC
Most arithmetic operations on addresses of values are not permitted.
For example one may not perform arithmetic operations (like +, ++,
-, --, *, /, etc.) on an address of a value with a numeric value.
The reason why most arithmetic operations were removed from calc
because arithmetic on addresses of calc objects could easily cause
calc to crash. Consider this horrific expression that was allowed
in calc prior to version 2.16.0.0:
; *((&.)+1e9) /* INVALID: for calc version >= 2.16.0.0 */
Prior to calc version 2.16.0.0, some arithmetic operations on
addresses of values were permitted. Starting with calc version
2.16.0.0, arithmetic operations between an addresses and an integer
will return an error code:
; ++p; /* INVALID: will be set to E_INVALID_ADDR_OP */
; r = q - 2; /* INVALID: will be set to E_INVALID_ADDR_OP */
Adding two value addresses is NOT permitted:
; mat A[3];
; p = &A[1];
; q = &A[2];
; s = p + q; /* INVALID: will be set to E_INVALID_ADDR_OP */
Subtracting two value addresses is permitted, however there is NO
guarantee that the address of a value will remain consistent across
calc runs. Addresses of values depend on the circumstances of when
the calc values were formed. For example:
; a = 3; pa = &a;
; /* ... stuff happens ... */
; b = 5; pb = &b;
; t = pa - pb; /* permitted: value depends on circumstances */
Subtracting value addresses of components with the same compound
object, such as a matrix, is permitted. For example:
; mat M[10] = {0,1,2,3,4,5,6,7,8,9};
; i = 4; j = 5;
; p = &M[i]; q = &M[j];
; v = p - q; /* permitted: value depends on circumstances */
Comparison between two value addresses is permitted, however the
same caveats apply as to the subtracting of addresses:
; if (p < q) {
;; print "permitted: p is less than q";
;; } else if (p == q) {
;; print "permitted: p is equal to q";
;; } else {
;; print "permitted: p is greater than q";
;; }
PLEASE NOTE:
The above restrictions and caveats apply to addresses of values.
Such restrictions and caveats to NOT apply to the addresses of
octets, NOR to the addresses within strings. If isptr(x) == 2,
then x is value-pointer and the above mentioned restrictions
and caveats apply it.
EXAMPLE
Addresses for particular systems may differ from those displayed here.
@@ -160,7 +223,7 @@ LINK LIBRARY
SEE ALSO
dereference, isptr
## Copyright (C) 1999-2006,2021 Landon Curt Noll
## Copyright (C) 1999-2006,2021,2025 Landon Curt Noll
##
## Calc is open software; you can redistribute it and/or modify it under
## the terms of the version 2.1 of the GNU Lesser General Public License

View File

@@ -1,5 +1,5 @@
NAME
log2 - base 10 logarithm
log2 - base 2 logarithm
SYNOPSIS
log2(x [,eps])

View File

@@ -959,8 +959,8 @@ o_deref(FUNC *UNUSED(fp))
return;
}
if (stack->v_type != V_ADDR) {
math_error("Dereferencing a non-variable");
not_reached();
*stack = error_value(E_INVALID_DEREF);
return;
}
vp = vp->v_addr;
switch (vp->v_type) {

98
str.c
View File

@@ -1,7 +1,7 @@
/*
* str - string list routines
*
* Copyright (C) 1999-2007,2021-2023 David I. Bell and Ernest Bowen
* Copyright (C) 1999-2007,2021-2023,2025 David I. Bell and Ernest Bowen
*
* Primary author: David I. Bell
*
@@ -42,7 +42,7 @@
#include "banned.h" /* include after system header <> includes */
#define STR_TABLECHUNK (1<<10) /* how often to reallocate string table */
#define STR_TABLECHUNK (1<<16) /* how often to reallocate string literal table */
#define STR_CHUNK (1<<16) /* size of string storage allocation */
#define OCTET_VALUES 256 /* number of different values in a OCTET */
#define STR_UNIQUE (1<<7) /* size of string to allocate separately */
@@ -97,6 +97,10 @@ initstr(STRINGHEAD *hp)
* given:
* hp header of string storage
* str string to be added
*
* returns:
* != NULL ==> pointer to newly added string
* NULL ==> unable to add string
*/
char *
addstr(STRINGHEAD *hp, char *str)
@@ -113,6 +117,10 @@ addstr(STRINGHEAD *hp, char *str)
/* alloc + 1 guard paranoia */
newsize = len + STR_CHUNK + hp->h_used + hp->h_avail + 1;
/* alloc + 1 guard paranoia */
/*
* XXX - doing a realloc can cause problems if the larger list has to be
* relocated due the recalloc() call and stuff point to old location
*/
list = (char *)realloc(hp->h_list, newsize + 1);
if (list == NULL)
return NULL;
@@ -130,35 +138,6 @@ addstr(STRINGHEAD *hp, char *str)
}
/*
* Return a null-terminated string which consists of a single character.
* The table is initialized on the first call.
*/
char *
charstr(int ch)
{
char *cp;
int i;
if (chartable == NULL) {
/* alloc + 1 guard paranoia */
cp = (char *)malloc((OCTET_VALUES + 1)*2);
if (cp == NULL) {
math_error("Cannot allocate character table");
not_reached();
}
for (i = 0; i < OCTET_VALUES; i++) {
*cp++ = (char)i;
*cp++ = '\0';
}
chartable = cp - (OCTET_VALUES*2);
*cp++ = '\0'; /* guard paranoia */
*cp++ = '\0'; /* guard paranoia */
}
return &chartable[(ch & 0xff) * 2];
}
/*
* Find a string with the specified name and return its number in the
* string list. The first string is numbered zero. Minus one is returned
@@ -166,7 +145,11 @@ charstr(int ch)
*
* given:
* hp header of string storage
* str string to be added
* str string to be searched for
*
* returns:
* >= 0 ==> index of string
* -1 ==> unable to find string
*/
int
findstr(STRINGHEAD *hp, char *str)
@@ -200,6 +183,10 @@ findstr(STRINGHEAD *hp, char *str)
* given:
* hp header of string storage
* n string index
*
* returns:
* non-empty string ==> string at index n
* "" ==> no strings or string at index n
*/
char *
namestr(STRINGHEAD *hp, long n)
@@ -219,36 +206,31 @@ namestr(STRINGHEAD *hp, long n)
/*
* Useful routine to return the index of one string within another one
* which has the format: "str1\000str2\000str3\000...strn\0\0". Index starts
* at one for the first string. Returns zero if the string being checked
* is not contained in the formatted string.
*
* Be sure to use \000 instead of \0. ANSI-C compilers interpret "foo\0foo..."
* as "foo\017oo...".
*
* given:
* format string formatted into substrings
* test string to be found in formatted string
* Return a null-terminated string which consists of a single character.
* The table is initialized on the first call.
*/
long
stringindex(char *format, char *test)
S_FUNC char *
charstr(int ch)
{
long index; /* found index */
size_t len; /* length of current piece of string */
size_t testlen; /* length of test string */
char *cp;
int i;
testlen = strlen(test);
index = 1;
while (*format) {
len = strlen(format);
if ((len == testlen) && (*format == *test) &&
(strcmp(format, test) == 0))
return index;
format += (len + 1);
index++;
if (chartable == NULL) {
/* alloc + 1 guard paranoia */
cp = (char *)malloc((OCTET_VALUES + 1)*2);
if (cp == NULL) {
math_error("Cannot allocate character table");
not_reached();
}
for (i = 0; i < OCTET_VALUES; i++) {
*cp++ = (char)i;
*cp++ = '\0';
}
chartable = cp - (OCTET_VALUES*2);
*cp++ = '\0'; /* guard paranoia */
*cp++ = '\0'; /* guard paranoia */
}
return 0;
return &chartable[(ch & 0xff) * 2];
}

4
str.h
View File

@@ -1,7 +1,7 @@
/*
* str - string list routines
*
* Copyright (C) 1999-2007,2014 David I. Bell
* Copyright (C) 1999-2007,2014,2025 David I. Bell
*
* Calc is open software; you can redistribute it and/or modify it under
* the terms of the version 2.1 of the GNU Lesser General Public License
@@ -59,9 +59,7 @@ E_FUNC void initstr(STRINGHEAD *hp);
E_FUNC char *addstr(STRINGHEAD *hp, char *str);
E_FUNC char *namestr(STRINGHEAD *hp, long n);
E_FUNC int findstr(STRINGHEAD *hp, char *str);
E_FUNC char *charstr(int ch);
E_FUNC char *addliteral(char *str);
E_FUNC long stringindex(char *str1, char *str2);
E_FUNC STRING *stralloc(void);
E_FUNC long addstring(char *str, size_t len);
E_FUNC STRING *charstring(int ch);

23
value.c
View File

@@ -434,6 +434,8 @@ addvalue(VALUE *v1, VALUE *v2, VALUE *vres)
*vres = error_value(E_STRADD);
return;
case TWOVAL(V_VPTR, V_NUM):
#if defined(PERMIT_DANGEROUS_ADDRESS_ARITHMETIC)
/* NOTE: Defining PERMIT_DANGEROUS_ADDRESS_ARITHMETIC is NOT supported! */
q = v2->v_num;
if (qisfrac(q)) {
math_error("Adding non-integer to address");
@@ -442,6 +444,12 @@ addvalue(VALUE *v1, VALUE *v2, VALUE *vres)
i = qtoi(q);
vres->v_addr = v1->v_addr + i;
vres->v_type = V_VPTR;
#else /* Disable arithmetic on addresses */
*vres = error_value(E_INVALID_ADDR_OP);
#endif /* Disable arithmetic on addresses */
return;
case TWOVAL(V_VPTR, V_VPTR):
*vres = error_value(E_INVALID_ADDR_OP);
return;
case TWOVAL(V_OPTR, V_NUM):
q = v2->v_num;
@@ -515,6 +523,8 @@ subvalue(VALUE *v1, VALUE *v2, VALUE *vres)
*vres = error_value(E_STRSUB);
return;
case TWOVAL(V_VPTR, V_NUM):
#if defined(PERMIT_DANGEROUS_ADDRESS_ARITHMETIC)
/* NOTE: Defining PERMIT_DANGEROUS_ADDRESS_ARITHMETIC is NOT supported! */
q = v2->v_num;
if (qisfrac(q)) {
math_error("Subtracting non-integer from address");
@@ -523,6 +533,9 @@ subvalue(VALUE *v1, VALUE *v2, VALUE *vres)
i = qtoi(q);
vres->v_addr = v1->v_addr - i;
vres->v_type = V_VPTR;
#else /* Disable arithmetic on addresses */
*vres = error_value(E_INVALID_ADDR_OP);
#endif /* Disable arithmetic on addresses */
return;
case TWOVAL(V_OPTR, V_NUM):
q = v2->v_num;
@@ -1407,7 +1420,12 @@ incvalue(VALUE *vp, VALUE *vres)
vres->v_octet = vp->v_octet + 1;
break;
case V_VPTR:
#if defined(PERMIT_DANGEROUS_ADDRESS_ARITHMETIC)
/* NOTE: Defining PERMIT_DANGEROUS_ADDRESS_ARITHMETIC is NOT supported! */
vres->v_addr = vp->v_addr + 1;
#else /* Disable arithmetic on addresses */
*vres = error_value(E_INVALID_ADDR_OP);
#endif /* Disable arithmetic on addresses */
break;
default:
if (vp->v_type > 0)
@@ -1443,7 +1461,12 @@ decvalue(VALUE *vp, VALUE *vres)
vres->v_octet = vp->v_octet - 1;
break;
case V_VPTR:
#if defined(PERMIT_DANGEROUS_ADDRESS_ARITHMETIC)
/* NOTE: Defining PERMIT_DANGEROUS_ADDRESS_ARITHMETIC is NOT supported! */
vres->v_addr = vp->v_addr - 1;
#else /* Disable arithmetic on addresses */
*vres = error_value(E_INVALID_ADDR_OP);
#endif /* Disable arithmetic on addresses */
break;
default:
if (vp->v_type >= 0)

View File

@@ -1,7 +1,7 @@
/*
* version - determine the version of calc
*
* Copyright (C) 2023 David I. Bell and Landon Curt Noll
* Copyright (C) 1989-2025 David I. Bell and Landon Curt Noll
*
* Calc is open software; you can redistribute it and/or modify it under
* the terms of the version 2.1 of the GNU Lesser General Public License
@@ -62,9 +62,22 @@
* bug fix and improvement updates will cause MINOR_PATCH to increment.
*/
#define MAJOR_VER 2 /* level 1: major library version */
#define MINOR_VER 15 /* level 2: minor library version */
#define MAJOR_PATCH 1 /* level 3: major software version level */
#define MINOR_VER 16 /* level 2: minor library version */
#define MAJOR_PATCH 0 /* level 3: major software version level */
#define MINOR_PATCH 0 /* level 4: minor software version level */
/*
* Defining PERMIT_DANGEROUS_ADDRESS_ARITHMETIC is NOT supported!
*
* If someone were to be a foolish as to permit dangerous address arithmetic, then we
* negate the major version to further "disavow" such a calc compile.
*/
#if defined(PERMIT_DANGEROUS_ADDRESS_ARITHMETIC)
# undef TEMP_MAJOR_VER
# define TEMP_MAJOR_VER MAJOR_VER
# undef MAJOR_VER
# define MAJOR_VER (-TEMP_MAJOR_VER)
# undef TEMP_MAJOR_VER
#endif
#endif /* !INCLUDE_VERSION_H*/