Release v2.12.9.0

Added notes to help/unexpected about:

    display() will limit the number of digits printed after decimal point

    %d will format after the decimal point for non-integer numeric values

    %x will format as fractions for non-integer numeric values

    fprintf(fd, "%d\n", huge_value) may need fflush(fd) to finish

Fixed Makefile dependencies for the args.h rule.

Fixed Makefile cases where echo with -n is used.  On some systems,
/bin/sh does not use -n, so we must call /bin/echo -n instead
via the ${ECHON} Makefile variable.

Add missing standard tools to sub-Makefiles to make them
easier to invoke directly.

Sort lists of standard tool Makefile variables and remove duplicates.

Declare the SHELL at the top of Makefiles.

Fixed the depend rule in the custom Makefile.

Improved the messages produced by the depend in the Makefiles.

Changed the UNUSED define in have_unused.h to be a macro with
a parameter.  Changed all use of UNUSED in *.c to be UNUSED(x).

Removed need for HAVE_UNUSED in building the have_unused.h file.

 CCBAN is given to ${CC} in order to control if banned.h is in effect.

 The banned.h attempts to ban the use of certain dangerous functions
 that, if improperly used, could compromise the computational integrity
 if calculations.

 In the case of calc, we are motivated in part by the desire for calc
 to correctly calculate: even during extremely long calculations.

 If UNBAN is NOT defined, then calling certain functions
 will result in a call to a non-existent function (link error).

 While we do NOT encourage defining UNBAN, there may be
 a system / compiler environment where re-defining a
 function may lead to a fatal compiler complication.
 If that happens, consider compiling as:

    make clobber all chk CCBAN=-DUNBAN

 as see if this is a work-a-round.

 If YOU discover a need for the -DUNBAN work-a-round, PLEASE tell us!
 Please send us a bug report.  See the file:

    BUGS

 or the URL:

    http://www.isthe.com/chongo/tech/comp/calc/calc-bugrept.html

 for how to send us such a bug report.

 Added the building of have_ban_pragma.h, which will determine
 if "#pragma GCC poison func_name" is supported.  If it is not,
 or of HAVE_PRAGMA_GCC_POSION=-DHAVE_NO_PRAGMA_GCC_POSION, then
 banned.h will have no effect.

 Fixed building of the have_getpgid.h file.
 Fixed building of the have_getprid.h file.
 Fixed building of the have_getsid.h file.
 Fixed building of the have_gettime.h file.
 Fixed building of the have_strdup.h file.
 Fixed building of the have_ustat.h file.
 Fixed building of the have_rusage.h file.

 Added HAVE_NO_STRLCPY to control if we want to test if
 the system has a strlcpy() function.  This in turn produces
 the have_strlcpy.h file wherein the symbol HAVE_STRLCPY will
 be defined, or not depending if the system comes with a
 strlcpy() function.

 If the system does not have a strlcpy() function, we
 compile our own strlcpy() function.  See strl.c for details.

 Added HAVE_NO_STRLCAT to control if we want to test if
 the system has a strlcat() function.  This in turn produces
 the have_strlcat.h file wherein the symbol HAVE_STRLCAT will
 be defined, or not depending if the system comes with a
 strlcat() function.

 If the system does not have a strlcat() function, we
 compile our own strlcat() function.  See strl.c for details.

 Fixed places were <string.h>, using #ifdef HAVE_STRING_H
 for legacy systems that do not have that include file.

 Added ${H} Makefile symbol to control the announcement
 of forming and having formed hsrc related files.  By default
 H=@ (announce hsrc file formation) vs. H=@: to silence hsrc
 related file formation.

 Explicitly turn off quiet mode (set Makefile variable ${Q} to
 be empty) when building rpms.

 Improved and fixed the hsrc build process.

 Forming rpms is performed in verbose mode to assist debugging
 to the rpm build process.

 Compile custom code, if needed, after main code is compiled.
This commit is contained in:
Landon Curt Noll
2021-03-10 03:14:29 -08:00
parent 9b4580d861
commit ac0d84eef8
109 changed files with 3147 additions and 1221 deletions

4
.gitignore vendored
View File

@@ -33,6 +33,7 @@ custom/libcustcalc*
endian
endian_calc.h
fposval.h
have_ban_pragma.h
have_const.h
have_fpos.h
have_fpos_pos.h
@@ -49,6 +50,8 @@ have_stdlib.h
have_stdvs
have_strdup.h
have_string.h
have_strlcat.h
have_strlcpy.h
have_times.h
have_uid_t.h
have_unistd.h
@@ -88,6 +91,7 @@ longbits
longbits.h
sample_many
sample_rand
tags
terminal.h
ver_calc

2
BUGS
View File

@@ -116,8 +116,6 @@ of a context diff patch).
Known bugs in calc:
Under macOS, runtime(), systime(), and usertime() only return 0.
Under macOS, the installation of the calc man page fails.
The output of the alg_config.cal resource file is bogus.

120
CHANGES
View File

@@ -1,16 +1,4 @@
The following are the changes from calc version 2.12.8.1 to date:
Fixed how the *.tar.bz2 are formed. The calc-2.12.8.0.tar.bz2 file
that was formed for calc version 2.12.8.0 was missing most files.
Expanded 'make chk' to also verify that 'make distchk' and 'make
distlist' execute successfully. This will help check a regression
of the bug that produced the bogus calc-2.12.8.0.tar.bz2 file.
Added additional regression tests related 0^(zero_expression)==1.
Calc can now correctly compile without CUSTOM being defined,
thanks to a report by <GitHub user barsnick>.
The following are the changes from calc version 2.12.9.0 to date:
Added notes to help/unexpected about:
@@ -22,7 +10,7 @@ The following are the changes from calc version 2.12.8.1 to date:
fprintf(fd, "%d\n", huge_value) may need fflush(fd) to finish
Fixed Makefile dependenies for the args.h rule.
Fixed Makefile dependencies for the args.h rule.
Fixed Makefile cases where echo with -n is used. On some systems,
/bin/sh does not use -n, so we must call /bin/echo -n instead
@@ -37,6 +25,110 @@ The following are the changes from calc version 2.12.8.1 to date:
Fixed the depend rule in the custom Makefile.
Improved the messages produced by the depend in the Makefiles.
Changed the UNUSED define in have_unused.h to be a macro with
a parameter. Changed all use of UNUSED in *.c to be UNUSED(x).
Removed need for HAVE_UNUSED in building the have_unused.h file.
CCBAN is given to ${CC} in order to control if banned.h is in effect.
The banned.h attempts to ban the use of certain dangerous functions
that, if improperly used, could compromise the computational integrity
if calculations.
In the case of calc, we are motivated in part by the desire for calc
to correctly calculate: even during extremely long calculations.
If UNBAN is NOT defined, then calling certain functions
will result in a call to a non-existent function (link error).
While we do NOT encourage defining UNBAN, there may be
a system / compiler environment where re-defining a
function may lead to a fatal compiler complication.
If that happens, consider compiling as:
make clobber all chk CCBAN=-DUNBAN
as see if this is a work-a-round.
If YOU discover a need for the -DUNBAN work-a-round, PLEASE tell us!
Please send us a bug report. See the file:
BUGS
or the URL:
http://www.isthe.com/chongo/tech/comp/calc/calc-bugrept.html
for how to send us such a bug report.
Added the building of have_ban_pragma.h, which will determine
if "#pragma GCC poison func_name" is supported. If it is not,
or of HAVE_PRAGMA_GCC_POSION=-DHAVE_NO_PRAGMA_GCC_POSION, then
banned.h will have no effect.
Fixed building of the have_getpgid.h file.
Fixed building of the have_getprid.h file.
Fixed building of the have_getsid.h file.
Fixed building of the have_gettime.h file.
Fixed building of the have_strdup.h file.
Fixed building of the have_ustat.h file.
Fixed building of the have_rusage.h file.
Added HAVE_NO_STRLCPY to control if we want to test if
the system has a strlcpy() function. This in turn produces
the have_strlcpy.h file wherein the symbol HAVE_STRLCPY will
be defined, or not depending if the system comes with a
strlcpy() function.
If the system does not have a strlcpy() function, we
compile our own strlcpy() function. See strl.c for details.
Added HAVE_NO_STRLCAT to control if we want to test if
the system has a strlcat() function. This in turn produces
the have_strlcat.h file wherein the symbol HAVE_STRLCAT will
be defined, or not depending if the system comes with a
strlcat() function.
If the system does not have a strlcat() function, we
compile our own strlcat() function. See strl.c for details.
Fixed places were <string.h>, using #ifdef HAVE_STRING_H
for legacy systems that do not have that include file.
Added ${H} Makefile symbol to control the announcement
of forming and having formed hsrc related files. By default
H=@ (announce hsrc file formation) vs. H=@: to silence hsrc
related file formation.
Explicitly turn off quiet mode (set Makefile variable ${Q} to
be empty) when building rpms.
Improved and fixed the hsrc build process.
Forming rpms is performed in verbose mode to assist debugging
to the rpm build process.
Compile custom code, if needed, after main code is compiled.
The following are the changes from calc version 2.12.8.1 to 2.12.8.2:
Fixed how the *.tar.bz2 are formed. The calc-2.12.8.0.tar.bz2 file
that was formed for calc version 2.12.8.0 was missing most files.
Expanded 'make chk' to also verify that 'make distchk' and 'make
distlist' execute successfully. This will help check a regression
of the bug that produced the bogus calc-2.12.8.0.tar.bz2 file.
Added additional regression tests related 0^(zero_expression)==1.
Calc can now correctly compile without CUSTOM being defined,
thanks to a report by <GitHub user barsnick>.
The following are the changes from calc version 2.12.7.5 to 2.12.8.0:

145
Makefile
View File

@@ -54,9 +54,63 @@
# Makefile by Landon Curt Noll
# our shell
# The shell used by this Makefile
#
SHELL= /bin/zsh
# On some systems, /bin/sh is a rather reduced shell with
# deprecated behavor.
#
# If your system has a up to date, bash shell, then
# you may wish to use:
#
# SHELL= /bin/bash
#
# On some systems such as macOS, the bash shell is very
# far behind to the point wehre is cannot be depended on.
# On such systems, the zsh may be a much better alternative
# shell for this Makefile to use:
#
# SHELL= /bin/zsh
#
#SHELL= /bin/sh
SHELL= /bin/bash
#SHELL= /bin/zsh
# CCBAN is given to ${CC} in order to control if banned.h is in effect.
#
# The banned.h attempts to ban the use of certain dangerous functions
# that, if improperly used, could compromise the computational integrity
# if calculations.
#
# In the case of calc, we are motivated in part by the desire for calc
# to correctly calculate: even durings extremely long calculations.
#
# If UNBAN is NOT defined, then calling certain functions
# will result in a call to a non-existent function (link error).
#
# While we do NOT encourage defining UNBAN, there may be
# a system / compiler environment where re-defining a
# function may lead to a fatal compiler complication.
# If that happens, consider compiling as:
#
# make clobber all chk CCBAN=-DUNBAN
#
# as see if this is a work-a-round.
#
# If YOU discover a need for the -DUNBAN work-a-round, PLEASE tell us!
# Please send us a bug report. See the file:
#
# BUGS
#
# or the URL:
#
# http://www.isthe.com/chongo/tech/comp/calc/calc-bugrept.html
#
# for how to send us such a bug report.
#
CCBAN= -UUNBAN
#CCBAN= -DUNBAN
# Try uname -s if the target was not already set on the make command line
#
@@ -164,11 +218,30 @@ CI= ci
# Q=@ do not echo internal Makefile actions (quiet mode)
# Q= echo internal Makefile actions (debug / verbose mode)
#
# H=@: do not report hsrc file formation progress
# H=@ do echo hsrc file formation progress
#
# S= >/dev/null 2>&1 slience ${CC} output during hsrc file formation
# S= full ${CC} output during hsrc file formation
#
# E= 2>/dev/null slience command stderr during hsrc file formation
# E= full command stderr during hsrc file formation
#
# V=@: do not echo debug statements (quiet mode)
# V=@ do echo debug statements (debug / verbose mode)
#
#Q=
Q=@
#
S= >/dev/null 2>&1
#S=
#
E= 2>/dev/null
#E=
#
#H=@:
H=@
#
V=@:
#V=@
@@ -184,20 +257,24 @@ XARG=
# that invokes the ${MAKE_FILE}.
#
XVAR= \
target=${target} \
USE_READLINE='${USE_READLINE}' \
READLINE_LIB='${READLINE_LIB}' \
READLINE_INCLUDE='${READLINE_INCLUDE}' \
RPM_TOP='${RPM_TOP}' \
MAKE_FILE='${MAKE_FILE}' \
EXT='${EXT}' \
DARWIN_ARCH='${DARWIN_ARCH}' \
CCBAN='${CCBAN}' \
CCWERR='${CCWERR}' \
NROFF='${NROFF}' \
COMMON_ADD='${COMMON_ADD}' \
DARWIN_ARCH='${DARWIN_ARCH}' \
E='${E}' \
EXT='${EXT}' \
H='${H}' \
MAKE_FILE='${MAKE_FILE}' \
MANDIR='${MANDIR}' \
NROFF='${NROFF}' \
Q='${Q}' \
V='${V}'
READLINE_INCLUDE='${READLINE_INCLUDE}' \
READLINE_LIB='${READLINE_LIB}' \
RPM_TOP='${RPM_TOP}' \
S='${S}' \
USE_READLINE='${USE_READLINE}' \
V='${V}' \
target=${target}
# We update the calc version string in these makefiles
#
@@ -213,7 +290,7 @@ XMKVER= ${MAKE_FILE} custom/Makefile.head
#
###
all: fix_version check_include
all: fix_version
${V} echo '=-=-=-=-= private Makefile $@ rule start =-=-=-=-='
${Q} ${MAKE} ${XARG} -f ${MAKE_FILE} $@ ${XVAR}
${V} echo '=-=-=-=-= private Makefile $@ rule end =-=-=-=-='
@@ -508,6 +585,20 @@ have_unused.h:
${Q} ${MAKE} ${XARG} -f ${MAKE_FILE} $@ ${XVAR}
${V} echo '=-=-=-=-= private Makefile $@ rule end =-=-=-=-='
have_ban_pragma.h:
${V} echo '=-=-=-=-= private Makefile $@ rule start =-=-=-=-='
${Q} ${MAKE} ${XARG} -f ${MAKE_FILE} $@ ${XVAR}
${V} echo '=-=-=-=-= private Makefile $@ rule end =-=-=-=-='
have_strlcpy.h:
${V} echo '=-=-=-=-= private Makefile $@ rule start =-=-=-=-='
${Q} ${MAKE} ${XARG} -f ${MAKE_FILE} $@ ${XVAR}
${V} echo '=-=-=-=-= private Makefile $@ rule end =-=-=-=-='
have_strlcat.h:
${V} echo '=-=-=-=-= private Makefile $@ rule start =-=-=-=-='
${Q} ${MAKE} ${XARG} -f ${MAKE_FILE} $@ ${XVAR}
${V} echo '=-=-=-=-= private Makefile $@ rule end =-=-=-=-='
##
#
@@ -523,34 +614,6 @@ win32_hsrc:
${Q} ${MAKE} ${XARG} -f ${MAKE_FILE} $@ ${XVAR}
${V} echo '=-=-=-=-= private Makefile $@ rule end =-=-=-=-='
##
#
# These rules are used in the process of building the BUILD_H_SRC.
#
##
endian.o:
${V} echo '=-=-=-=-= private Makefile $@ rule start =-=-=-=-='
${Q} ${MAKE} ${XARG} -f ${MAKE_FILE} $@ ${XVAR}
${V} echo '=-=-=-=-= private Makefile $@ rule end =-=-=-=-='
endian${EXT}:
${V} echo '=-=-=-=-= private Makefile $@ rule start =-=-=-=-='
${Q} ${MAKE} ${XARG} -f ${MAKE_FILE} $@ ${XVAR}
${V} echo '=-=-=-=-= private Makefile $@ rule end =-=-=-=-='
longbits.o:
${V} echo '=-=-=-=-= private Makefile $@ rule start =-=-=-=-='
${Q} ${MAKE} ${XARG} -f ${MAKE_FILE} $@ ${XVAR}
${V} echo '=-=-=-=-= private Makefile $@ rule end =-=-=-=-='
longbits${EXT}:
${V} echo '=-=-=-=-= private Makefile $@ rule start =-=-=-=-='
${Q} ${MAKE} ${XARG} -f ${MAKE_FILE} $@ ${XVAR}
${V} echo '=-=-=-=-= private Makefile $@ rule end =-=-=-=-='
##
#
# These two .all rules are used to determine of the lower level

File diff suppressed because it is too large Load Diff

View File

@@ -1,7 +1,7 @@
/*
* addop - add opcodes to a function being compiled
*
* Copyright (C) 1999-2007 David I. Bell and Ernest Bowen
* Copyright (C) 1999-2007,2021 David I. Bell and Ernest Bowen
*
* Primary author: David I. Bell
*
@@ -28,6 +28,7 @@
#include <stdio.h>
#include "calc.h"
#include "alloc.h"
#include "opcodes.h"
#include "str.h"
#include "func.h"
@@ -36,6 +37,9 @@
#include "symbol.h"
#include "banned.h" /* include after system header <> includes */
#define FUNCALLOCSIZE 20 /* reallocate size for functions */
#define OPCODEALLOCSIZE 100 /* reallocate size for opcodes in functions */

View File

@@ -1,7 +1,7 @@
/*
* align32 - determine if 32 bit accesses must be aligned
*
* Copyright (C) 1999 Landon Curt Noll
* 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
@@ -34,6 +34,10 @@
#include <unistd.h>
#endif
#include "banned.h" /* include after system header <> includes */
static void buserr(void); /* catch alignment errors */

View File

@@ -1,7 +1,7 @@
/*
* assocfunc - association table routines
*
* Copyright (C) 1999-2007 David I. Bell
* Copyright (C) 1999-2007,2021 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
@@ -36,6 +36,9 @@
#include "value.h"
#include "banned.h" /* include after system header <> includes */
#define MINHASHSIZE 31 /* minimum size of hash tables */
#define GROWHASHSIZE 50 /* approximate growth for hash tables */
#define CHAINLENGTH 10 /* desired number of elements on a hash chain */

174
banned.h
View File

@@ -1,7 +1,46 @@
/*
* banned - indicate which functions are banned in calc source
* banned - optionally ban dqngerious functions
*
* inspired by https://github.com/git/git/blob/master/banned.h
* Unless UNBAN is defined, this file will turn the use
* of certain dangerous functions into syntax errors.
*
* In the case of calc, we are motivated in part by the desire for
* calc to correctly calculate: even durings extremely long calculations.
*
* If UNBAN is NOT defined, then calling certain functions
* will result in a syntaxc error.
*
* If we define UNBAN, then the effect of this file is disabled.
*
* The banned.h attempts to ban the use of certain dangerous functions
* that, if improperly used, could compromise the computational integrity
* if calculations.
*
* In the case of calc, we are motivated in part by the desire for calc
* to correctly calculate: even durings extremely long calculations.
*
* If UNBAN is NOT defined, then calling certain functions
* will result in a call to a non-existent function (link error).
*
* While we do NOT encourage defining UNBAN, there may be
* a system / compiler environment where re-defining a
* function may lead to a fatal compiler complication.
* If that happens, consider compiling as:
*
* make clobber all chk CCBAN=-DUNBAN
*
* as see if this is a work-a-round.
*
* If YOU discover a need for the -DUNBAN work-a-round, PLEASE tell us!
* Please send us a bug report. See the file:
*
* BUGS
*
* or the URL:
*
* http://www.isthe.com/chongo/tech/comp/calc/calc-bugrept.html
*
* for how to send us such a bug report.
*
* Copyright (C) 2021 Landon Curt Noll
*
@@ -27,56 +66,115 @@
*/
#if !defined(PRE_HAVE_BAN_PRAGMA_H)
#include "have_ban_pragma.h"
#endif /* ! PRE_HAVE_BAN_PRAGMA_H */
#if !defined(INCLUDE_BANNED_H)
#define INCLUDE_BANNED_H
#include "have_stdlib.h"
#ifdef HAVE_STDLIB_H
# include <stdlib.h>
#endif
/*
* If we define UNBAN, then the effect of this file is disabled.
*/
#if !defined(UNBAN)
/*
* From: //github.com/git/git/blob/master/banned.h
* In the spirit of:
*
* This header lists functions that have been banned from our code base,
* because they're too easy to misuse (and even if used correctly,
* complicate audits). Including this header turns them into compile-time
* errors.
* https://github.com/git/git/blob/master/banned.h
*
* we will ban the use of certain unsafe functions by turning
* then into function calls that do not exist.
*
* In the case of calc, we are motivated in part by the desire
* for calc to correctly calculate: even durings extremely long
* calculations.
*
* If UNBAN is NOT defined, then calling certain functions
* will result in a syntaxc error.
*
* Unlike the above URL, we suggest an alternative function.
* In many cases, additional logic is required to use the
* alternative function, we cannot simply replace one function
* with another.
*/
#define BANNED(func,better) sorry_##func##_is_a_banned_function_use_##better##_instead
/*
* If one is not careful, strcpy() can lead to buffer overflows.
* Use strlcpy() instead.
*/
#if defined(HAVE_PRAGMA_GCC_POSION)
#undef strcpy
#define strcpy(x,y) BANNED(strcpy,strlcpy)
#pragma GCC poison strcpy
#endif /* HAVE_PRAGMA_GCC_POSION */
/*
* If one is not careful, strcat() can lead to buffer overflows.
* Use strlcat() instead.
*/
#if defined(HAVE_PRAGMA_GCC_POSION)
#undef strcat
#define strcat(x,y) BANNED(strcat,strlcat)
#pragma GCC poison strcat
#endif /* HAVE_PRAGMA_GCC_POSION */
/*
* If one is not careful, strncpy() can lead to buffer overflows.
* Use memccpy() instead.
*/
#if defined(HAVE_PRAGMA_GCC_POSION)
#undef strncpy
#define strncpy(x,y,n) BANNED(strncpy,memccpy)
#pragma GCC poison strncpy
#endif /* HAVE_PRAGMA_GCC_POSION */
/*
* If one is not careful, strncat() can lead to buffer overflows.
* Use memccpy() instead.
*/
#if defined(HAVE_PRAGMA_GCC_POSION)
#undef strncat
#define strncat(x,y,n) BANNED(strncat,memccpy)
#pragma GCC poison strncat
#endif /* HAVE_PRAGMA_GCC_POSION */
#if defined(STDARG)
#define sprintf(...) BANNED(sprintf,snprintf)
#define vsprintf(...) BANNED(vsprintf,vsnprintf)
#else /* STDARG */
#define sprintf(buf,fmt,arg) BANNED(sprintf,snprintf)
#define vsprintf(buf,fmt,arg) BANNED(vsprintf,vsnprintf)
#endif /* STDARG */
/*
* If one is not careful, sprintf() can lead to buffer overflows.
* Use snprintf() instead.
*/
#if defined(HAVE_PRAGMA_GCC_POSION)
#undef sprintf
#pragma GCC poison sprintf
#endif /* HAVE_PRAGMA_GCC_POSION */
#if 0 /* the XYtimeZZY_s() c11 functions are not yet universal - so do not ban XYtimeZZY() just yet - XXX */
#undef gmtime
#define gmtime(t) BANNED(gmtime,gmtime_s)
#undef localtime
#define localtime(t) BANNED(localtime,localtime_s)
#undef ctime
#define ctime(t) BANNED(ctime,ctime_s)
#undef ctime_r
#define ctime_r(t, buf) BANNED(ctime_r,ctime_s)
#undef asctime
#define asctime(t) BANNED(asctime,asctime_s)
#undef asctime_r
#define asctime_r(t, buf) BANNED(asctime_r,asctime_s)
#endif /* XXX */
/*
* If one is not careful, vsprintf() can lead to buffer overflows.
* Use vsnprintf() instead.
*/
#if defined(HAVE_PRAGMA_GCC_POSION)
#undef vsprintf
#pragma GCC poison vsprintf
#endif /* HAVE_PRAGMA_GCC_POSION */
/*
* XXX - As of 2021, functions such as:
*
* gmtime_s
* localtime_s
* ctime_s
* asctime_s
*
* are not universal. We cannot yet ban the following
* functions because we do not have a portable AND
* widely available alternative. Therefore we just
* have to be extra careful when using:
*
* gmtime
* localtime
* ctime
* ctime_r
* asctime
* asctime_r
*/
#endif /* !UNBAN */
#endif /* !INCLUDE_BANNED_H */

View File

@@ -29,12 +29,16 @@
#include <stdio.h>
#include <sys/types.h>
#include "calc.h"
#include "alloc.h"
#include "value.h"
#include "file.h"
#include "blkcpy.h"
#include "str.h"
#include "banned.h" /* include after system header <> includes */
/*
* copystod - copy num indexed items from source value to destination value
*

View File

@@ -28,6 +28,11 @@
#include <stdio.h>
#include "have_string.h"
#ifdef HAVE_STRING_H
# include <string.h>
#endif
#include "alloc.h"
#include "value.h"
#include "zmath.h"
#include "config.h"
@@ -36,6 +41,10 @@
#include "str.h"
#include "calcerr.h"
#include "banned.h" /* include after system header <> includes */
#define NBLOCKCHUNK 16
STATIC long nblockcount = 0;

View File

@@ -29,6 +29,9 @@
#include "byteswap.h"
#include "banned.h" /* include after system header <> includes */
/*
* swap_b8_in_HALFs - swap 8 and if needed, 16 bits in an array of HALFs
*

View File

@@ -28,9 +28,27 @@
# Makefile by Landon Curt Noll
# our shell
# The shell used by this Makefile
#
# On some systems, /bin/sh is a rather reduced shell with
# deprecated behavor.
#
# If your system has a up to date, bash shell, then
# you may wish to use:
#
# SHELL= /bin/bash
#
# On some systems such as macOS, the bash shell is very
# far behind to the point wehre is cannot be depended on.
# On such systems, the zsh may be a much better alternative
# shell for this Makefile to use:
#
# SHELL= /bin/zsh
#
SHELL= /bin/sh
#SHELL= /bin/bash
#SHELL= /bin/zsh
####
# Normally, the upper level makefile will set these values. We provide

46
calc.c
View File

@@ -26,7 +26,6 @@
* Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/
*/
#include <stdio.h>
#include <signal.h>
@@ -66,6 +65,7 @@
#include "lib_calc.h"
#include "args.h"
#include "zmath.h"
#include "strl.h"
#include "have_unistd.h"
#if defined(HAVE_UNISTD_H)
@@ -85,6 +85,9 @@
#include "have_unused.h"
#include "banned.h" /* include after system header <> includes */
/*
* S_FUNC definitions and functions
*/
@@ -373,14 +376,20 @@ main(int argc, char **argv)
havearg = TRUE;
if (cmdlen > 0)
cmdbuf[cmdlen++] = ' ';
strcpy(cmdbuf + cmdlen, "read ");
cmdlen += 5;
if (strncmp(cp, "-once", 5) == 0 &&
(cp[5] == '\0' || cp[5] == ' ')) {
cp += 5;
strlcpy(cmdbuf + cmdlen, "read ",
sizeof("read "));
cmdlen += sizeof("read ")-1;
cmdbuf[cmdlen] = '\0';
if (strncmp(cp, "-once",
sizeof("-once")) == 0 &&
(cp[sizeof("-once")-1] == '\0' ||
cp[sizeof("-once")-1] == ' ')) {
cp += sizeof("-once")-1;
haveendstr = (*cp == '\0');
strcpy(cmdbuf+cmdlen, "-once ");
cmdlen += 6;
strlcpy(cmdbuf+cmdlen, "-once ",
sizeof("-once "));
cmdlen += sizeof("-once ")-1;
cmdbuf[cmdlen] = '\0';
if (nextcp(&cp, &index, argc,
argv, haveendstr)) {
fprintf(stderr, "-f -once"
@@ -406,7 +415,7 @@ main(int argc, char **argv)
}
/* XXX - what if *cp = '\''? */
*bp++ = '\'';
strncpy(bp, cp, len+1);
strlcpy(bp, cp, len+1);
bp += len;
*bp++ = '\'';
cp += len;
@@ -428,6 +437,7 @@ main(int argc, char **argv)
if (*cp == ';')
cp++;
*bp++ = ';';
*bp = '\0';
cmdlen++;
s_flag = TRUE; /* -f implies -s */
break;
@@ -480,21 +490,7 @@ main(int argc, char **argv)
program);
exit(21);
}
/*
* The next statement could be:
*
* strncpy(cmdbuf + cmdlen, cp, cplen);
*
* however compilers like gcc would issue warnings such as:
*
* specified bound depends on the length of the
* source argument
*
* even though we terminate the string by setting a NUL
* byte following the copy. Therefore we call memcpy()
* instead to avoid such warnings.
*/
memcpy(cmdbuf + cmdlen, cp, cplen);
strlcpy(cmdbuf + cmdlen, cp, cplen+1);
cmdbuf[newcmdlen] = '\0';
cmdlen = newcmdlen;
index++;
@@ -762,7 +758,7 @@ main(int argc, char **argv)
*/
/*ARGSUSED*/
S_FUNC void
intint(int UNUSED arg)
intint(int UNUSED(arg))
{
(void) signal(SIGINT, intint);
if (inputwait || (++abortlevel >= ABORT_NOW)) {

View File

@@ -28,6 +28,8 @@ BEGIN {
printf("#include <stdio.h>\n");
printf("#include \"calcerr.h\"\n\n");
printf("#include \"have_const.h\"\n\n");
printf("#include \"banned.h\"\t");
printf("/* include after system header <> includes */\n\n");
printf("/*\n");
printf(" * names of calc error values\n");
printf(" */\n");

View File

@@ -34,6 +34,7 @@
#include "lib_calc.h"
#include "calc.h"
#include "alloc.h"
#include "token.h"
#include "symbol.h"
#include "label.h"
@@ -41,11 +42,16 @@
#include "str.h"
#include "func.h"
#include "conf.h"
#include "strl.h"
#if defined(_WIN32) && !defined(__CYGWIN__)
# include <direct.h>
#endif
#include "banned.h" /* include after system header <> includes */
STATIC BOOL rdonce; /* TRUE => do not reread this file */
FUNC *curfunc;
@@ -144,11 +150,9 @@ getcommands(BOOL toplevel)
case 1:
case -1:
if(i == 1) {
strncpy(name,
strlcpy(name,
DEFAULTCALCHELP,
MAXCMD);
/* paranoia */
name[MAXCMD] = '\0';
MAXCMD+1);
givehelp(name);
}
break;
@@ -2354,8 +2358,7 @@ getfilename(char *name, size_t namelen, BOOL *once)
/* use the value of the literal string */
s = findstring(tokenstring());
strncpy(name, s->s_str, namelen-1);
name[namelen-1] = '\0';
strlcpy(name, s->s_str, namelen);
sfree(s);
break;
@@ -2392,8 +2395,7 @@ getfilename(char *name, size_t namelen, BOOL *once)
}
/* return symbol name or value of global var string */
strncpy(name, symstr, namelen-1);
name[namelen-1] = '\0';
strlcpy(name, symstr, namelen);
break;
case T_NEWLINE:
@@ -2431,7 +2433,7 @@ getshowstatement(void)
switch (gettoken()) {
case T_SYMBOL:
strncpy(name, tokensymbol(), 4);
strlcpy(name, tokensymbol(), sizeof(name));
name[4] = '\0';
/* Yuck! */
arg = stringindex("buil\000"
@@ -2595,8 +2597,7 @@ getid(char *buf)
*buf = '\0';
return FALSE;
}
strncpy(buf, tokensymbol(), SYMBOLSIZE);
buf[SYMBOLSIZE] = '\0';
strlcpy(buf, tokensymbol(), SYMBOLSIZE+1);
return TRUE;
}

View File

@@ -29,6 +29,10 @@
#include "config.h"
#include "cmath.h"
#include "banned.h" /* include after system header <> includes */
/*
* cache the natural logarithm of 10
*/

View File

@@ -1,7 +1,7 @@
/*
* commath - extended precision complex arithmetic primitive routines
*
* Copyright (C) 1999-2007 David I. Bell
* Copyright (C) 1999-2007,2021 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
@@ -27,6 +27,9 @@
#include "cmath.h"
#include "banned.h" /* include after system header <> includes */
COMPLEX _czero_ = { &_qzero_, &_qzero_, 1 };
COMPLEX _cone_ = { &_qone_, &_qzero_, 1 };
COMPLEX _conei_ = { &_qzero_, &_qone_, 1 };

View File

@@ -1,7 +1,7 @@
/*
* config - configuration routines
*
* Copyright (C) 1999-2007 David I. Bell and Landon Curt Noll
* Copyright (C) 1999-2007,2021 David I. Bell and Landon Curt Noll
*
* Primary author: David I. Bell
*
@@ -46,6 +46,7 @@
#endif
#include "calc.h"
#include "alloc.h"
#include "token.h"
#include "zrand.h"
#include "block.h"
@@ -53,12 +54,17 @@
#include "config.h"
#include "str.h"
#include "custom.h"
#include "strl.h"
#include "have_strdup.h"
#if !defined(HAVE_STRDUP)
# define strdup(x) calc_strdup((CONST char *)(x))
#endif /* HAVE_STRDUP */
#include "banned.h" /* include after system header <> includes */
/*
* deal with systems that lack a defined CLK_TCK
*/
@@ -757,7 +763,7 @@ setconfig(int type, VALUE *vp)
math_error("Cannot duplicate new prompt");
/*NOTREACHED*/
}
strncpy(p, vp->v_str->s_str, vp->v_str->s_len + 1);
strlcpy(p, vp->v_str->s_str, vp->v_str->s_len + 1);
free(conf->prompt1);
conf->prompt1 = p;
break;
@@ -772,7 +778,7 @@ setconfig(int type, VALUE *vp)
math_error("Cannot duplicate new more prompt");
/*NOTREACHED*/
}
strncpy(p, vp->v_str->s_str, vp->v_str->s_len + 1);
strlcpy(p, vp->v_str->s_str, vp->v_str->s_len + 1);
free(conf->prompt2);
conf->prompt2 = p;
break;

View File

@@ -1,7 +1,7 @@
/*
* const - constant number storage module
*
* Copyright (C) 1999-2007 David I. Bell
* Copyright (C) 1999-2007,2021 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
@@ -28,6 +28,10 @@
#include "calc.h"
#include "qmath.h"
#include "banned.h" /* include after system header <> includes */
#define CONSTALLOCSIZE 400 /* number of constants to allocate */
STATIC unsigned long constcount;/* number of constants defined */

View File

@@ -27,9 +27,27 @@
# Makefile by Landon Curt Noll
# our shell
# The shell used by this Makefile
#
# On some systems, /bin/sh is a rather reduced shell with
# deprecated behavor.
#
# If your system has a up to date, bash shell, then
# you may wish to use:
#
# SHELL= /bin/bash
#
# On some systems such as macOS, the bash shell is very
# far behind to the point wehre is cannot be depended on.
# On such systems, the zsh may be a much better alternative
# shell for this Makefile to use:
#
# SHELL= /bin/zsh
#
SHELL= /bin/sh
#SHELL= /bin/bash
#SHELL= /bin/zsh
####
# Normally, the upper level makefile will set these values. We provide
@@ -328,7 +346,7 @@ depend:
echo 'restoring original cscript/${MAKE_FILE}'; \
${MV} -f ${MAKE_FILE}.bak ${MAKE_FILE}; \
else \
echo 'previous cscript/${MAKE_FILE} is now cscript/${MAKE_FILE}.bak'; \
echo 'old cscript/${MAKE_FILE} is now cscript/${MAKE_FILE}.bak'; \
echo 'new cscript/${MAKE_FILE} formed'; \
echo 'try: diff -u cscript/${MAKE_FILE}.bak cscript/${MAKE_FILE}'; \
fi

View File

@@ -47,6 +47,10 @@
#endif /* CUSTOM */
#include "banned.h" /* include after system header <> includes */
BOOL allow_custom = FALSE; /* TRUE => custom builtins allowed */

View File

@@ -28,9 +28,63 @@
# Makefile by Landon Curt Noll
# our shell
# The shell used by this Makefile
#
# On some systems, /bin/sh is a rather reduced shell with
# deprecated behavor.
#
# If your system has a up to date, bash shell, then
# you may wish to use:
#
# SHELL= /bin/bash
#
# On some systems such as macOS, the bash shell is very
# far behind to the point wehre is cannot be depended on.
# On such systems, the zsh may be a much better alternative
# shell for this Makefile to use:
#
# SHELL= /bin/zsh
#
SHELL= /bin/sh
#SHELL= /bin/bash
#SHELL= /bin/zsh
# CCBAN is given to ${CC} in order to control if banned.h is in effect.
#
# The banned.h attempts to ban the use of certain dangerous functions
# that, if improperly used, could compromise the computational integrity
# if calculations.
#
# In the case of calc, we are motivated in part by the desire for calc
# to correctly calculate: even durings extremely long calculations.
#
# If UNBAN is NOT defined, then calling certain functions
# will result in a call to a non-existent function (link error).
#
# While we do NOT encourage defining UNBAN, there may be
# a system / compiler environment where re-defining a
# function may lead to a fatal compiler complication.
# If that happens, consider compiling as:
#
# make clobber all chk CCBAN=-DUNBAN
#
# as see if this is a work-a-round.
#
# If YOU discover a need for the -DUNBAN work-a-round, PLEASE tell us!
# Please send us a bug report. See the file:
#
# BUGS
#
# or the URL:
#
# http://www.isthe.com/chongo/tech/comp/calc/calc-bugrept.html
#
# for how to send us such a bug report.
#
CCBAN= -UUNBAN
#CCBAN= -DUNBAN
#if 0 /* start of skip for non-Gnu makefiles */
##############################################################################
@@ -353,7 +407,7 @@ EXT=
# The default calc versions
#
VERSION= 2.12.8.2
VERSION= 2.12.9.0
# Names of shared libraries with versions
#
@@ -424,9 +478,9 @@ COMMON_LDFLAGS= ${EXTRA_LDFLAGS}
# NOTE: This does not work for: make-XYZ-only and BLD_TYPE != make-XYZ-only
#
ifeq ($(BLD_TYPE),calc-static-only)
ICFLAGS= ${COMMON_CFLAGS} ${CC_STATIC}
ICFLAGS= ${COMMON_CFLAGS} ${CCBAN} ${CC_STATIC}
else
ICFLAGS= ${COMMON_CFLAGS} ${CC_SHARE}
ICFLAGS= ${COMMON_CFLAGS} ${CCBAN} ${CC_SHARE}
endif
CFLAGS= ${ICFLAGS} ${CCOPT}
@@ -470,12 +524,20 @@ LDFLAGS= ${LD_DEBUG} ${ILDFLAGS}
# CCOPT are flags given to ${CC} for optimization
# CCWARN are flags given to ${CC} for warning message control
#
# WNO_IMPLICT, WNO_ERROR_LONG_LONG and WNO_LONG_LONG are given to ${CC}
# when compiling special .o files that may need special compile options
# The following are given to ${CC}:
#
# WNO_IMPLICT
# WNO_ERROR_LONG_LONG
# WNO_LONG_LONG
#
# when compiling special .o files that may need special compile options:
#
# NOTE: These flags simply turn off certain compiler warnings,
# which is useful only when CCWERR is set to -Werror.
#
# NOTE: If your compiler does not have these -Wno files, just
# set these variables to nothing as in:
#
# WNO_IMPLICT=
# WNO_ERROR_LONG_LONG=
# WNO_LONG_LONG=
@@ -486,6 +548,9 @@ LDFLAGS= ${LD_DEBUG} ${ILDFLAGS}
# to abort on warnings, then leave CCWERR blank.
# CCMISC are misc flags given to ${CC}
#
# CCBAN is given to ${CC} in order to control if banned.h is in effect.
# NOTE: See where CCBAN is defined above for details.
#
# LCC is how the C compiler is invoked on locally executed intermediate programs
# CC is how the C compiler is invoked (with an optional Purify)
#
@@ -908,7 +973,7 @@ CC= ${PURIFY} ${LCC} ${CCWERR}
# ILDFLAGS for ${CC} in linking intermediate programs used to help compile calc
# LDFLAGS for ${CC} in linking calc programs other than intermediate programs
#
ICFLAGS= ${COMMON_CFLAGS} ${CC_STATIC}
ICFLAGS= ${COMMON_CFLAGS} ${CCBAN} ${CC_STATIC}
CFLAGS= ${ICFLAGS} ${CCOPT}
#
ILDFLAGS= ${COMMON_LDFLAGS} ${LD_STATIC}
@@ -1035,9 +1100,9 @@ endif
# NOTE: This does not work for: make-XYZ-only and BLD_TYPE != make-XYZ-only
#
ifeq ($(BLD_TYPE),calc-static-only)
ICFLAGS= ${COMMON_CFLAGS} ${CC_STATIC}
ICFLAGS= ${COMMON_CFLAGS} ${CCBAN} ${CC_STATIC}
else
ICFLAGS= ${COMMON_CFLAGS} ${CC_SHARE}
ICFLAGS= ${COMMON_CFLAGS} ${CCBAN} ${CC_SHARE}
endif
CFLAGS= ${ICFLAGS} ${CCOPT}
@@ -1284,13 +1349,14 @@ depend:
${Q} ${SED} -n '1,/^# DO NOT DELETE THIS LINE/p' \
${MAKE_FILE}.bak > ${MAKE_FILE}
${Q} ${GREP} -v '^#' skel/custom/makedep.out >> ${MAKE_FILE}
${Q} echo removing skel
${Q} ${RM} -rf skel
-${Q} if ${CMP} -s ${MAKE_FILE}.bak ${MAKE_FILE}; then \
echo 'custom/${MAKE_FILE} was already up to date'; \
echo 'restoring original custom/${MAKE_FILE}'; \
${MV} -f ${MAKE_FILE}.bak ${MAKE_FILE}; \
else \
echo 'previous custom/${MAKE_FILE} is now custom/${MAKE_FILE}.bak'; \
echo 'old custom/${MAKE_FILE} is now custom/${MAKE_FILE}.bak'; \
echo 'new custom/${MAKE_FILE} formed'; \
echo 'try: diff -u custom/${MAKE_FILE}.bak custom/${MAKE_FILE}'; \
fi
@@ -1339,6 +1405,7 @@ clobber: clean
${RM} -f libcustcalc${LIB_EXT}
${RM} -f libcustcalc.a
${RM} -f libcustcalc*
${RM} -rf skel
${V} echo remove files that are obsolete
#if 0 /* start of skip for non-Gnu makefiles */
${RM} -f Makefile.simple
@@ -1585,6 +1652,7 @@ uninstall:
# DO NOT DELETE THIS LINE -- make depend depends on it.
c_argv.o: ../alloc.h
c_argv.o: ../banned.h
c_argv.o: ../block.h
c_argv.o: ../byteswap.h
c_argv.o: ../calc.h
@@ -1595,6 +1663,7 @@ c_argv.o: ../custom.h
c_argv.o: ../decl.h
c_argv.o: ../endian_calc.h
c_argv.o: ../hash.h
c_argv.o: ../have_ban_pragma.h
c_argv.o: ../have_const.h
c_argv.o: ../have_memmv.h
c_argv.o: ../have_newstr.h
@@ -1610,6 +1679,7 @@ c_argv.o: ../value.h
c_argv.o: ../zmath.h
c_argv.o: c_argv.c
c_devnull.o: ../alloc.h
c_devnull.o: ../banned.h
c_devnull.o: ../block.h
c_devnull.o: ../byteswap.h
c_devnull.o: ../calcerr.h
@@ -1619,6 +1689,7 @@ c_devnull.o: ../custom.h
c_devnull.o: ../decl.h
c_devnull.o: ../endian_calc.h
c_devnull.o: ../hash.h
c_devnull.o: ../have_ban_pragma.h
c_devnull.o: ../have_const.h
c_devnull.o: ../have_memmv.h
c_devnull.o: ../have_newstr.h
@@ -1635,6 +1706,7 @@ c_devnull.o: ../value.h
c_devnull.o: ../zmath.h
c_devnull.o: c_devnull.c
c_help.o: ../alloc.h
c_help.o: ../banned.h
c_help.o: ../block.h
c_help.o: ../byteswap.h
c_help.o: ../calcerr.h
@@ -1644,6 +1716,7 @@ c_help.o: ../custom.h
c_help.o: ../decl.h
c_help.o: ../endian_calc.h
c_help.o: ../hash.h
c_help.o: ../have_ban_pragma.h
c_help.o: ../have_const.h
c_help.o: ../have_memmv.h
c_help.o: ../have_newstr.h
@@ -1660,6 +1733,7 @@ c_help.o: ../value.h
c_help.o: ../zmath.h
c_help.o: c_help.c
c_pmodm127.o: ../alloc.h
c_pmodm127.o: ../banned.h
c_pmodm127.o: ../block.h
c_pmodm127.o: ../byteswap.h
c_pmodm127.o: ../calcerr.h
@@ -1669,6 +1743,7 @@ c_pmodm127.o: ../custom.h
c_pmodm127.o: ../decl.h
c_pmodm127.o: ../endian_calc.h
c_pmodm127.o: ../hash.h
c_pmodm127.o: ../have_ban_pragma.h
c_pmodm127.o: ../have_const.h
c_pmodm127.o: ../have_memmv.h
c_pmodm127.o: ../have_newstr.h
@@ -1684,6 +1759,7 @@ c_pmodm127.o: ../value.h
c_pmodm127.o: ../zmath.h
c_pmodm127.o: c_pmodm127.c
c_pzasusb8.o: ../alloc.h
c_pzasusb8.o: ../banned.h
c_pzasusb8.o: ../block.h
c_pzasusb8.o: ../byteswap.h
c_pzasusb8.o: ../calcerr.h
@@ -1693,6 +1769,7 @@ c_pzasusb8.o: ../custom.h
c_pzasusb8.o: ../decl.h
c_pzasusb8.o: ../endian_calc.h
c_pzasusb8.o: ../hash.h
c_pzasusb8.o: ../have_ban_pragma.h
c_pzasusb8.o: ../have_const.h
c_pzasusb8.o: ../have_memmv.h
c_pzasusb8.o: ../have_newstr.h
@@ -1708,6 +1785,7 @@ c_pzasusb8.o: ../value.h
c_pzasusb8.o: ../zmath.h
c_pzasusb8.o: c_pzasusb8.c
c_register.o: ../alloc.h
c_register.o: ../banned.h
c_register.o: ../block.h
c_register.o: ../byteswap.h
c_register.o: ../calc.h
@@ -1718,6 +1796,7 @@ c_register.o: ../custom.h
c_register.o: ../decl.h
c_register.o: ../endian_calc.h
c_register.o: ../hash.h
c_register.o: ../have_ban_pragma.h
c_register.o: ../have_const.h
c_register.o: ../have_memmv.h
c_register.o: ../have_newstr.h
@@ -1733,6 +1812,7 @@ c_register.o: ../value.h
c_register.o: ../zmath.h
c_register.o: c_register.c
c_sysinfo.o: ../alloc.h
c_sysinfo.o: ../banned.h
c_sysinfo.o: ../block.h
c_sysinfo.o: ../byteswap.h
c_sysinfo.o: ../calc.h
@@ -1745,6 +1825,7 @@ c_sysinfo.o: ../decl.h
c_sysinfo.o: ../endian_calc.h
c_sysinfo.o: ../fposval.h
c_sysinfo.o: ../hash.h
c_sysinfo.o: ../have_ban_pragma.h
c_sysinfo.o: ../have_const.h
c_sysinfo.o: ../have_memmv.h
c_sysinfo.o: ../have_newstr.h
@@ -1765,6 +1846,7 @@ c_sysinfo.o: ../zrand.h
c_sysinfo.o: ../zrandom.h
c_sysinfo.o: c_sysinfo.c
custtbl.o: ../alloc.h
custtbl.o: ../banned.h
custtbl.o: ../block.h
custtbl.o: ../byteswap.h
custtbl.o: ../calcerr.h
@@ -1774,6 +1856,7 @@ custtbl.o: ../custom.h
custtbl.o: ../decl.h
custtbl.o: ../endian_calc.h
custtbl.o: ../hash.h
custtbl.o: ../have_ban_pragma.h
custtbl.o: ../have_const.h
custtbl.o: ../have_memmv.h
custtbl.o: ../have_newstr.h

View File

@@ -28,9 +28,63 @@
# Makefile by Landon Curt Noll
# our shell
# The shell used by this Makefile
#
# On some systems, /bin/sh is a rather reduced shell with
# deprecated behavor.
#
# If your system has a up to date, bash shell, then
# you may wish to use:
#
# SHELL= /bin/bash
#
# On some systems such as macOS, the bash shell is very
# far behind to the point wehre is cannot be depended on.
# On such systems, the zsh may be a much better alternative
# shell for this Makefile to use:
#
# SHELL= /bin/zsh
#
SHELL= /bin/sh
#SHELL= /bin/bash
#SHELL= /bin/zsh
# CCBAN is given to ${CC} in order to control if banned.h is in effect.
#
# The banned.h attempts to ban the use of certain dangerous functions
# that, if improperly used, could compromise the computational integrity
# if calculations.
#
# In the case of calc, we are motivated in part by the desire for calc
# to correctly calculate: even durings extremely long calculations.
#
# If UNBAN is NOT defined, then calling certain functions
# will result in a call to a non-existent function (link error).
#
# While we do NOT encourage defining UNBAN, there may be
# a system / compiler environment where re-defining a
# function may lead to a fatal compiler complication.
# If that happens, consider compiling as:
#
# make clobber all chk CCBAN=-DUNBAN
#
# as see if this is a work-a-round.
#
# If YOU discover a need for the -DUNBAN work-a-round, PLEASE tell us!
# Please send us a bug report. See the file:
#
# BUGS
#
# or the URL:
#
# http://www.isthe.com/chongo/tech/comp/calc/calc-bugrept.html
#
# for how to send us such a bug report.
#
CCBAN= -UUNBAN
#CCBAN= -DUNBAN
#if 0 /* start of skip for non-Gnu makefiles */
##############################################################################
@@ -353,7 +407,7 @@ EXT=
# The default calc versions
#
VERSION= 2.12.8.2
VERSION= 2.12.9.0
# Names of shared libraries with versions
#
@@ -424,9 +478,9 @@ COMMON_LDFLAGS= ${EXTRA_LDFLAGS}
# NOTE: This does not work for: make-XYZ-only and BLD_TYPE != make-XYZ-only
#
ifeq ($(BLD_TYPE),calc-static-only)
ICFLAGS= ${COMMON_CFLAGS} ${CC_STATIC}
ICFLAGS= ${COMMON_CFLAGS} ${CCBAN} ${CC_STATIC}
else
ICFLAGS= ${COMMON_CFLAGS} ${CC_SHARE}
ICFLAGS= ${COMMON_CFLAGS} ${CCBAN} ${CC_SHARE}
endif
CFLAGS= ${ICFLAGS} ${CCOPT}

View File

@@ -228,13 +228,14 @@ depend:
${Q} ${SED} -n '1,/^# DO NOT DELETE THIS LINE/p' \
${MAKE_FILE}.bak > ${MAKE_FILE}
${Q} ${GREP} -v '^#' skel/custom/makedep.out >> ${MAKE_FILE}
${Q} echo removing skel
${Q} ${RM} -rf skel
-${Q} if ${CMP} -s ${MAKE_FILE}.bak ${MAKE_FILE}; then \
echo 'custom/${MAKE_FILE} was already up to date'; \
echo 'restoring original custom/${MAKE_FILE}'; \
${MV} -f ${MAKE_FILE}.bak ${MAKE_FILE}; \
else \
echo 'previous custom/${MAKE_FILE} is now custom/${MAKE_FILE}.bak'; \
echo 'old custom/${MAKE_FILE} is now custom/${MAKE_FILE}.bak'; \
echo 'new custom/${MAKE_FILE} formed'; \
echo 'try: diff -u custom/${MAKE_FILE}.bak custom/${MAKE_FILE}'; \
fi
@@ -283,6 +284,7 @@ clobber: clean
${RM} -f libcustcalc${LIB_EXT}
${RM} -f libcustcalc.a
${RM} -f libcustcalc*
${RM} -rf skel
${V} echo remove files that are obsolete
#if 0 /* start of skip for non-Gnu makefiles */
${RM} -f Makefile.simple
@@ -529,6 +531,7 @@ uninstall:
# DO NOT DELETE THIS LINE -- make depend depends on it.
c_argv.o: ../alloc.h
c_argv.o: ../banned.h
c_argv.o: ../block.h
c_argv.o: ../byteswap.h
c_argv.o: ../calc.h
@@ -539,6 +542,7 @@ c_argv.o: ../custom.h
c_argv.o: ../decl.h
c_argv.o: ../endian_calc.h
c_argv.o: ../hash.h
c_argv.o: ../have_ban_pragma.h
c_argv.o: ../have_const.h
c_argv.o: ../have_memmv.h
c_argv.o: ../have_newstr.h
@@ -554,6 +558,7 @@ c_argv.o: ../value.h
c_argv.o: ../zmath.h
c_argv.o: c_argv.c
c_devnull.o: ../alloc.h
c_devnull.o: ../banned.h
c_devnull.o: ../block.h
c_devnull.o: ../byteswap.h
c_devnull.o: ../calcerr.h
@@ -563,6 +568,7 @@ c_devnull.o: ../custom.h
c_devnull.o: ../decl.h
c_devnull.o: ../endian_calc.h
c_devnull.o: ../hash.h
c_devnull.o: ../have_ban_pragma.h
c_devnull.o: ../have_const.h
c_devnull.o: ../have_memmv.h
c_devnull.o: ../have_newstr.h
@@ -579,6 +585,7 @@ c_devnull.o: ../value.h
c_devnull.o: ../zmath.h
c_devnull.o: c_devnull.c
c_help.o: ../alloc.h
c_help.o: ../banned.h
c_help.o: ../block.h
c_help.o: ../byteswap.h
c_help.o: ../calcerr.h
@@ -588,6 +595,7 @@ c_help.o: ../custom.h
c_help.o: ../decl.h
c_help.o: ../endian_calc.h
c_help.o: ../hash.h
c_help.o: ../have_ban_pragma.h
c_help.o: ../have_const.h
c_help.o: ../have_memmv.h
c_help.o: ../have_newstr.h
@@ -604,6 +612,7 @@ c_help.o: ../value.h
c_help.o: ../zmath.h
c_help.o: c_help.c
c_pmodm127.o: ../alloc.h
c_pmodm127.o: ../banned.h
c_pmodm127.o: ../block.h
c_pmodm127.o: ../byteswap.h
c_pmodm127.o: ../calcerr.h
@@ -613,6 +622,7 @@ c_pmodm127.o: ../custom.h
c_pmodm127.o: ../decl.h
c_pmodm127.o: ../endian_calc.h
c_pmodm127.o: ../hash.h
c_pmodm127.o: ../have_ban_pragma.h
c_pmodm127.o: ../have_const.h
c_pmodm127.o: ../have_memmv.h
c_pmodm127.o: ../have_newstr.h
@@ -628,6 +638,7 @@ c_pmodm127.o: ../value.h
c_pmodm127.o: ../zmath.h
c_pmodm127.o: c_pmodm127.c
c_pzasusb8.o: ../alloc.h
c_pzasusb8.o: ../banned.h
c_pzasusb8.o: ../block.h
c_pzasusb8.o: ../byteswap.h
c_pzasusb8.o: ../calcerr.h
@@ -637,6 +648,7 @@ c_pzasusb8.o: ../custom.h
c_pzasusb8.o: ../decl.h
c_pzasusb8.o: ../endian_calc.h
c_pzasusb8.o: ../hash.h
c_pzasusb8.o: ../have_ban_pragma.h
c_pzasusb8.o: ../have_const.h
c_pzasusb8.o: ../have_memmv.h
c_pzasusb8.o: ../have_newstr.h
@@ -652,6 +664,7 @@ c_pzasusb8.o: ../value.h
c_pzasusb8.o: ../zmath.h
c_pzasusb8.o: c_pzasusb8.c
c_register.o: ../alloc.h
c_register.o: ../banned.h
c_register.o: ../block.h
c_register.o: ../byteswap.h
c_register.o: ../calc.h
@@ -662,6 +675,7 @@ c_register.o: ../custom.h
c_register.o: ../decl.h
c_register.o: ../endian_calc.h
c_register.o: ../hash.h
c_register.o: ../have_ban_pragma.h
c_register.o: ../have_const.h
c_register.o: ../have_memmv.h
c_register.o: ../have_newstr.h
@@ -677,6 +691,7 @@ c_register.o: ../value.h
c_register.o: ../zmath.h
c_register.o: c_register.c
c_sysinfo.o: ../alloc.h
c_sysinfo.o: ../banned.h
c_sysinfo.o: ../block.h
c_sysinfo.o: ../byteswap.h
c_sysinfo.o: ../calc.h
@@ -689,6 +704,7 @@ c_sysinfo.o: ../decl.h
c_sysinfo.o: ../endian_calc.h
c_sysinfo.o: ../fposval.h
c_sysinfo.o: ../hash.h
c_sysinfo.o: ../have_ban_pragma.h
c_sysinfo.o: ../have_const.h
c_sysinfo.o: ../have_memmv.h
c_sysinfo.o: ../have_newstr.h
@@ -709,6 +725,7 @@ c_sysinfo.o: ../zrand.h
c_sysinfo.o: ../zrandom.h
c_sysinfo.o: c_sysinfo.c
custtbl.o: ../alloc.h
custtbl.o: ../banned.h
custtbl.o: ../block.h
custtbl.o: ../byteswap.h
custtbl.o: ../calcerr.h
@@ -718,6 +735,7 @@ custtbl.o: ../custom.h
custtbl.o: ../decl.h
custtbl.o: ../endian_calc.h
custtbl.o: ../hash.h
custtbl.o: ../have_ban_pragma.h
custtbl.o: ../have_const.h
custtbl.o: ../have_memmv.h
custtbl.o: ../have_newstr.h

View File

@@ -1,7 +1,7 @@
/*
* c_argv - a custom function display info about its args
*
* Copyright (C) 1999-2006 Landon Curt Noll
* Copyright (C) 1999-2006,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
@@ -38,6 +38,10 @@
#include "have_unused.h"
#include "banned.h" /* include after system header <> includes */
/*
* c_argv - a custom function display info about its args
*
@@ -49,7 +53,7 @@
*/
/*ARGSUSED*/
VALUE
c_argv(char UNUSED *name, int count, VALUE **vals)
c_argv(char *UNUSED(name), int count, VALUE **vals)
{
VALUE result; /* what we will return */
ZVALUE zfilelen; /* length of a file as a ZVALUE */

View File

@@ -1,7 +1,7 @@
/*
* c_devnull - a custom function that does nothing
*
* Copyright (C) 1999-2004 Landon Curt Noll
* Copyright (C) 1999-2004,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
@@ -39,6 +39,9 @@
#include "have_unused.h"
#include "banned.h" /* include after system header <> includes */
/*
* c_devnull - a custom function that does nothing
*
@@ -47,7 +50,7 @@
*/
/*ARGSUSED*/
VALUE
c_devnull(char UNUSED *name, int UNUSED count, VALUE UNUSED **vals)
c_devnull(char *UNUSED(name), int UNUSED(count), VALUE **UNUSED(vals))
{
VALUE result; /* what we will return */

View File

@@ -1,7 +1,7 @@
/*
* c_help - custom help function
*
* Copyright (C) 1999-2004 Landon Curt Noll
* Copyright (C) 1999-2004,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
@@ -39,6 +39,9 @@
#include "have_unused.h"
#include "banned.h" /* include after system header <> includes */
/*
* c_help - custom help function
*
@@ -58,7 +61,7 @@
*/
/*ARGSUSED*/
VALUE
c_help(char UNUSED *name, int UNUSED count, VALUE **vals)
c_help(char *UNUSED(name), int UNUSED(count), VALUE **vals)
{
VALUE result; /* what we will return */

View File

@@ -35,6 +35,10 @@
#include "have_unused.h"
#include "banned.h" /* include after system header <> includes */
/* 2^255 */
STATIC HALF h255[] = {
#if BASEB == 32
@@ -71,7 +75,7 @@ STATIC ZVALUE lastmodinv[1];
*/
/*ARGSUSED*/
VALUE
c_pmodm127(char UNUSED *name, int UNUSED count, VALUE **vals)
c_pmodm127(char *UNUSED(name), int UNUSED(count), VALUE **vals)
{
VALUE result; /* what we will return */
ZVALUE q; /* test factor */

View File

@@ -35,6 +35,10 @@
#include "have_unused.h"
#include "banned.h" /* include after system header <> includes */
/*
* c_pzasusb8 - print numerator as a string of USB8s
*
@@ -47,7 +51,7 @@
*/
/*ARGSUSED*/
VALUE
c_pzasusb8(char UNUSED *name, int UNUSED count, VALUE **vals)
c_pzasusb8(char *UNUSED(name), int UNUSED(count), VALUE **vals)
{
VALUE result; /* what we will return */
ZVALUE z; /* numerator of the value */

View File

@@ -1,7 +1,7 @@
/*
* c_register - set or print a custom register value
*
* Copyright (C) 2007 Landon Curt Noll
* Copyright (C) 2007,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
@@ -39,6 +39,9 @@
#include "have_unused.h"
#include "banned.h" /* include after system header <> includes */
/*
* registers
*/
@@ -76,7 +79,7 @@ init_custreg(void)
*/
/*ARGSUSED*/
VALUE
c_register(char UNUSED *name, int count, VALUE **vals)
c_register(char *UNUSED(name), int count, VALUE **vals)
{
VALUE result; /* what we will return */
long reg; /* register number */

View File

@@ -57,6 +57,9 @@
#include "have_unused.h"
#include "banned.h" /* include after system header <> includes */
/*
* sys_info - names and values of selected #defines
*/
@@ -266,7 +269,7 @@ S_FUNC void dump_mening_value(void); /* custom("sysinfo", 2) */
*/
/*ARGSUSED*/
VALUE
c_sysinfo(char UNUSED *name, int count, VALUE **vals)
c_sysinfo(char *UNUSED(name), int count, VALUE **vals)
{
VALUE result; /* what we will return */
struct infoname *p; /* current infoname */

View File

@@ -30,6 +30,10 @@
#include "value.h"
#include "custom.h"
#include "banned.h" /* include after system header <> includes */
/*
* NOTE: See the file CUSTOM for instructions on how to add
* custom functions.

2
decl.h
View File

@@ -1,7 +1,7 @@
/*
* decl - variable and function declaration macros
*
* Copyright (C) 2007,2014 Landon Curt Noll
* Copyright (C) 2007,2014,2021 Landon Curt Noll
*
* Primary author: Landon Curt Noll
*

View File

@@ -42,6 +42,10 @@
#include <unistd.h>
#endif
#include "banned.h" /* include after system header <> includes */
/* byte order array */
char byte[8] = { (char)0x12, (char)0x36, (char)0x48, (char)0x59,
(char)0x01, (char)0x23, (char)0x45, (char)0x67 };

50
file.c
View File

@@ -37,17 +37,23 @@
#endif /* HAVE_UNISTD_H */
#include <ctype.h>
#include "calc.h"
#include "alloc.h"
#include "longbits.h"
#include "have_fpos.h"
#include "have_fpos_pos.h"
#include "fposval.h"
#include "file.h"
#include "calcerr.h"
#include "strl.h"
#if defined(_WIN32)
# include <io.h>
#endif
#include "banned.h" /* include after system header <> includes */
#define READSIZE 1024 /* buffer size for reading */
#define MIN(a,b) (((a) <= (b)) ? (a) : (b))
@@ -141,6 +147,7 @@ file_init(void)
files[idnum].reading = TRUE;
files[idnum].writing = TRUE;
files[idnum].action = 0;
memset(files[idnum].mode, 0, MODE_LEN+1);
/*
* stat the descriptor to see what we have
*/
@@ -148,16 +155,19 @@ file_init(void)
size_t snprintf_len; /* malloced snprintf length */
fp = (FILE *) fdopen(i,"r+"); /*guess mode*/
if (fp) {
strcpy(files[idnum].mode, "r+");
strlcpy(files[idnum].mode, "r+",
sizeof(files[idnum].mode));
} else {
fp = (FILE *) fdopen(i, "r");
if (fp) {
strcpy(files[idnum].mode, "r");
strlcpy(files[idnum].mode, "r",
sizeof(files[idnum].mode));
files[idnum].writing = FALSE;
} else {
fp = (FILE *) fdopen(i, "w");
if (fp) {
strcpy(files[idnum].mode, "w");
strlcpy(files[idnum].mode, "w",
sizeof(files[idnum].mode));
files[idnum].reading = FALSE;
}
else
@@ -208,10 +218,14 @@ S_FUNC void
init_fileio(FILEIO *fiop, char *name, char *mode,
struct stat *sbufp, FILEID id, FILE *fp)
{
char modestr[sizeof(fiop->mode)]; /* mode [rwa]b?\+? */
size_t namelen; /* length of name */
char modestr[MODE_LEN+1]; /* mode [rwa]b?\+? */
size_t namelen; /* length of name */
/* clear modestr */
memset(modestr, 0, sizeof(modestr));
/* allocate filename if requested */
namelen = 0;
if (name != NULL) {
namelen = strlen(name);
fiop->name = (char *)malloc(namelen + 1);
@@ -223,7 +237,7 @@ init_fileio(FILEIO *fiop, char *name, char *mode,
/* initialize FILEIO structure */
if (name != NULL) {
strncpy(fiop->name, name, namelen+1);
strlcpy(fiop->name, name, namelen+1);
}
fiop->id = id;
fiop->fp = fp;
@@ -234,7 +248,7 @@ init_fileio(FILEIO *fiop, char *name, char *mode,
fiop->appending = FALSE;
fiop->binary = FALSE;
fiop->action = 0;
fiop->mode[0] = '\0';
memset(fiop->mode, 0, sizeof(fiop->mode));
/*
* determine file open mode
@@ -248,65 +262,65 @@ init_fileio(FILEIO *fiop, char *name, char *mode,
if (mode[0] == 'r') {
/* note read mode */
strcpy(modestr, "r");
strlcpy(modestr, "r", sizeof(modestr));
fiop->reading = TRUE;
/* note binary mode even though mode is not used / ignored */
if (strchr(mode, 'b') != NULL) {
strcat(modestr, "b");
strlcat(modestr, "b", sizeof(modestr));
}
/* note if reading and writing */
if (strchr(mode, '+') != NULL) {
fiop->writing = TRUE;
strcat(modestr, "+");
strlcat(modestr, "+", sizeof(modestr));
}
/* canonicalize write modes */
} else if (mode[0] == 'w') {
/* note write mode */
strcpy(modestr, "w");
strlcpy(modestr, "w", sizeof(modestr));
fiop->writing = TRUE;
/* note binary mode even though mode is not used / ignored */
if (strchr(mode, 'b') != NULL) {
strcat(modestr, "b");
strlcat(modestr, "b", sizeof(modestr));
}
/* note if reading and writing */
if (strchr(mode, '+') != NULL) {
fiop->reading = TRUE;
strcat(modestr, "+");
strlcat(modestr, "+", sizeof(modestr));
}
/* canonicalize append modes */
} else if (mode[0] == 'a') {
/* note append mode */
strcpy(modestr, "a");
strlcpy(modestr, "a", sizeof(modestr));
fiop->writing = TRUE;
fiop->appending = TRUE;
/* note binary mode even though mode is not used / ignored */
if (strchr(mode, 'b') != NULL) {
strcat(modestr, "b");
strlcat(modestr, "b", sizeof(modestr));
}
/* note if reading and writing */
if (strchr(mode, '+') != NULL) {
fiop->reading = TRUE;
strcat(modestr, "+");
strlcat(modestr, "+", sizeof(modestr));
}
/* canonicalize no I/O modes */
} else {
modestr[0] = '\0';
}
modestr[sizeof(modestr)-1] = '\0'; /* firewall */
modestr[MODE_LEN] = '\0'; /* firewall */
/* record canonical open mode string */
strncpy(fiop->mode, modestr, sizeof(fiop->mode));
strlcpy(fiop->mode, modestr, sizeof(fiop->mode));
}

3
file.h
View File

@@ -41,6 +41,7 @@
/*
* Definition of opened files.
*/
#define MODE_LEN (sizeof("rb+")-1)
typedef struct {
FILEID id; /* id to identify this file */
FILE *fp; /* real file structure for I/O */
@@ -52,7 +53,7 @@ typedef struct {
BOOL appending; /* TRUE if also opened for appending */
BOOL binary; /* TRUE if binary mode - mode ignored/unused */
char action; /* most recent use for 'r', 'w' or 0 */
char mode[sizeof("rb+")+1];/* open mode */
char mode[MODE_LEN+1]; /* open mode */
} FILEIO;

View File

@@ -64,6 +64,11 @@
#include "have_offscl.h"
#include "have_posscl.h"
#include "have_fpos_pos.h"
#include "alloc.h"
#include "banned.h" /* include after system header <> includes */
char *program; /* our name */

54
fposval.h.def Normal file
View File

@@ -0,0 +1,54 @@
/*
* fposval.h.def - fposval.h default macros
*
* Copyright (C) 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: 2021/03/10 22;14:26
* File existed as early as: 2021
*
* Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/
*/
/*
* WARNING: For some reason fposval failed to generate values
* so we choose these values that are hopefully OK
*/
/* what are our file position & size types? */
#undef FILEPOS_BITS
#define FILEPOS_BITS 64
#undef FILEPOS_LEN
#define FILEPOS_LEN 8
#define SWAP_HALF_IN_FILEPOS(dest, src) (*(dest) = *(src))
#undef OFF_T_BITS
#define OFF_T_BITS 64
#undef OFF_T_LEN
#define OFF_T_LEN 8
#define SWAP_HALF_IN_OFF_T(dest, src) (*(dest) = *(src))
#undef DEV_BITS
#define DEV_BITS 32
#undef DEV_LEN
#define DEV_LEN 4
#define SWAP_HALF_IN_DEV(dest, src) memcpy((void *)(dest), (void *)(src), 4)
#undef INODE_BITS
#define INODE_BITS 64
#undef INODE_LEN
#define INODE_LEN 8
#define SWAP_HALF_IN_INODE(dest, src) memcpy((void *)(dest), (void *)(src), 8)

59
func.c
View File

@@ -105,6 +105,7 @@
#include "zrand.h"
#include "zrandom.h"
#include "custom.h"
#include "strl.h"
#if defined(CUSTOM)
# define E_CUSTOM_ERROR E_NO_C_ARG
@@ -113,6 +114,9 @@
#endif
#include "banned.h" /* include after system header <> includes */
/*
* forward declarations
*/
@@ -269,22 +273,7 @@ f_prompt(VALUE *vp)
math_error("Cannot allocate string");
/*NOTREACHED*/
}
/*
* The next statement could be::
*
* strncpy(newcp, cp, len);
*
* however compilers like gcc would issue warnings such as:
*
* specified bound depends on the length of the
* source argument
*
* even though we terminate the string by setting a NUL
* byte following the copy. Therefore we call memcpy()
* instead to avoid such warnings.
*/
memcpy(newcp, cp, len);
newcp[len] = '\0';
strlcpy(newcp, cp, len+1);
result.v_str = makestring(newcp);
return result;
}
@@ -317,7 +306,7 @@ f_display(int count, VALUE **vals)
/*ARGSUSED*/
S_FUNC VALUE
f_null(int UNUSED count, VALUE UNUSED **vals)
f_null(int UNUSED(count), VALUE **UNUSED(vals))
{
VALUE res;
@@ -5341,7 +5330,7 @@ f_list(int count, VALUE **vals)
/*ARGSUSED*/
S_FUNC VALUE
f_assoc(int UNUSED count, VALUE UNUSED **vals)
f_assoc(int UNUSED(count), VALUE **UNUSED(vals))
{
VALUE result;
@@ -7466,22 +7455,7 @@ f_cmdbuf(void)
math_error("Cannot allocate string in cmdbuf");
/*NOTREACHED*/
}
/*
* The next statement could be::
*
* strncpy(newcp, cmdbuf, cmdbuf_len);
*
* however compilers like gcc would issue warnings such as:
*
* specified bound depends on the length of the
* source argument
*
* even though we terminate the string by setting a NUL
* byte following the copy. Therefore we call memcpy()
* instead to avoid such warnings.
*/
memcpy(newcp, cmdbuf, cmdbuf_len);
newcp[cmdbuf_len] = '\0';
strlcpy(newcp, cmdbuf, cmdbuf_len+1);
result.v_str = makestring(newcp);
return result;
}
@@ -7666,7 +7640,7 @@ f_putenv(int count, VALUE **vals)
/*NOTREACHED*/
}
/*
* The next statement could be::
* The next statement could be:
*
* snprintf(putenv_str, snprintf_len,
* "%s=%s", vals[0]->v_str->s_str,
@@ -7677,16 +7651,16 @@ f_putenv(int count, VALUE **vals)
* null destination pointer
*
* even though we check that putenv_str is non-NULL
* above before using it. Therefore we call memcpy()
* above before using it. Therefore we call strlcpy()
* twice and make an assignment instead to avoid such warnings.
*/
memcpy(putenv_str,
strlcpy(putenv_str,
vals[0]->v_str->s_str,
vals[0]->v_str->s_len);
vals[0]->v_str->s_len+1);
putenv_str[vals[0]->v_str->s_len] = '=';
memcpy(putenv_str + vals[0]->v_str->s_len + 1,
strlcpy(putenv_str + vals[0]->v_str->s_len + 1,
vals[1]->v_str->s_str,
vals[1]->v_str->s_len);
vals[1]->v_str->s_len+1);
putenv_str[snprintf_len] = '\0';
} else {
@@ -7711,9 +7685,8 @@ f_putenv(int count, VALUE **vals)
math_error("Cannot allocate string in putenv");
/*NOTREACHED*/
}
memcpy(putenv_str, vals[0]->v_str->s_str,
vals[0]->v_str->s_len);
putenv_str[vals[0]->v_str->s_len] = '\0';
strlcpy(putenv_str, vals[0]->v_str->s_str,
vals[0]->v_str->s_len+1);
}
/* return putenv result */

9
hash.c
View File

@@ -26,16 +26,23 @@
#include <stdio.h>
#include <string.h>
#include "have_string.h"
#ifdef HAVE_STRING_H
# include <string.h>
#endif
#include <sys/types.h>
#include <sys/stat.h>
#include "calc.h"
#include "alloc.h"
#include "value.h"
#include "zrand.h"
#include "zrandom.h"
#include "hash.h"
#include "banned.h" /* include after system header <> includes */
/*
* external hash_setup functions
*/

71
have_ban_pragma.c Normal file
View File

@@ -0,0 +1,71 @@
/*
* have_ban_pragma.c - Determine if we have #pragma GCC poison func_name
*
* Copyright (C) 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: 2021/03/08 01:02:34
* File existed as early as: 2021
*
* chongo <was here> /\oo/\ http://www.isthe.com/chongo/
* Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/
*/
/*
* usage:
* have_ban_pragma
*
* Not all systems have #pragma GCC poison func_name, so this may not
* compile on your system.
*
* This prog outputs several defines:
*
* HAVE_PRAGMA_GCC_POSION
* defined ==> use #pragma GCC poison func_name
* undefined ==> do not use #pragma GCC poison func_name
*
* NOTE: Modern clang compilers allow for 'pragma GCC poison func_name'.
* This is NOT simply a GCC feature.
*/
#include <stdio.h>
/* undef UNBAN to be undefined to force use of banned.h */
#undef UNBAN
/* prevent banned.h from including have_ban_pragma.h */
#define PRE_HAVE_BAN_PRAGMA_H
#include "banned.h" /* include after system header <> includes */
int
main(void)
{
#if defined(HAVE_NO_PRAGMA_GCC_POSION)
printf("#undef HAVE_PRAGMA_GCC_POSION /* no */\n");
#else /* HAVE_NO_PRAGMA_GCC_POSION */
printf("#define HAVE_PRAGMA_GCC_POSION /* yes */\n");
#endif /* HAVE_NO_PRAGMA_GCC_POSION */
/* exit(0); */
return 0;
}

View File

@@ -41,9 +41,12 @@
* (nothing) ==> const not used
*/
#include <stdio.h>
#include "banned.h" /* include after system header <> includes */
int
main(void)
{

View File

@@ -1,7 +1,7 @@
/*
* have_fpos - Determine if have fgetpos and fsetpos functions
*
* Copyright (C) 1999 Landon Curt Noll
* 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
@@ -31,9 +31,12 @@
* appropriate have_fpos.h file body.
*/
#include <stdio.h>
#include "banned.h" /* include after system header <> includes */
int
main(void)
{

View File

@@ -1,7 +1,7 @@
/*
* have_fpos_pos - Determine if a __pos element in FILEPOS
*
* Copyright (C) 2000 Landon Curt Noll
* Copyright (C) 2000,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
@@ -31,11 +31,14 @@
* __pos element in a non-scalar FILEPOS.
*/
#include <stdio.h>
#include "have_fpos.h"
#include "have_posscl.h"
#include "banned.h" /* include after system header <> includes */
int
main(void)
{

View File

@@ -38,12 +38,17 @@
* undefined ==> do not or cannot call getpgid()
*/
#include <stdio.h>
#include <sys/types.h>
#include "have_unistd.h"
#if defined(HAVE_UNISTD_H)
#include <unistd.h>
#endif
#include "banned.h" /* include after system header <> includes */
int
main(void)
{

View File

@@ -38,13 +38,17 @@
* undefined ==> do not or cannot call getprid()
*/
#include <stdio.h>
#include <sys/types.h>
#include "have_unistd.h"
#if defined(HAVE_UNISTD_H)
#include <unistd.h>
#endif
#include "banned.h" /* include after system header <> includes */
int
main(void)
{

View File

@@ -38,13 +38,17 @@
* undefined ==> do not call or cannot call getsid()
*/
#include <stdio.h>
#include <sys/types.h>
#include "have_unistd.h"
#if defined(HAVE_UNISTD_H)
#include <unistd.h>
#endif
#include "banned.h" /* include after system header <> includes */
int
main(void)
{

View File

@@ -1,7 +1,7 @@
/*
* have_gettime - determine if we have clock_gettime()
*
* Copyright (C) 1999 Landon Curt Noll
* 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
@@ -40,9 +40,13 @@
* CLOCK_SGI_CYCLE and CLOCK_REALTIME
*/
#include <stdio.h>
#include <time.h>
#include "banned.h" /* include after system header <> includes */
int
main(void)
{

View File

@@ -38,9 +38,15 @@
* undefined ==> use internal slow memmove() instead
*/
#include <stdio.h>
#include <string.h>
#include "have_string.h"
#ifdef HAVE_STRING_H
# include <string.h>
#endif
#include "banned.h" /* include after system header <> includes */
#define MOVELEN 3

View File

@@ -40,9 +40,15 @@
* use index() instead of strchr()
*/
#include <stdio.h>
#include <string.h>
#include "have_string.h"
#ifdef HAVE_STRING_H
# include <string.h>
#endif
#include "banned.h" /* include after system header <> includes */
#define MOVELEN 3

View File

@@ -42,7 +42,6 @@
* undefined ==> convert to ZVALUE first
*/
#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
@@ -51,6 +50,10 @@
#include <unistd.h>
#endif
#include "banned.h" /* include after system header <> includes */
int
main(void)
{

View File

@@ -41,7 +41,6 @@
* undefined ==> convert to ZVALUE first
*/
#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
@@ -51,6 +50,10 @@
#endif
#include "have_fpos.h"
#include "banned.h" /* include after system header <> includes */
int
main(void)
{

View File

@@ -1,7 +1,7 @@
/*
* have_rusage - Determine if we have getrusage()
*
* Copyright (C) 1999 Landon Curt Noll
* 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
@@ -38,10 +38,14 @@
* undefined ==> do not call or cannot call getrusage()
*/
#include <stdio.h>
#include <sys/time.h>
#include <sys/resource.h>
#include "banned.h" /* include after system header <> includes */
int
main(void)
{

View File

@@ -1,7 +1,7 @@
/*
* have_stdvs - try <stdarg.h> to see if it really works with vsnprintf()
*
* Copyright (C) 1999,2014,2018 Landon Curt Noll
* Copyright (C) 1999,2014,2018,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
@@ -38,7 +38,6 @@
* include file.
*/
#include <stdio.h>
#include "have_unistd.h"
@@ -65,6 +64,10 @@
# define VSNPRINTF_SIZE_T long
#endif
#include "banned.h" /* include after system header <> includes */
char buf[BUFSIZ+1];

View File

@@ -1,7 +1,7 @@
/*
* have_strdup - determine if we have strdup()
*
* Copyright (C) 1999 Landon Curt Noll
* 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
@@ -38,8 +38,15 @@
* undefined ==> do not call or cannot call strdup()
*/
#include <stdio.h>
#include "have_string.h"
#ifdef HAVE_STRING_H
# include <string.h>
#endif
#include "banned.h" /* include after system header <> includes */
#include <string.h>
int
main(void)

76
have_strlcat.c Normal file
View File

@@ -0,0 +1,76 @@
/*
* have_strlcat - determine if we have strlcat()
*
* Copyright (C) 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: 2021/03/08 20:34:13
* File existed as early as: 2021
*
* chongo <was here> /\oo/\ http://www.isthe.com/chongo/
* Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/
*/
/*
* usage:
* have_strlcat
*
* Not all systems have the strlcat() function, so this may not
* compile on your system.
*
* This prog outputs several defines:
*
* HAVE_STRLCAT
* defined ==> use strlcat()
* undefined ==> do not or cannot call strlcat()
*/
#include <stdio.h>
#include "have_string.h"
#ifdef HAVE_STRING_H
# include <string.h>
#endif
#include "banned.h" /* include after system header <> includes */
#define BUF_SIZ 5
char src[BUF_SIZ+1] = "abcde";
int
main(void)
{
#if defined(HAVE_NO_STRLCAT)
printf("#undef HAVE_STRLCAT /* no */\n");
#else /* HAVE_NO_STRLCAT */
char dst[BUF_SIZ+1+1];
dst[0] = 'S';
dst[1] = '\0';
(void) strlcat(dst, src, sizeof(dst));
printf("#define HAVE_STRLCAT /* yes */\n");
#endif /* HAVE_NO_STRLCAT */
/* exit(0); */
return 0;
}

74
have_strlcpy.c Normal file
View File

@@ -0,0 +1,74 @@
/*
* have_strlcpy - determine if we have strlcpy()
*
* Copyright (C) 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: 2021/03/08 20:34:13
* File existed as early as: 2021
*
* chongo <was here> /\oo/\ http://www.isthe.com/chongo/
* Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/
*/
/*
* usage:
* have_strlcpy
*
* Not all systems have the strlcpy() function, so this may not
* compile on your system.
*
* This prog outputs several defines:
*
* HAVE_STRLCPY
* defined ==> use strlcpy()
* undefined ==> do not or cannot call strlcpy()
*/
#include <stdio.h>
#include "have_string.h"
#ifdef HAVE_STRING_H
# include <string.h>
#endif
#include "banned.h" /* include after system header <> includes */
#define BUF_SIZ (sizeof("abcde")-1)
char src[BUF_SIZ+1] = "abcde";
int
main(void)
{
#if defined(HAVE_NO_STRLCPY)
printf("#undef HAVE_STRLCPY /* no */\n");
#else /* HAVE_NO_STRLCPY */
char dst[BUF_SIZ+1];
(void) strlcpy(dst, src, sizeof(dst));
printf("#define HAVE_STRLCPY /* yes */\n");
#endif /* HAVE_NO_STRLCPY */
/* exit(0); */
return 0;
}

View File

@@ -1,7 +1,7 @@
/*
* have_uid_t - Determine if we want or can support uid_t
*
* Copyright (C) 1999 Landon Curt Noll
* 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
@@ -37,7 +37,6 @@
* undefined ==> do not use uid_t
*/
#include <stdio.h>
#if !defined(HAVE_NO_UID_T)
@@ -49,6 +48,10 @@
#include <sys/types.h>
#endif /* ! HAVE_NO_UID_T */
#include "banned.h" /* include after system header <> includes */
int
main(void)
{

View File

@@ -1,7 +1,7 @@
/*
* have_unused - Determine if we want or can support the unused attribute
*
* Copyright (C) 2004 Landon Curt Noll
* Copyright (C) 2004,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
@@ -42,22 +42,25 @@
* (nothing) ==> unused not used
*/
#include <stdio.h>
#include "banned.h" /* include after system header <> includes */
#if !defined(HAVE_NO_UNUSED)
/* make sure that we can use the __attribute__((unused)) in #define's */
/* make sure that we can use the __attribute__((x)) in #define's */
#undef UNUSED
#define UNUSED __attribute__((unused))
#define UNUSED(x) UNUSED_ ## x __attribute__((unused))
/*
* unused_str - a function with an unused argument
*/
static char *
unused_str(char UNUSED *str)
unused_str(char *UNUSED(str))
{
return "__attribute__((unused))";
return "UNUSED_ ## x __attribute__((unused))";
}
#endif /* !HAVE_NO_UNUSED */
@@ -68,15 +71,17 @@ main(void)
{
#if defined(HAVE_NO_UNUSED)
printf("#undef HAVE_UNUSED /* no */\n");
printf("#undef UNUSED\n");
printf("#define UNUSED /* no */\n");
printf("#if defined(__LCLINT__)\n");
printf("# define UNUSED(x) /*@unused@*/ x\n");
printf("#else\n");
printf("# define UNUSED(x) x\n");
printf("#endif\n");
#else /* HAVE_NO_UNUSED */
printf("#define HAVE_UNUSED /* yes */\n");
printf("#undef UNUSED\n");
printf("#define UNUSED %s /* yes */\n", unused_str(NULL));
printf("#define UNUSED(x) %s\n", unused_str(NULL));
#endif /* HAVE_NO_UNUSED */

View File

@@ -1,7 +1,7 @@
/*
* have_ustat - Determine if we have ustat()
*
* Copyright (C) 1999 Landon Curt Noll
* 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
@@ -38,11 +38,15 @@
* undefined ==> do not call or cannot call ustat()
*/
#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <ustat.h>
#include "banned.h" /* include after system header <> includes */
int
main(void)
{

View File

@@ -1,7 +1,7 @@
/*
* have_varvs - try <varargs.h> to see if it really works with vsnprintf()
*
* Copyright (C) 1999,2018 Landon Curt Noll
* Copyright (C) 1999,2018,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
@@ -35,7 +35,6 @@
* include file.
*/
#include <stdio.h>
#include "have_unistd.h"
@@ -56,10 +55,17 @@
# define VSNPRINTF_SIZE_T long
#endif
#if !defined(STDARG) && !defined(SIMULATE_STDARG)
#include <varargs.h>
#endif
#include "banned.h" /* include after system header <> includes */
char buf[BUFSIZ+1];
#if !defined(STDARG) && !defined(SIMULATE_STDARG)
#include <varargs.h>
void
try_nthis(char *fmt, VSNPRINTF_SIZE_T size, ...)

3
help.c
View File

@@ -45,6 +45,9 @@
#endif
#include "banned.h" /* include after system header <> includes */
/*
* some help topics are symbols, so we alias them to nice filenames
*/

View File

@@ -27,9 +27,28 @@
# calculator by David I. Bell with help/mods from others
# Makefile by Landon Curt Noll
# required vars
# The shell used by this Makefile
#
# On some systems, /bin/sh is a rather reduced shell with
# deprecated behavor.
#
# If your system has a up to date, bash shell, then
# you may wish to use:
#
# SHELL= /bin/bash
#
# On some systems such as macOS, the bash shell is very
# far behind to the point wehre is cannot be depended on.
# On such systems, the zsh may be a much better alternative
# shell for this Makefile to use:
#
# SHELL= /bin/zsh
#
SHELL= /bin/sh
#SHELL= /bin/bash
#SHELL= /bin/zsh
####
# Normally, the upper level makefile will set these values. We provide

14
hist.c
View File

@@ -52,20 +52,26 @@
#include "calc.h"
#include "lib_calc.h"
#include "alloc.h"
#include "hist.h"
#include "have_string.h"
#include "strl.h"
#include "have_strdup.h"
#if !defined(HAVE_STRDUP)
# define strdup(x) calc_strdup((CONST char *)(x))
#endif /* HAVE_STRDUP */
#include "have_string.h"
#ifdef HAVE_STRING_H
# include <string.h>
#endif
#include "have_unused.h"
#include "banned.h" /* include after system header <> includes */
#if !defined(USE_READLINE)
E_FUNC FILE *curstream(void);
@@ -1490,7 +1496,7 @@ hist_getline(char *prompt, char *buf, size_t len)
/*NOTREACHED*/
}
}
strncpy(buf, line, len - 1);
strlcpy(buf, line, len);
buf[len - 2] = '\0';
len = strlen(buf);
buf[len] = '\n';
@@ -1518,7 +1524,7 @@ my_stifle_history (void)
int
hist_init(char UNUSED *filename)
hist_init(char *UNUSED(filename))
{
/* used when parsing conditionals in ~/.inputrc */
rl_readline_name = "calc";
@@ -1570,7 +1576,7 @@ hist_saveline(char *line, int len)
/*
* Main routine to test history.
*/
void
int
main(int argc, char **argv)
{
char *filename;

54
input.c
View File

@@ -1,7 +1,7 @@
/*
* input - nested input source file reader
*
* Copyright (C) 1999-2007,2014,2018 David I. Bell
* Copyright (C) 1999-2007,2014,2018,2021 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
@@ -53,6 +53,11 @@
#include "calc.h"
#include "conf.h"
#include "hist.h"
#include "strl.h"
#include "banned.h" /* include after system header <> includes */
EXTERN int stdin_tty; /* TRUE if stdin is a tty */
E_FUNC FILE *f_open(char *name, char *mode);
@@ -135,6 +140,7 @@ opensearchfile(char *name, char *pathlist, char *extension, int rd_once)
int i;
char *cp;
char *path; /* name being searched for */
size_t path_alloc; /* length of malloced path */
struct stat statbuf; /* stat of the path */
size_t namelen; /* length of name */
size_t extlen; /* length of the extension if non-NULL or 0 */
@@ -181,11 +187,14 @@ opensearchfile(char *name, char *pathlist, char *extension, int rd_once)
extlen = 0;
}
pathlen = strlen(pathlist);
path = malloc(pathlen+1 + 1 + namelen+1 + extlen+1 + 1 + 1);
path_alloc = pathlen+1 + 1 + namelen+1 + extlen+1 + 1 + 1;
path = malloc(path_alloc+1);
if (path == NULL) {
math_error("Cannot allocate filename path buffer");
/*NOTREACHED*/
}
path[0] = '\0'; /* paranoia */
path[path_alloc] = '\0'; /* paranoia */
/*
* Don't try the extension if the filename already contains it.
@@ -206,11 +215,11 @@ opensearchfile(char *name, char *pathlist, char *extension, int rd_once)
*cp++ = *pathlist++;
if (cp != path)
*cp++ = PATHCHAR;
strncpy(cp, name, namelen+1);
strlcpy(cp, name, namelen+1);
i = openfile(path);
if ((i < 0) &&
(extension != NULL && extension[0] != '\0')) {
strcat(path, extension);
strlcat(path, extension, path_alloc+1);
i = openfile(path);
}
} while ((i < 0) && *pathlist);
@@ -348,7 +357,7 @@ f_pathopen(char *name, char *mode, char *pathlist, char **openpath)
*cp++ = *pathlist++;
if (cp != path)
*cp++ = PATHCHAR;
strncpy(cp, name, namelen+1);
strlcpy(cp, name, namelen+1);
ret = f_open(path, mode);
} while ((ret == NULL) && *pathlist);
@@ -442,23 +451,7 @@ homeexpand(char *name)
if (fullpath == NULL) {
return NULL;
}
/*
* The next statement could be:
*
* strncpy(fullpath, ent->pw_dir, fullpath_len);
*
* however compilers like gcc would issue warnings
* such as:
*
* specified bound depends on the length of the
* source argument
*
* even though we terminate the string by setting a NUL
* byte following the copy. Therefore we call memcpy()
* instead to avoid such warnings.
*/
memcpy(fullpath, ent->pw_dir, fullpath_len);
fullpath[fullpath_len] = '\0';
strlcpy(fullpath, ent->pw_dir, fullpath_len+1);
return fullpath;
}
username = (char *) malloc(after-name + 1 + 1);
@@ -466,8 +459,7 @@ homeexpand(char *name)
/* failed to malloc username */
return NULL;
}
strncpy(username, name+1, after-name-1);
username[after-name-1] = '\0';
strlcpy(username, name+1, after-name+1+1);
/* get that user's home directory */
ent = (struct passwd *)getpwnam(username);
@@ -587,7 +579,7 @@ openfile(char *name)
if (cip->i_name == NULL) {
return -1;
}
strncpy(cip->i_name, name, namelen+1);
strlcpy(cip->i_name, name, namelen+1);
return 0;
}
@@ -623,8 +615,7 @@ openstring(char *str, size_t num)
cp = (char *) malloc(num + 1);
if (cp == NULL)
return -1;
strncpy(cp, str, num);
cp[num] = '\0'; /* firewall */
strlcpy(cp, str, num+1);
cip = inputs + depth++;
cip->i_state = IS_READ;
cip->i_char = '\0';
@@ -946,10 +937,9 @@ runrcfiles(void)
/* load file name into the path */
if (calcrc == NULL) {
strncpy(path, cp, MAX_CALCRC+1);
strlcpy(path, cp, MAX_CALCRC+1);
} else {
strncpy(path, cp, calcrc - cp);
path[calcrc - cp] = '\0';
strlcpy(path, cp, calcrc - cp + 1);
}
/* find the start of the path */
@@ -1129,7 +1119,7 @@ addreadset(char *name, char *path, struct stat *sbuf)
if (readset[ret].name == NULL) {
return -1;
}
strncpy(readset[ret].name, name, name_len+1);
strlcpy(readset[ret].name, name, name_len+1);
#if defined(_WIN32) || defined(__MSDOS__)
/*
* For WIN32, _fullpath expands the path to a fully qualified
@@ -1149,7 +1139,7 @@ addreadset(char *name, char *path, struct stat *sbuf)
if (readset[ret].path == NULL) {
return -1;
}
strncpy(readset[ret].path, path, path_len+1);
strlcpy(readset[ret].path, path, path_len+1);
#endif /* Windoz free systems */
readset[ret].inode = *sbuf;
readset[ret].active = 1;

6
jump.c
View File

@@ -1,7 +1,7 @@
/*
* jump - trivial prime jump table
*
* Copyright (C) 1999 Landon Curt Noll
* 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
@@ -50,6 +50,10 @@
#include "jump.h"
#include "banned.h" /* include after system header <> includes */
/*
* jmpindx - how to find the next value not divisible by a trivial prime
*

View File

@@ -1,7 +1,7 @@
/*
* label - label handling routines
*
* Copyright (C) 1999-2007 David I. Bell
* Copyright (C) 1999-2007,2021 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
@@ -31,6 +31,10 @@
#include "opcodes.h"
#include "func.h"
#include "banned.h" /* include after system header <> includes */
STATIC long labelcount; /* number of user labels defined */
STATIC STRINGHEAD labelnames; /* list of user label names */
STATIC LABEL labels[MAXLABELS]; /* list of user labels */

View File

@@ -41,6 +41,7 @@
#include "token.h"
#include "symbol.h"
#include "func.h"
#include "strl.h"
#if defined(CUSTOM)
#include "custom.h"
@@ -92,6 +93,10 @@ typedef struct {int fd;} ttystruct;
# endif
#endif /* Windoz */
#include "banned.h" /* include after system header <> includes */
/*
* in case we do not have certain .h files
*/
@@ -692,7 +697,7 @@ calc_strdup(CONST char *s1)
* if we have storage, duplicate the string
*/
if (ret != NULL) {
strncpy(ret, s1, s1_len+1);
strlcpy(ret, s1, s1_len+1);
}
/*

View File

@@ -31,9 +31,13 @@
#include "zmath.h"
#include "alloc.h"
#include "lib_util.h"
#include "banned.h" /* include after system header <> includes */
/*
* lowhex2bin - quick low order ASCII hex to binary conversion
*

View File

@@ -1,7 +1,7 @@
/*
* listfunc - list handling routines
*
* Copyright (C) 1999-2007 David I. Bell
* Copyright (C) 1999-2007,2021 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
@@ -36,6 +36,10 @@
#include "value.h"
#include "zrand.h"
#include "banned.h" /* include after system header <> includes */
E_FUNC long irand(long s);
S_FUNC LISTELEM *elemalloc(void);

View File

@@ -1,7 +1,7 @@
/*
* longbits - Determine the number if bits in a char, short, int or long
*
* Copyright (C) 1999-2007,2014 Landon Curt Noll
* Copyright (C) 1999-2007,2014,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
@@ -92,6 +92,10 @@
# include <stdlib.h>
#endif
#include "banned.h" /* include after system header <> includes */
char *program; /* our name */
int

View File

@@ -28,12 +28,17 @@
* Matrices can contain arbitrary types of elements.
*/
#include "alloc.h"
#include "value.h"
#include "zrand.h"
#include "calcerr.h"
#include "have_unused.h"
#include "banned.h" /* include after system header <> includes */
E_FUNC long irand(long s);
S_FUNC void matswaprow(MATRIX *m, long r1, long r2);
@@ -851,7 +856,7 @@ matfrac(MATRIX *m)
*/
/*ARGSUSED*/
VALUE *
matindex(MATRIX *mp, BOOL UNUSED create, long dim, VALUE *indices)
matindex(MATRIX *mp, BOOL UNUSED(create), long dim, VALUE *indices)
{
NUMBER *q; /* index value */
VALUE *vp;

View File

@@ -65,6 +65,9 @@
#include "lib_calc.h"
#include "banned.h" /* include after system header <> includes */
/*
* math_error - print a math error and exit
*/

15
obj.c
View File

@@ -1,7 +1,7 @@
/*
* obj - object handling primitives
*
* Copyright (C) 1999-2007 David I. Bell
* Copyright (C) 1999-2007,2021 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
@@ -35,6 +35,10 @@
#include "func.h"
#include "symbol.h"
#include "str.h"
#include "strl.h"
#include "banned.h" /* include after system header <> includes */
/*
@@ -210,6 +214,9 @@ objcall(int action, VALUE *v1, VALUE *v2, VALUE *v3)
char *namestr_ret; /* namestr() return string */
size_t opi_name_len; /* length of the oip name */
/* initilaize name */
memset(name, 0, sizeof(name));
/* initialize VALUEs */
val.v_subtype = V_NOSUBTYPE;
tmp.v_subtype = V_NOSUBTYPE;
@@ -241,9 +248,9 @@ objcall(int action, VALUE *v1, VALUE *v2, VALUE *v3)
/*NOTREACHED*/
}
name[0] = '\0';
strncpy(name, namestr_ret, namestr_len+1);
strcat(name, "_");
strncat(name, oip->name, opi_name_len+1);
strlcpy(name, namestr_ret, namestr_len+1);
strlcat(name, "_", sizeof(name));
strlcat(name, oip->name, sizeof(name));
index = adduserfunc(name);
oap->oa_indices[action] = index;
}

View File

@@ -1,7 +1,7 @@
/*
* opcodes - opcode execution module
*
* Copyright (C) 1999-2007 David I. Bell and Ernest Bowen
* Copyright (C) 1999-2007,2021 David I. Bell and Ernest Bowen
*
* Primary author: David I. Bell
*
@@ -46,6 +46,10 @@
#include "have_unused.h"
#include "banned.h" /* include after system header <> includes */
#define QUICKLOCALS 20 /* local vars to handle quickly */
@@ -161,7 +165,7 @@ o_localaddr(FUNC *fp, VALUE *locals, long index)
/*ARGSUSED*/
S_FUNC void
o_globaladdr(FUNC UNUSED *fp, GLOBAL *sp)
o_globaladdr(FUNC *UNUSED(fp), GLOBAL *sp)
{
if (sp == NULL) {
math_error("Global variable \"%s\" not initialized",
@@ -177,7 +181,7 @@ o_globaladdr(FUNC UNUSED *fp, GLOBAL *sp)
/*ARGSUSED*/
S_FUNC void
o_paramaddr(FUNC UNUSED *fp, int argcount, VALUE *args, long index)
o_paramaddr(FUNC *UNUSED(fp), int argcount, VALUE *args, long index)
{
if ((long)index >= argcount) {
math_error("Bad parameter index");
@@ -209,7 +213,7 @@ o_localvalue(FUNC *fp, VALUE *locals, long index)
/*ARGSUSED*/
S_FUNC void
o_globalvalue(FUNC UNUSED *fp, GLOBAL *sp)
o_globalvalue(FUNC *UNUSED(fp), GLOBAL *sp)
{
if (sp == NULL) {
math_error("Global variable not defined");
@@ -221,7 +225,7 @@ o_globalvalue(FUNC UNUSED *fp, GLOBAL *sp)
/*ARGSUSED*/
S_FUNC void
o_paramvalue(FUNC UNUSED *fp, int argcount, VALUE *args, long index)
o_paramvalue(FUNC *UNUSED(fp), int argcount, VALUE *args, long index)
{
if ((long)index >= argcount) {
math_error("Bad parameter index");
@@ -266,7 +270,7 @@ o_argvalue(FUNC *fp, int argcount, VALUE *args)
/*ARGSUSED*/
S_FUNC void
o_number(FUNC UNUSED *fp, long arg)
o_number(FUNC *UNUSED(fp), long arg)
{
NUMBER *q;
@@ -284,7 +288,7 @@ o_number(FUNC UNUSED *fp, long arg)
/*ARGSUSED*/
S_FUNC void
o_imaginary(FUNC UNUSED *fp, long arg)
o_imaginary(FUNC *UNUSED(fp), long arg)
{
NUMBER *q;
COMPLEX *c;
@@ -311,7 +315,7 @@ o_imaginary(FUNC UNUSED *fp, long arg)
/*ARGSUSED*/
S_FUNC void
o_string(FUNC UNUSED *fp, long arg)
o_string(FUNC *UNUSED(fp), long arg)
{
stack++;
stack->v_str = slink(findstring(arg));
@@ -331,7 +335,7 @@ o_undef(void)
/*ARGSUSED*/
S_FUNC void
o_matcreate(FUNC UNUSED *fp, long dim)
o_matcreate(FUNC *UNUSED(fp), long dim)
{
register MATRIX *mp; /* matrix being defined */
NUMBER *num1; /* first number from stack */
@@ -399,7 +403,7 @@ o_matcreate(FUNC UNUSED *fp, long dim)
/*ARGSUSED*/
S_FUNC void
o_eleminit(FUNC UNUSED *fp, long index)
o_eleminit(FUNC *UNUSED(fp), long index)
{
VALUE *vp;
STATIC VALUE *oldvp;
@@ -540,7 +544,7 @@ o_eleminit(FUNC UNUSED *fp, long index)
*/
/*ARGSUSED*/
S_FUNC void
o_indexaddr(FUNC UNUSED *fp, long dim, long writeflag)
o_indexaddr(FUNC *UNUSED(fp), long dim, long writeflag)
{
int i;
BOOL flag;
@@ -693,7 +697,7 @@ o_indexaddr(FUNC UNUSED *fp, long dim, long writeflag)
/*ARGSUSED*/
S_FUNC void
o_elemaddr(FUNC UNUSED *fp, long index)
o_elemaddr(FUNC *UNUSED(fp), long index)
{
VALUE *vp;
MATRIX *mp;
@@ -748,7 +752,7 @@ o_elemvalue(FUNC *fp, long index)
/*ARGSUSED*/
S_FUNC void
o_objcreate(FUNC UNUSED *fp, long arg)
o_objcreate(FUNC *UNUSED(fp), long arg)
{
stack++;
stack->v_type = V_OBJ;
@@ -2558,7 +2562,7 @@ o_return(void)
/*ARGSUSED*/
S_FUNC void
o_jumpz(FUNC UNUSED *fp, BOOL *dojump)
o_jumpz(FUNC *UNUSED(fp), BOOL *dojump)
{
VALUE *vp;
int i; /* result of comparison */
@@ -2582,7 +2586,7 @@ o_jumpz(FUNC UNUSED *fp, BOOL *dojump)
/*ARGSUSED*/
S_FUNC void
o_jumpnz(FUNC UNUSED *fp, BOOL *dojump)
o_jumpnz(FUNC *UNUSED(fp), BOOL *dojump)
{
VALUE *vp;
int i; /* result of comparison */
@@ -2609,7 +2613,7 @@ o_jumpnz(FUNC UNUSED *fp, BOOL *dojump)
*/
/*ARGSUSED*/
S_FUNC void
o_jumpnn(FUNC UNUSED *fp, BOOL *dojump)
o_jumpnn(FUNC *UNUSED(fp), BOOL *dojump)
{
if (stack->v_addr->v_type) {
*dojump = TRUE;
@@ -2620,7 +2624,7 @@ o_jumpnn(FUNC UNUSED *fp, BOOL *dojump)
/*ARGSUSED*/
S_FUNC void
o_condorjump(FUNC UNUSED *fp, BOOL *dojump)
o_condorjump(FUNC *UNUSED(fp), BOOL *dojump)
{
VALUE *vp;
@@ -2646,7 +2650,7 @@ o_condorjump(FUNC UNUSED *fp, BOOL *dojump)
/*ARGSUSED*/
S_FUNC void
o_condandjump(FUNC UNUSED *fp, BOOL *dojump)
o_condandjump(FUNC *UNUSED(fp), BOOL *dojump)
{
VALUE *vp;
@@ -2677,7 +2681,7 @@ o_condandjump(FUNC UNUSED *fp, BOOL *dojump)
*/
/*ARGSUSED*/
S_FUNC void
o_casejump(FUNC UNUSED *fp, BOOL *dojump)
o_casejump(FUNC *UNUSED(fp), BOOL *dojump)
{
VALUE *v1, *v2;
int r;
@@ -2699,7 +2703,7 @@ o_casejump(FUNC UNUSED *fp, BOOL *dojump)
/*ARGSUSED*/
S_FUNC void
o_jump(FUNC UNUSED *fp, BOOL *dojump)
o_jump(FUNC *UNUSED(fp), BOOL *dojump)
{
*dojump = TRUE;
}
@@ -2719,7 +2723,7 @@ o_usercall(FUNC *fp, long index, long argcount)
/*ARGSUSED*/
S_FUNC void
o_call(FUNC UNUSED *fp, long index, long argcount)
o_call(FUNC *UNUSED(fp), long index, long argcount)
{
VALUE result;
@@ -3101,7 +3105,7 @@ o_rightshift(void)
/*ARGSUSED*/
S_FUNC void
o_debug(FUNC UNUSED *fp, long line)
o_debug(FUNC *UNUSED(fp), long line)
{
funcline = line;
if (abortlevel >= ABORT_STATEMENT) {
@@ -3142,7 +3146,7 @@ o_printresult(void)
/*ARGSUSED*/
S_FUNC void
o_print(FUNC UNUSED *fp, long flags)
o_print(FUNC *UNUSED(fp), long flags)
{
VALUE *vp;
@@ -3176,7 +3180,7 @@ o_printspace(void)
/*ARGSUSED*/
S_FUNC void
o_printstring(FUNC UNUSED *fp, long index)
o_printstring(FUNC *UNUSED(fp), long index)
{
STRING *s;
char *cp;

5
pix.c
View File

@@ -1,7 +1,7 @@
/*
* pix - number of primes less than a small value
*
* Copyright (C) 1999 Landon Curt Noll
* 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
@@ -30,6 +30,9 @@
#include "have_const.h"
#include "banned.h" /* include after system header <> includes */
/*
* pi10b - number of primes <= 2^18 in multiples of 2^10
*

5
poly.c
View File

@@ -1,7 +1,7 @@
/*
* poly - polynomial functions
*
* Copyright (C) 1999 Ernest Bowen and Landon Curt Noll
* Copyright (C) 1999,2021 Ernest Bowen and Landon Curt Noll
*
* Primary author: Ernest Bowen
*
@@ -30,6 +30,9 @@
#include "value.h"
#include "banned.h" /* include after system header <> includes */
BOOL
evp(LISTELEM *cp, LISTELEM *x, VALUE *vres)
{

View File

@@ -1,7 +1,7 @@
/*
* prime - quickly determine if a small number is prime
*
* Copyright (C) 1999-2007 Landon Curt Noll
* Copyright (C) 1999-2007,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
@@ -31,6 +31,9 @@
#include "have_const.h"
#include "banned.h" /* include after system header <> includes */
/*
* odd prime bitmap for odd values < 2^16
*

View File

@@ -30,6 +30,10 @@
#include "config.h"
#include "prime.h"
#include "banned.h" /* include after system header <> includes */
STATIC NUMBER **B_table;
STATIC long B_num;
STATIC long B_allocnum;

7
qio.c
View File

@@ -1,7 +1,7 @@
/*
* qio - scanf and printf routines for arbitrary precision rational numbers
*
* Copyright (C) 1999-2007 David I. Bell
* Copyright (C) 1999-2007,2021 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
@@ -31,6 +31,9 @@
#include "have_unused.h"
#include "banned.h" /* include after system header <> includes */
#define PUTCHAR(ch) math_chr(ch)
#define PUTSTR(str) math_str(str)
#define PRINTF1(fmt, a1) math_fmt(fmt, a1)
@@ -322,7 +325,7 @@ qprintff(NUMBER *q, long width, long precision)
*/
/*ARGSUSED*/
void
qprintfe(NUMBER *q, long UNUSED width, long precision)
qprintfe(NUMBER *q, long UNUSED(width), long precision)
{
long exponent;
NUMBER q2;

View File

@@ -31,6 +31,9 @@
#include "config.h"
#include "banned.h" /* include after system header <> includes */
NUMBER _qzero_ = { { _zeroval_, 1, 0 }, { _oneval_, 1, 0 }, 1, NULL };
NUMBER _qone_ = { { _oneval_, 1, 0 }, { _oneval_, 1, 0 }, 1, NULL };
NUMBER _qtwo_ = { { _twoval_, 1, 0 }, { _oneval_, 1, 0 }, 1, NULL };

5
qmod.c
View File

@@ -1,7 +1,7 @@
/*
* qmod - modular arithmetic routines for normal numbers and REDC numbers
*
* Copyright (C) 1999-2007 David I. Bell and Ernest Bowen
* Copyright (C) 1999-2007,2021 David I. Bell and Ernest Bowen
*
* Primary author: David I. Bell
*
@@ -31,6 +31,9 @@
#include "config.h"
#include "banned.h" /* include after system header <> includes */
/*
* Structure used for caching REDC information.
*/

View File

@@ -33,6 +33,10 @@
#include "qmath.h"
#include "banned.h" /* include after system header <> includes */
HALF _qlgenum_[] = { 36744 };
HALF _qlgeden_[] = { 25469 };
NUMBER _qlge_ = { { _qlgenum_, 1, 0 }, { _qlgeden_, 1, 0 }, 1, NULL };

View File

@@ -39,6 +39,10 @@
#include "zrand.h"
#include "zrandom.h"
#include "banned.h" /* include after system header <> includes */
/*
* forward declarations
*/

30
rpm.mk
View File

@@ -106,11 +106,30 @@ TMPDIR= ${RPM_TOP}/tmp
# Q=@ do not echo internal Makefile actions (quiet mode)
# Q= echo internal Makefile actions (debug / verbose mode)
#
# H=@: do not report hsrc file formation progress
# H=@ do echo hsrc file formation progress
#
# S= >/dev/null 2>&1 slience ${CC} output during hsrc file formation
# S= full ${CC} output during hsrc file formation
#
# E= 2>/dev/null slience command stderr during hsrc file formation
# E= full command stderr during hsrc file formation
#
# V=@: do not echo debug statements (quiet mode)
# V=@ do echo debug statements (debug / verbose mode)
#
#Q=
Q=@
#
S= >/dev/null 2>&1
#S=
#
E= 2>/dev/null
#E=
#
#H=@:
H=@
#
V=@:
#V=@
@@ -121,20 +140,20 @@ all: ver_calc calc.spec
-e '/^Release:/s/^Release: *//p' calc.spec.in`"; \
$(MAKE) -f rpm.mk rpm \
PROJECT_VERSION="$$PROJECT_VERSION" \
PROJECT_RELEASE="$$PROJECT_RELEASE"
PROJECT_RELEASE="$$PROJECT_RELEASE" Q= S= E=
${V} echo '=-=-=-=-= rpm.mk end of $@ rule =-=-=-=-='
pkgme: $(PROJECT_NAME)-spec.${TAR}.bz2
ver_calc:
${V} echo '=-=-=-=-= rpm.mk start of $@ rule =-=-=-=-='
$(MAKE) -f Makefile ver_calc
$(MAKE) -f Makefile ver_calc Q= S= E=
${V} echo '=-=-=-=-= rpm.mk end of $@ rule =-=-=-=-='
.PHONY: vers
vers:
${V} echo '=-=-=-=-= rpm.mk start of $@ rule =-=-=-=-='
$(MAKE) -f Makefile ver_calc
$(MAKE) -f Makefile ver_calc Q= S= E=
${V} echo '=-=-=-=-= rpm.mk end of $@ rule =-=-=-=-='
calc.spec: calc.spec.in ver_calc
@@ -174,7 +193,7 @@ rpm: srcpkg calc.spec
${V} echo RPM_BUILD_ROOT="${RPM_BUILD_ROOT}"
${V} echo PROJECT_VERSION="${PROJECT_VERSION}"
${V} echo PROJECT_RELEASE="${PROJECT_RELEASE}"
$(MAKE) -f Makefile clean
$(MAKE) -f Makefile clean Q= S= E=
${CP} "$(SPECFILE)" "$(RPM_TOP)/SPECS/$(SPECFILE)"
${RM} -f "$(RPM_TOP)/RPMS/$(TARCH)/$(RPMx86_64)"
${RM} -f "$(RPM_TOP)/RPMS/$(TARCH)/$(DRPMx86_64)"
@@ -270,7 +289,8 @@ test: ver_calc
echo "test needs to install, must be root to test" 1>&2; \
exit 6; \
fi
$(MAKE) -f rpm.mk PROJECT_VERSION="`./ver_calc`" installrpm chksys
$(MAKE) -f rpm.mk PROJECT_VERSION="`./ver_calc`" installrpm \
chksys Q= S= E=
${V} echo '=-=-=-=-= rpm.mk end of $@ rule =-=-=-=-='
.PHONY: installrpm

View File

@@ -1,7 +1,7 @@
/*
* sample_many - generate many random values via random number generator
*
* Copyright (C) 1999-2007 Landon Curt Noll
* Copyright (C) 1999-2007,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
@@ -40,6 +40,10 @@
#include "have_const.h"
#include "lib_util.h"
#include "banned.h" /* include after system header <> includes */
#define DEF_CNT 128 /* default number of bits to generate */
#define RESEED 1000 /* number of random numbers to generate */
#define MANY 100 /* number of random numbers to generate */

View File

@@ -1,7 +1,7 @@
/*
* sample_rand - test the libcalc random number generator
*
* Copyright (C) 1999-2007 Landon Curt Noll
* Copyright (C) 1999-2007,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
@@ -40,6 +40,10 @@
#include "have_const.h"
#include "lib_util.h"
#include "banned.h" /* include after system header <> includes */
#define DEF_CNT 128 /* default number of bits to generate */
extern char *program; /* our name */

4
seed.c
View File

@@ -79,6 +79,7 @@
# include <sys/resource.h>
#endif
#include <setjmp.h>
#include "alloc.h"
#include "qmath.h"
#include "longbits.h"
#include "have_ustat.h"
@@ -99,6 +100,9 @@
#endif
#include "banned.h" /* include after system header <> includes */
/*
* 64 bit hash value
*/

4
sha1.c
View File

@@ -27,6 +27,7 @@
#include <stdio.h>
#include "alloc.h"
#include "longbits.h"
#include "align32.h"
#include "endian_calc.h"
@@ -35,6 +36,9 @@
#include "sha1.h"
#include "banned.h" /* include after system header <> includes */
/*
* The SHA1 f()-functions. The f1 and f3 functions can be optimized
* to save one boolean operation each - thanks to Rich Schroeppel,

5
size.c
View File

@@ -1,7 +1,7 @@
/*
* size - size and sizeof functions are implemented here
*
* Copyright (C) 1999-2007 David I. Bell
* Copyright (C) 1999-2007,2021 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
@@ -30,6 +30,9 @@
#include "block.h"
#include "banned.h" /* include after system header <> includes */
/*
* forward declarations
*/

28
str.c
View File

@@ -1,7 +1,7 @@
/*
* str - string list routines
*
* Copyright (C) 1999-2007 David I. Bell and Ernest Bowen
* Copyright (C) 1999-2007,2021 David I. Bell and Ernest Bowen
*
* Primary author: David I. Bell
*
@@ -28,12 +28,22 @@
#include <stdio.h>
#include <ctype.h>
#include "have_string.h"
#ifdef HAVE_STRING_H
# include <string.h>
#endif
#include "calc.h"
#include "alloc.h"
#include "str.h"
#include "strl.h"
#include "banned.h" /* include after system header <> includes */
#define STR_TABLECHUNK 100 /* how often to reallocate string table */
#define STR_CHUNK 2000 /* size of string storage allocation */
#define STR_UNIQUE 100 /* size of string to allocate separately */
#define STR_CHUNK (1<<11) /* size of string storage allocation */
#define STR_UNIQUE (1<<7) /* size of string to allocate separately */
STRING _nullstring_ = {"", 0, 1, NULL};
@@ -107,7 +117,7 @@ addstr(STRINGHEAD *hp, char *str)
hp->h_used += len;
hp->h_avail -= len;
hp->h_count++;
strcpy(retstr, str);
strlcpy(retstr, str, len);
retstr[len] = '\0';
return retstr;
}
@@ -279,15 +289,19 @@ addliteral(char *str)
table = literals.l_table;
/*
* If the new string is very long, allocate it manually.
*
* Add room for trailing NUL and then round up to a
* memory chunk (in this case we pick the size of a FULL
* just because that is a nice size) for extra padded room.
*/
len = (len + 2) & ~1; /* add room for null and round up to word */
len = ROUNDUP(len+1, FULL_LEN);
if (len >= STR_UNIQUE) {
newstr = (char *)malloc(len);
if (newstr == NULL) {
math_error("Cannot allocate large literal string");
/*NOTREACHED*/
}
strcpy(newstr, str);
strlcpy(newstr, str, len);
table[literals.l_count++] = newstr;
return newstr;
}
@@ -311,7 +325,7 @@ addliteral(char *str)
literals.l_avail -= len;
literals.l_alloc += len;
table[literals.l_count++] = newstr;
strcpy(newstr, str);
strlcpy(newstr, str, len);
return newstr;
}

9
str.h
View File

@@ -24,8 +24,8 @@
*/
#if !defined(INCLUDE_CALCSTRING_H)
#define INCLUDE_CALCSTRING_H
#if !defined(INCLUDE_STR_H)
#define INCLUDE_STR_H
#if defined(CALC_SRC) /* if we are building from the calc source tree */
@@ -35,6 +35,7 @@
#endif
struct string {
char *s_str;
size_t s_len;
@@ -52,6 +53,7 @@ typedef struct {
long h_count; /* number of strings */
} STRINGHEAD;
EXTERN STRING _nullstring_;
E_FUNC void initstr(STRINGHEAD *hp);
E_FUNC char *addstr(STRINGHEAD *hp, char *str);
@@ -72,7 +74,6 @@ E_FUNC void fitstring(char *, long, long);
E_FUNC void strprint(STRING *);
E_FUNC void showstrings(void);
E_FUNC void showliterals(void);
EXTERN STRING _nullstring_;
#endif /* !INCLUDE_CALCSTRING_H */
#endif /* !INCLUDE_STR_H */

301
strl.c Normal file
View File

@@ -0,0 +1,301 @@
/*
* strl - size-bounded string copying and concatenation
*
* Copyright (C) 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: 2021/03/08 21;58:10
* File existed as early as: 2021
*
* Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/
*/
#include "have_string.h"
#ifdef HAVE_STRING_H
# include <string.h>
#endif
#include "strl.h"
#include "alloc.h"
#if defined(STRL_TEST)
#include <stdio.h>
#include <stdlib.h>
#endif /* STRL_TEST */
#include "banned.h" /* include after system header <> includes */
#if !defined(HAVE_STRLCPY) || defined(STRL_TEST)
/*
* calc_strlcpy - calc STRL_TEST test version of strlcpy
* strlcpy - size-bounded string copying
*
* The strlcpy() functions copies up to dstsize-1 characters from the
* string src to dst, NUL-terminating the result if dstsize > 0.
*
* This function attempts to simulate strlcpy() on systems that
* do not have this function in their C library.
*
* given:
* dst destination string
* src source string
* dstsize size of the destination string buffer including NUL
*
* returns:
* total length of source string excluding NUL,
* 0 ==> invalid arguments
*
* NOTE: If return value is >= dstsize, the result was truncated.
* I.e., there was not enough room in dst and so the copy
* was stopped before it would have overflowed and was NUL terminated.
*/
#if defined(STRL_TEST)
size_t
calc_strlcpy(char * dst, const char * src, size_t dstsize)
#else /* STRL_TEST */
size_t
strlcpy(char * dst, const char * src, size_t dstsize)
#endif /* STRL_TEST */
{
size_t srclen; /* src string length not including NUL */
/*
* firewall
*/
if (dst == NULL || src == NULL || dstsize <= 0) {
/* nothing can be copied */
#if defined(STRL_TEST)
printf("in %s: return 0\n", __FUNCTION__);
#endif /* STRL_TEST */
return 0;
}
/*
* determine how much string we could copy
*/
srclen = strlen(src);
/*
* perform the size limited copy and NUL terminate
*/
if (srclen > dstsize-1) {
memcpy(dst, src, dstsize-1);
dst[dstsize-1] = '\0';
#if defined(STRL_TEST)
printf("in %s: if memcpy(\"%s\", \"%s\", %zu)\n",
__FUNCTION__, dst, src, dstsize-1);
#endif /* STRL_TEST */
} else {
memcpy(dst, src, srclen);
dst[srclen] = '\0';
#if defined(STRL_TEST)
printf("in %s: else memcpy(\"%s\", \"%s\", %zu)\n",
__FUNCTION__, dst, src, srclen);
#endif /* STRL_TEST */
}
/*
* return the length we tried to copy, not including NUL
*/
#if defined(STRL_TEST)
printf("in %s: return %zu\n", __FUNCTION__, srclen);
#endif /* STRL_TEST */
return srclen;
}
#endif /* !HAVE_STRLCPY || STRL_TEST */
#if !defined(HAVE_STRLCAT) || defined(STRL_TEST)
/*
* calc_strlcat - calc STRL_TEST test version of strlcat
* strlcat - size-bounded string cat
*
* The strlcat() appends string src to the end of dst.
* At most, dstsize - strlen(dst) - 1 characters will of appended.
*
* This function attempts to simulate strlcat() on systems that
* do not have this function in their C library.
*
* given:
* dst destination string
* src source string
* dstsize size of the destination string buffer including NUL
*
* returns:
* total length of string could have been copied excluding NUL,
* 0 ==> invalid arguments
*
* NOTE: If return value is >= dstsize, the output string was truncated.
* I.e., there was not enough room and so the result was truncated
* and NUL terminated.
*/
#if defined(STRL_TEST)
size_t
calc_strlcat(char * dst, const char * src, size_t dstsize)
#else /* STRL_TEST */
size_t
strlcat(char * dst, const char * src, size_t dstsize)
#endif /* STRL_TEST */
{
size_t srclen; /* src string length not including NUL */
size_t dstlen; /* dst string length not including NUL */
size_t catlen; /* amount from src we can copy */
/*
* firewall
*/
if (dst == NULL || src == NULL || dstsize <= 0) {
/* nothing can be concatinated */
#if defined(STRL_TEST)
printf("in %s: return 0\n", __FUNCTION__);
#endif /* STRL_TEST */
return 0;
}
/*
* prep to determine the room we have
*/
dstlen = strlen(dst);
srclen = strlen(src);
#if defined(STRL_TEST)
printf("in %s: dst = ((%s)) src = ((%s)) dstsize = %zu\n",
__FUNCTION__, dst, src, dstsize);
printf("in %s: dstlen = %zu srclen = %zu\n",
__FUNCTION__, dstlen, srclen);
#endif /* STRL_TEST */
if (dstsize <= dstlen+1) {
/* dst is already full */
#if defined(STRL_TEST)
printf("in %s: dstsize: %zu <= dstlen+1: %zu\n",
__FUNCTION__, dstsize, dstlen+1);
printf("in %s: already full return %zu\n",
__FUNCTION__, srclen+dstlen);
#endif /* STRL_TEST */
return srclen+dstlen;
}
/*
* determine the amount data we can copy
*/
catlen = dstsize - dstlen;
/*
* perform the cancatimation
*/
dst += dstlen;
#if defined(STRL_TEST)
printf("in %s: catlen = %zu\n", __FUNCTION__, catlen);
#endif /* STRL_TEST */
if (catlen > srclen+1) {
memcpy(dst, src, srclen);
dst[srclen] = '\0';
#if defined(STRL_TEST)
printf("in %s: if memcpy(\"%s\", \"%s\", %zu)\n",
__FUNCTION__, dst, src, srclen);
#endif /* STRL_TEST */
} else {
memcpy(dst, src, catlen);
dst[catlen] = '\0';
#if defined(STRL_TEST)
printf("in %s: if memcpy(\"%s\", \"%s\", %zu)\n",
__FUNCTION__, dst, src, catlen);
#endif /* STRL_TEST */
}
/*
* return the length, not including NUL, of what could have been formed
*/
#if defined(STRL_TEST)
printf("in %s: return %zu\n", __FUNCTION__, srclen+dstlen);
#endif /* STRL_TEST */
return srclen+dstlen;
}
#endif /* !HAVE_STRLCAT || STRL_TEST */
#if defined(STRL_TEST)
static char src[] = "abcde"; /* test source string */
/*
* Main routine to test the strlcpy() and strlcat() functions.
*/
int
main(int argc, char **argv)
{
char dst[sizeof(src)]; /* test destination string */
size_t ret; /* strlcpy() or strlcat() return */
/*
* normal copy
*/
memset(dst, 0, sizeof(dst));
printf("src: %s\n", src);
ret = calc_strlcpy(dst, src, sizeof(dst));
printf("ret: %zu\n", ret);
printf("dst: %s\n\n", dst);
/*
* truncated copy
*/
memset(dst, 0, sizeof(dst));
printf("src: %s\n", src);
ret = calc_strlcpy(dst, src, sizeof(dst)-3);
printf("ret: %zu\n", ret);
printf("dst: %s\n\n", dst);
/*
* overcat
*/
printf("src: %s\n", src);
ret = calc_strlcat(dst, src, sizeof(dst));
printf("ret: %zu\n", ret);
printf("dst: %s\n\n", dst);
/*
* fullcat
*/
printf("src: %s\n", src);
ret = calc_strlcat(dst, src, sizeof(dst));
printf("ret: %zu\n", ret);
printf("dst: %s\n\n", dst);
/*
* nilcat
*/
dst[0] = '\0';
printf("src: %s\n", src);
ret = calc_strlcat(dst, src, sizeof(dst));
printf("ret: %zu\n", ret);
printf("dst: %s\n\n", dst);
/*
* shortcat
*/
dst[1] = '\0';
printf("src: %s\n", src);
ret = calc_strlcat(dst, src, sizeof(dst)-3);
printf("ret: %zu\n", ret);
printf("dst: %s\n\n", dst);
/*
* all done
*/
exit(0);
}
#endif /* STRL_TEST */

59
strl.h Normal file
View File

@@ -0,0 +1,59 @@
/*
* strl - size-bounded string copying and concatenation
*
* Copyright (C) 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: 2021/03/08 21;58:10
* File existed as early as: 2021
*
* Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/
*/
#if !defined(INCLUDE_STRL_H)
#define INCLUDE_STRL_H
#if defined(CALC_SRC) /* if we are building from the calc source tree */
#include "have_string.h"
#else
#include <calc/have_string.h>
#endif
#ifdef HAVE_STRING_H
# include <string.h>
#endif
#if defined(CALC_SRC) /* if we are building from the calc source tree */
# include "have_strlcpy.h"
# include "have_strlcat.h"
# include "decl.h"
#else
# include <calc/have_strlcpy.h>
# include <calc/have_strlcat.h>
# include <calc/decl.h>
#endif
#if !defined(HAVE_STRLCPY)
E_FUNC size_t strlcpy(char * dst, const char * src, size_t dstsize);
#endif /* !HAVE_STRLCPY */
#if !defined(HAVE_STRLCAT)
E_FUNC size_t strlcat(char * dst, const char * src, size_t dstsize);
#endif /* !HAVE_STRLCAT */
#endif /* !INCLUDE_STRL_H */

View File

@@ -1,7 +1,7 @@
/*
* symbol - global and local symbol routines
*
* Copyright (C) 1999-2007 David I. Bell and Ernest Bowen
* Copyright (C) 1999-2007,2021 David I. Bell and Ernest Bowen
*
* Primary author: David I. Bell
*
@@ -34,6 +34,10 @@
#include "opcodes.h"
#include "func.h"
#include "banned.h" /* include after system header <> includes */
#define HASHSIZE 37 /* size of hash table */
E_FUNC FILE *f_open(char *name, char *mode);

View File

@@ -1,7 +1,7 @@
/*
* token - read input file characters into tokens
*
* Copyright (C) 1999-2007,2017 David I. Bell and Ernest Bowen
* Copyright (C) 1999-2007,2017,2021 David I. Bell and Ernest Bowen
*
* Primary author: David I. Bell
*
@@ -30,12 +30,16 @@
#include <setjmp.h>
#include "calc.h"
#include "alloc.h"
#include "token.h"
#include "str.h"
#include "args.h"
#include "lib_calc.h"
#include "banned.h" /* include after system header <> includes */
#define isletter(ch) ((((ch) >= 'a') && ((ch) <= 'z')) || \
(((ch) >= 'A') && ((ch) <= 'Z')))
#define isdigit(ch) (((ch) >= '0') && ((ch) <= '9'))

View File

@@ -1,7 +1,7 @@
/*
* value - generic value manipulation routines
*
* Copyright (C) 1999-2007,2014,2017 David I. Bell
* Copyright (C) 1999-2007,2014,2017,2021 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
@@ -38,6 +38,10 @@
#include "file.h"
#include "config.h"
#include "banned.h" /* include after system header <> includes */
#define LINELEN 80 /* length of a typical tty line */
/*

View File

@@ -1,7 +1,7 @@
/*
* value - definitions of general values and related routines used by calc
*
* Copyright (C) 1999-2007,2014 David I. Bell
* Copyright (C) 1999-2007,2014,2021 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

View File

@@ -29,7 +29,10 @@
#include <stdio.h>
#include <errno.h>
#include <string.h>
#include "have_string.h"
#ifdef HAVE_STRING_H
# include <string.h>
#endif
#if defined(CALC_VER)
# include <stdlib.h>
@@ -39,13 +42,19 @@ static char *program;
#else
# include "calc.h"
#endif
#include "str.h"
#include "strl.h"
#include "have_unused.h"
#include "banned.h" /* include after system header <> includes */
#define MAJOR_VER 2 /* major library version */
#define MINOR_VER 12 /* minor library version */
#define MAJOR_PATCH 8 /* major software version level */
#define MINOR_PATCH 2 /* minor software version level */
#define MAJOR_PATCH 9 /* major software version level */
#define MINOR_PATCH 0 /* minor software version level */
/*
@@ -131,22 +140,7 @@ version(void)
fprintf(stderr, "%s: cannot malloc version string\n", program);
exit(70);
}
/*
* The next statement could be:
*
* strncpy(stored_version, verbuf, len);
*
* however compilers like gcc would issue warnings such as:
*
* specified bound depends on the length of the
* source argument
*
* even though we terminate the string by setting a NUL
* byte following the copy. Therefore we call memcpy()
* instead to avoid such warnings.
*/
memcpy(stored_version, verbuf, len);
stored_version[len] = '\0';
strlcpy(stored_version, verbuf, len+1);
/*
* return the newly malloced buffer

Some files were not shown because too many files have changed in this diff Show More