mirror of
https://git.FreeBSD.org/src.git
synced 2024-11-21 07:15:49 +00:00
vendor/bc: upgrade to version 7.0.0
This is a production release to fix three bugs, none of which
affects well formed scripts on FreeBSD:
The first bug is that bc/dc will exit on macOS when the terminal
is resized.
The second bug is that an array, which should only be a function
parameter, was accepted as part of larger expressions.
The third bug is that the value stack for dc was cleared on any error.
However, this is not how other dc behave. To bring dc more in line
with other implementations, this behavior was changed. This change is
why this version is a new major version.
(cherry picked from commit 54d20d67e2
)
MFC after: 3 days
This commit is contained in:
parent
49a5fe1a01
commit
12e0d31664
@ -94,6 +94,10 @@ BC = bc
|
||||
DC = dc
|
||||
BC_EXEC = $(BIN)/$(EXEC_PREFIX)$(BC)
|
||||
DC_EXEC = $(BIN)/$(EXEC_PREFIX)$(DC)
|
||||
BC_FUZZER = $(BIN)/$(BC)_fuzzer_c
|
||||
BC_FUZZER_C = $(BIN)/$(BC)_fuzzer_C
|
||||
DC_FUZZER = $(BIN)/$(DC)_fuzzer_c
|
||||
DC_FUZZER_C = $(BIN)/$(DC)_fuzzer_C
|
||||
|
||||
BC_TEST_OUTPUTS = tests/bc_outputs
|
||||
BC_FUZZ_OUTPUTS = tests/fuzzing/bc_outputs1 tests/fuzzing/bc_outputs2 tests/fuzzing/bc_outputs3
|
||||
@ -149,8 +153,11 @@ BC_ENABLE_NLS = %%NLS%%
|
||||
BC_EXCLUDE_EXTRA_MATH = %%EXCLUDE_EXTRA_MATH%%
|
||||
|
||||
BC_ENABLE_AFL = %%FUZZ%%
|
||||
BC_ENABLE_OSSFUZZ = %%OSSFUZZ%%
|
||||
BC_ENABLE_MEMCHECK = %%MEMCHECK%%
|
||||
|
||||
LIB_FUZZING_ENGINE = %%LIB_FUZZING_ENGINE%%
|
||||
|
||||
BC_DEFAULT_BANNER = %%BC_DEFAULT_BANNER%%
|
||||
BC_DEFAULT_SIGINT_RESET = %%BC_DEFAULT_SIGINT_RESET%%
|
||||
DC_DEFAULT_SIGINT_RESET = %%DC_DEFAULT_SIGINT_RESET%%
|
||||
@ -210,7 +217,8 @@ CPPFLAGS5 = $(CPPFLAGS4) -DBC_NUM_KARATSUBA_LEN=$(BC_NUM_KARATSUBA_LEN)
|
||||
CPPFLAGS6 = $(CPPFLAGS5) -DBC_ENABLE_NLS=$(BC_ENABLE_NLS)
|
||||
CPPFLAGS7 = $(CPPFLAGS6) -D$(BC_ENABLE_EXTRA_MATH_NAME)=$(BC_ENABLE_EXTRA_MATH)
|
||||
CPPFLAGS8 = $(CPPFLAGS7) -DBC_ENABLE_HISTORY=$(BC_ENABLE_HISTORY) -DBC_ENABLE_LIBRARY=$(BC_ENABLE_LIBRARY)
|
||||
CPPFLAGS = $(CPPFLAGS8) -DBC_ENABLE_MEMCHECK=$(BC_ENABLE_MEMCHECK) -DBC_ENABLE_AFL=$(BC_ENABLE_AFL)
|
||||
CPPFLAGS9 = $(CPPFLAGS8) -DBC_ENABLE_MEMCHECK=$(BC_ENABLE_MEMCHECK) -DBC_ENABLE_AFL=$(BC_ENABLE_AFL)
|
||||
CPPFLAGS = $(CPPFLAGS9) -DBC_ENABLE_OSSFUZZ=$(BC_ENABLE_OSSFUZZ)
|
||||
CFLAGS = $(CPPFLAGS) $(BC_DEFS) $(DC_DEFS) %%CPPFLAGS%% %%CFLAGS%%
|
||||
LDFLAGS = %%LDFLAGS%%
|
||||
|
||||
|
@ -1,5 +1,19 @@
|
||||
# News
|
||||
|
||||
## 7.0.0
|
||||
|
||||
This is a production release to fix three bugs.
|
||||
|
||||
The first bug is that `bc`/`dc` will exit on macOS when the terminal is resized.
|
||||
|
||||
The second bug is that an array, which should only be a function parameter, was
|
||||
accepted as part of larger expressions.
|
||||
|
||||
The third bug is that value stack for `dc` was cleared on any error. However,
|
||||
this is not how other `dc` behave. To bring `dc` more in line with other
|
||||
implementations, this behavior was changed. This change is why this version is a
|
||||
new major version.
|
||||
|
||||
## 6.7.6
|
||||
|
||||
This is a production release to fix one bug.
|
||||
|
@ -13,3 +13,4 @@
|
||||
-DBC_ENABLE_EXTRA_MATH=1
|
||||
-DBC_ENABLE_HISTORY=1
|
||||
-DBC_ENABLE_NLS=1
|
||||
-DBC_ENABLE_OSSFUZZ=0
|
||||
|
@ -68,7 +68,7 @@ usage() {
|
||||
printf ' [--man3dir=MAN3DIR]\n'
|
||||
|
||||
if [ "$_usage_val" -ne 0 ]; then
|
||||
exit
|
||||
exit "$_usage_val"
|
||||
fi
|
||||
|
||||
printf '\n'
|
||||
@ -181,6 +181,8 @@ usage() {
|
||||
printf ' Enable a build appropriate for valgrind. For development only.\n'
|
||||
printf ' -z, --enable-fuzz-mode\n'
|
||||
printf ' Enable fuzzing mode. THIS IS FOR DEVELOPMENT ONLY.\n'
|
||||
printf ' -Z, --enable-ossfuzz-mode\n'
|
||||
printf ' Enable fuzzing mode for OSS-Fuzz. THIS IS FOR DEVELOPMENT ONLY.\n'
|
||||
printf ' --prefix PREFIX\n'
|
||||
printf ' The prefix to install to. Overrides "$PREFIX" if it exists.\n'
|
||||
printf ' If PREFIX is "/usr", install path will be "/usr/bin".\n'
|
||||
@ -722,6 +724,7 @@ predefined_build() {
|
||||
all_locales=0
|
||||
library=0
|
||||
fuzz=0
|
||||
ossfuzz=0
|
||||
time_tests=0
|
||||
vg=0
|
||||
memcheck=0
|
||||
@ -755,6 +758,7 @@ predefined_build() {
|
||||
all_locales=0
|
||||
library=0
|
||||
fuzz=0
|
||||
ossfuzz=0
|
||||
time_tests=0
|
||||
vg=0
|
||||
memcheck=0
|
||||
@ -772,7 +776,8 @@ predefined_build() {
|
||||
dc_default_digit_clamp=0;;
|
||||
|
||||
GDH)
|
||||
CFLAGS="-flto -Weverything -Wno-padded -Wno-unsafe-buffer-usage -Wno-poison-system-directories -Werror -pedantic -std=c11"
|
||||
CFLAGS="-Weverything -Wno-padded -Wno-unsafe-buffer-usage -Wno-poison-system-directories"
|
||||
CFLAGS="$CFLAGS -Wno-switch-default -Werror -pedantic -std=c11"
|
||||
bc_only=0
|
||||
dc_only=0
|
||||
coverage=0
|
||||
@ -789,6 +794,7 @@ predefined_build() {
|
||||
all_locales=0
|
||||
library=0
|
||||
fuzz=0
|
||||
ossfuzz=0
|
||||
time_tests=0
|
||||
vg=0
|
||||
memcheck=0
|
||||
@ -806,7 +812,8 @@ predefined_build() {
|
||||
dc_default_digit_clamp=1;;
|
||||
|
||||
DBG)
|
||||
CFLAGS="-Weverything -Wno-padded -Wno-unsafe-buffer-usage -Wno-poison-system-directories -Werror -pedantic -std=c11"
|
||||
CFLAGS="-Weverything -Wno-padded -Wno-unsafe-buffer-usage -Wno-poison-system-directories"
|
||||
CFLAGS="$CFLAGS -Wno-switch-default -Werror -pedantic -std=c11"
|
||||
bc_only=0
|
||||
dc_only=0
|
||||
coverage=0
|
||||
@ -823,6 +830,7 @@ predefined_build() {
|
||||
all_locales=0
|
||||
library=0
|
||||
fuzz=0
|
||||
ossfuzz=0
|
||||
time_tests=0
|
||||
vg=0
|
||||
memcheck=1
|
||||
@ -888,6 +896,7 @@ strip_bin=1
|
||||
all_locales=0
|
||||
library=0
|
||||
fuzz=0
|
||||
ossfuzz=0
|
||||
time_tests=0
|
||||
vg=0
|
||||
memcheck=0
|
||||
@ -911,7 +920,7 @@ dc_default_digit_clamp=0
|
||||
# getopts is a POSIX utility, but it cannot handle long options. Thus, the
|
||||
# handling of long options is done by hand, and that's the reason that short and
|
||||
# long options cannot be mixed.
|
||||
while getopts "abBcdDeEfgGhHik:lMmNO:p:PrS:s:tTvz-" opt; do
|
||||
while getopts "abBcdDeEfgGhHik:lMmNO:p:PrS:s:tTvzZ-" opt; do
|
||||
|
||||
case "$opt" in
|
||||
a) library=1 ;;
|
||||
@ -944,6 +953,7 @@ while getopts "abBcdDeEfgGhHik:lMmNO:p:PrS:s:tTvz-" opt; do
|
||||
T) strip_bin=0 ;;
|
||||
v) vg=1 ;;
|
||||
z) fuzz=1 ;;
|
||||
Z) ossfuzz=1 ;;
|
||||
-)
|
||||
arg="$1"
|
||||
arg="${arg#--}"
|
||||
@ -1070,6 +1080,7 @@ while getopts "abBcdDeEfgGhHik:lMmNO:p:PrS:s:tTvz-" opt; do
|
||||
enable-test-timing) time_tests=1 ;;
|
||||
enable-valgrind) vg=1 ;;
|
||||
enable-fuzz-mode) fuzz=1 ;;
|
||||
enable-ossfuzz-mode) ossfuzz=1 ;;
|
||||
enable-memcheck) memcheck=1 ;;
|
||||
install-all-locales) all_locales=1 ;;
|
||||
help* | bc-only* | dc-only* | coverage* | debug*)
|
||||
@ -1320,6 +1331,45 @@ elif [ "$dc_only" -eq 1 ]; then
|
||||
|
||||
tests="test_dc"
|
||||
|
||||
elif [ "$ossfuzz" -eq 1 ]; then
|
||||
|
||||
if [ "$bc_only" -ne 0 ] || [ "$dc_only" -ne 0 ]; then
|
||||
usage "An OSS-Fuzz build must build both fuzzers."
|
||||
fi
|
||||
|
||||
bc=1
|
||||
dc=1
|
||||
|
||||
# Expressions *cannot* exit in an OSS-Fuzz build.
|
||||
bc_default_expr_exit=0
|
||||
dc_default_expr_exit=0
|
||||
|
||||
executables="bc_fuzzer and dc_fuzzer"
|
||||
|
||||
karatsuba="@\$(KARATSUBA) 30 0 \$(BC_EXEC)"
|
||||
karatsuba_test="@\$(KARATSUBA) 1 100 \$(BC_EXEC)"
|
||||
|
||||
if [ "$library" -eq 0 ]; then
|
||||
install_prereqs=" install_execs"
|
||||
install_man_prereqs=" install_bc_manpage install_dc_manpage"
|
||||
uninstall_prereqs=" uninstall_bc uninstall_dc"
|
||||
uninstall_man_prereqs=" uninstall_bc_manpage uninstall_dc_manpage"
|
||||
else
|
||||
install_prereqs=" install_library install_bcl_header"
|
||||
install_man_prereqs=" install_bcl_manpage"
|
||||
uninstall_prereqs=" uninstall_library uninstall_bcl_header"
|
||||
uninstall_man_prereqs=" uninstall_bcl_manpage"
|
||||
tests="test_library"
|
||||
fi
|
||||
|
||||
second_target_prereqs="src/bc_fuzzer.o $default_target_prereqs"
|
||||
default_target_prereqs="\$(BC_FUZZER) src/dc_fuzzer.o $default_target_prereqs"
|
||||
default_target_cmd="\$(CXX) \$(CFLAGS) src/dc_fuzzer.o \$(LIB_FUZZING_ENGINE) \$(OBJS) \$(LDFLAGS) -o \$(DC_FUZZER) \&\& ln -sf ./dc_fuzzer_c \$(DC_FUZZER_C)"
|
||||
second_target_cmd="\$(CXX) \$(CFLAGS) src/bc_fuzzer.o \$(LIB_FUZZING_ENGINE) \$(OBJS) \$(LDFLAGS) -o \$(BC_FUZZER) \&\& ln -sf ./bc_fuzzer_c \$(BC_FUZZER_C)"
|
||||
|
||||
default_target="\$(DC_FUZZER) \$(DC_FUZZER_C)"
|
||||
second_target="\$(BC_FUZZER) \$(BC_FUZZER_C)"
|
||||
|
||||
else
|
||||
|
||||
bc=1
|
||||
@ -1349,8 +1399,12 @@ else
|
||||
|
||||
fi
|
||||
|
||||
if [ "$fuzz" -ne 0 ] && [ "$ossfuzz" -ne 0 ]; then
|
||||
usage "Fuzzing mode and OSS-Fuzz mode are mutually exclusive"
|
||||
fi
|
||||
|
||||
# We need specific stuff for fuzzing.
|
||||
if [ "$fuzz" -ne 0 ]; then
|
||||
if [ "$fuzz" -ne 0 ] || [ "$ossfuzz" -ne 0 ]; then
|
||||
debug=1
|
||||
hist=0
|
||||
nls=0
|
||||
@ -1395,7 +1449,6 @@ else
|
||||
COVERAGE_PREREQS=""
|
||||
fi
|
||||
|
||||
|
||||
# Set some defaults.
|
||||
if [ -z "${DESTDIR+set}" ]; then
|
||||
destdir=""
|
||||
@ -1485,8 +1538,8 @@ if [ "$nls" -ne 0 ]; then
|
||||
|
||||
flags="-DBC_ENABLE_NLS=1 -DBC_ENABLED=$bc -DDC_ENABLED=$dc"
|
||||
flags="$flags -DBC_ENABLE_HISTORY=$hist -DBC_ENABLE_LIBRARY=0 -DBC_ENABLE_AFL=0"
|
||||
flags="$flags -DBC_ENABLE_EXTRA_MATH=$extra_math -I$scriptdir/include/"
|
||||
flags="$flags -D_POSIX_C_SOURCE=200809L -D_XOPEN_SOURCE=700"
|
||||
flags="$flags -DBC_ENABLE_EXTRA_MATH=$extra_math -DBC_ENABLE_OSSFUZZ=0"
|
||||
flags="$flags -I$scriptdir/include/ -D_POSIX_C_SOURCE=200809L -D_XOPEN_SOURCE=700"
|
||||
|
||||
ccbase=$(basename "$CC")
|
||||
|
||||
@ -1494,14 +1547,14 @@ if [ "$nls" -ne 0 ]; then
|
||||
flags="$flags -Wno-unreachable-code"
|
||||
fi
|
||||
|
||||
"$CC" $CPPFLAGS $CFLAGS $flags -c "$scriptdir/src/vm.c" -o "./vm.o" > /dev/null 2>&1
|
||||
"$CC" $CPPFLAGS $CFLAGS $flags -c "$scriptdir/src/vm.c" -E > /dev/null
|
||||
|
||||
err="$?"
|
||||
|
||||
rm -rf "./vm.o"
|
||||
|
||||
# If this errors, it is probably because of building on Windows,
|
||||
# and NLS is not supported on Windows, so disable it.
|
||||
# If this errors, it is probably because of building on Windows or musl,
|
||||
# and NLS is not supported on Windows or musl, so disable it.
|
||||
if [ "$err" -ne 0 ]; then
|
||||
printf 'NLS does not work.\n'
|
||||
if [ $force -eq 0 ]; then
|
||||
@ -1514,7 +1567,7 @@ if [ "$nls" -ne 0 ]; then
|
||||
printf 'NLS works.\n\n'
|
||||
|
||||
printf 'Testing gencat...\n'
|
||||
gencat "./en_US.cat" "$scriptdir/locales/en_US.msg" > /dev/null 2>&1
|
||||
gencat "./en_US.cat" "$scriptdir/locales/en_US.msg" > /dev/null
|
||||
|
||||
err="$?"
|
||||
|
||||
@ -1587,10 +1640,10 @@ if [ "$hist" -eq 1 ]; then
|
||||
flags="-DBC_ENABLE_HISTORY=1 -DBC_ENABLED=$bc -DDC_ENABLED=$dc"
|
||||
flags="$flags -DBC_ENABLE_NLS=$nls -DBC_ENABLE_LIBRARY=0 -DBC_ENABLE_AFL=0"
|
||||
flags="$flags -DBC_ENABLE_EDITLINE=$editline -DBC_ENABLE_READLINE=$readline"
|
||||
flags="$flags -DBC_ENABLE_EXTRA_MATH=$extra_math -I$scriptdir/include/"
|
||||
flags="$flags -D_POSIX_C_SOURCE=200809L -D_XOPEN_SOURCE=700"
|
||||
flags="$flags -DBC_ENABLE_EXTRA_MATH=$extra_math -DBC_ENABLE_OSSFUZZ=0"
|
||||
flags="$flags -I$scriptdir/include/ -D_POSIX_C_SOURCE=200809L -D_XOPEN_SOURCE=700"
|
||||
|
||||
"$CC" $CPPFLAGS $CFLAGS $flags -c "$scriptdir/src/history.c" -o "./history.o" > /dev/null 2>&1
|
||||
"$CC" $CPPFLAGS $CFLAGS $flags -c "$scriptdir/src/history.c" -E > /dev/null
|
||||
|
||||
err="$?"
|
||||
|
||||
@ -1660,7 +1713,7 @@ set +e
|
||||
printf 'Testing for FreeBSD...\n'
|
||||
|
||||
flags="-DBC_TEST_FREEBSD -DBC_ENABLE_AFL=0"
|
||||
"$CC" $CPPFLAGS $CFLAGS $flags "-I$scriptdir/include" -E "$scriptdir/src/vm.c" > /dev/null 2>&1
|
||||
"$CC" $CPPFLAGS $CFLAGS $flags "-I$scriptdir/include" -E "$scriptdir/scripts/os.c" > /dev/null
|
||||
|
||||
err="$?"
|
||||
|
||||
@ -1677,7 +1730,7 @@ fi
|
||||
printf 'Testing for macOS...\n'
|
||||
|
||||
flags="-DBC_TEST_APPLE -DBC_ENABLE_AFL=0"
|
||||
"$CC" $CPPFLAGS $CFLAGS $flags "-I$scriptdir/include" -E "$scriptdir/src/vm.c" > /dev/null 2>&1
|
||||
"$CC" $CPPFLAGS $CFLAGS $flags "-I$scriptdir/include" -E "$scriptdir/scripts/os.c" > /dev/null
|
||||
|
||||
err="$?"
|
||||
|
||||
@ -1705,7 +1758,7 @@ fi
|
||||
printf 'Testing for OpenBSD...\n'
|
||||
|
||||
flags="-DBC_TEST_OPENBSD -DBC_ENABLE_AFL=0"
|
||||
"$CC" $CPPFLAGS $CFLAGS $flags "-I$scriptdir/include" -E "$scriptdir/src/vm.c" > /dev/null 2>&1
|
||||
"$CC" $CPPFLAGS $CFLAGS $flags "-I$scriptdir/include" -E "$scriptdir/scripts/os.c" > /dev/null
|
||||
|
||||
err="$?"
|
||||
|
||||
@ -1741,7 +1794,7 @@ GEN_DIR="$scriptdir/gen"
|
||||
# These lines set the appropriate targets based on whether `gen/strgen.c` or
|
||||
# `gen/strgen.sh` is used.
|
||||
GEN="strgen"
|
||||
GEN_EXEC_TARGET="\$(HOSTCC) -DBC_ENABLE_AFL=0 -I$scriptdir/include/ \$(HOSTCFLAGS) -o \$(GEN_EXEC) \$(GEN_C)"
|
||||
GEN_EXEC_TARGET="\$(HOSTCC) -DBC_ENABLE_AFL=0 -DBC_ENABLE_OSSFUZZ=0 -I$scriptdir/include/ \$(HOSTCFLAGS) -o \$(GEN_EXEC) \$(GEN_C)"
|
||||
CLEAN_PREREQS=" clean_gen clean_coverage"
|
||||
|
||||
if [ -z "${GEN_HOST+set}" ]; then
|
||||
@ -1754,8 +1807,9 @@ else
|
||||
fi
|
||||
fi
|
||||
|
||||
# The fuzzer files are always unneeded because they'll be built separately.
|
||||
manpage_args=""
|
||||
unneeded=""
|
||||
unneeded="bc_fuzzer.c dc_fuzzer.c"
|
||||
headers="\$(HEADERS)"
|
||||
|
||||
# This series of if statements figure out what source files are *not* needed.
|
||||
@ -1826,6 +1880,14 @@ if [ "$library" -ne 0 ]; then
|
||||
|
||||
fi
|
||||
|
||||
elif [ "$ossfuzz" -ne 0 ]; then
|
||||
|
||||
unneeded="$unneeded library.c main.c"
|
||||
|
||||
PC_PATH=""
|
||||
pkg_config_install=""
|
||||
pkg_config_uninstall=""
|
||||
|
||||
else
|
||||
|
||||
unneeded="$unneeded library.c"
|
||||
@ -1836,9 +1898,10 @@ else
|
||||
|
||||
fi
|
||||
|
||||
# library.c is not needed under normal circumstances.
|
||||
# library.c, bc_fuzzer.c, and dc_fuzzer.c are not needed under normal
|
||||
# circumstances.
|
||||
if [ "$unneeded" = "" ]; then
|
||||
unneeded="library.c"
|
||||
unneeded="library.c bc_fuzzer.c dc_fuzzer.c"
|
||||
fi
|
||||
|
||||
# This sets the appropriate manpage for a full build.
|
||||
@ -1846,7 +1909,7 @@ if [ "$manpage_args" = "" ]; then
|
||||
manpage_args="A"
|
||||
fi
|
||||
|
||||
if [ "$vg" -ne 0 ]; then
|
||||
if [ "$vg" -ne 0 ] || [ "$ossfuzz" -ne 0 ]; then
|
||||
memcheck=1
|
||||
fi
|
||||
|
||||
@ -2011,7 +2074,9 @@ contents=$(replace "$contents" "HISTORY" "$hist")
|
||||
contents=$(replace "$contents" "EXTRA_MATH" "$extra_math")
|
||||
contents=$(replace "$contents" "NLS" "$nls")
|
||||
contents=$(replace "$contents" "FUZZ" "$fuzz")
|
||||
contents=$(replace "$contents" "OSSFUZZ" "$ossfuzz")
|
||||
contents=$(replace "$contents" "MEMCHECK" "$memcheck")
|
||||
contents=$(replace "$contents" "LIB_FUZZING_ENGINE" "$LIB_FUZZING_ENGINE")
|
||||
|
||||
contents=$(replace "$contents" "BC_LIB_O" "$bc_lib")
|
||||
contents=$(replace "$contents" "BC_HELP_O" "$bc_help")
|
||||
@ -2117,6 +2182,15 @@ if [ "$dc" -ne 0 ]; then
|
||||
gen_err_tests dc $dc_test_exec
|
||||
fi
|
||||
|
||||
if [ "$ossfuzz" -ne 0 ]; then
|
||||
|
||||
printf 'bc_fuzzer_c: $(BC_FUZZER)\n\tln -sf $(BC_FUZZER) bc_fuzzer_c\n' >> Makefile
|
||||
printf 'bc_fuzzer_C: $(BC_FUZZER)\n\tln -sf $(BC_FUZZER) bc_fuzzer_C\n' >> Makefile
|
||||
printf 'dc_fuzzer_c: $(DC_FUZZER)\n\tln -sf $(DC_FUZZER) dc_fuzzer_c\n' >> Makefile
|
||||
printf 'dc_fuzzer_C: $(DC_FUZZER)\n\tln -sf $(DC_FUZZER) dc_fuzzer_C\n' >> Makefile
|
||||
|
||||
fi
|
||||
|
||||
# Copy the correct manuals to the expected places.
|
||||
mkdir -p manuals
|
||||
cp -f "$scriptdir/manuals/bc/$manpage_args.1.md" manuals/bc.1.md
|
||||
|
@ -54,7 +54,7 @@
|
||||
* any.
|
||||
*/
|
||||
void
|
||||
bc_args(int argc, char* argv[], bool exit_exprs, BcBigDig* scale,
|
||||
bc_args(int argc, const char* argv[], bool exit_exprs, BcBigDig* scale,
|
||||
BcBigDig* ibase, BcBigDig* obase);
|
||||
|
||||
#if BC_ENABLED
|
||||
|
@ -51,7 +51,7 @@
|
||||
* @return A status.
|
||||
*/
|
||||
BcStatus
|
||||
bc_main(int argc, char* argv[]);
|
||||
bc_main(int argc, const char* argv[]);
|
||||
|
||||
// These are references to the help text, the library text, and the "filename"
|
||||
// for the library.
|
||||
|
@ -48,7 +48,7 @@
|
||||
* @return A status.
|
||||
*/
|
||||
BcStatus
|
||||
dc_main(int argc, char* argv[]);
|
||||
dc_main(int argc, const char* argv[]);
|
||||
|
||||
// A reference to the dc help text.
|
||||
extern const char dc_help[];
|
||||
|
@ -47,7 +47,7 @@
|
||||
typedef struct BcOpt
|
||||
{
|
||||
/// The array of arguments.
|
||||
char** argv;
|
||||
const char** argv;
|
||||
|
||||
/// The index of the current argument.
|
||||
size_t optind;
|
||||
@ -59,7 +59,7 @@ typedef struct BcOpt
|
||||
int subopt;
|
||||
|
||||
/// The option argument.
|
||||
char* optarg;
|
||||
const char* optarg;
|
||||
|
||||
} BcOpt;
|
||||
|
||||
@ -103,7 +103,7 @@ typedef struct BcOptLong
|
||||
* @param argv The array of arguments.
|
||||
*/
|
||||
void
|
||||
bc_opt_init(BcOpt* o, char** argv);
|
||||
bc_opt_init(BcOpt* o, const char** argv);
|
||||
|
||||
/**
|
||||
* Parse an option. This returns a value the same way getopt() and getopt_long()
|
||||
|
79
contrib/bc/include/ossfuzz.h
Normal file
79
contrib/bc/include/ossfuzz.h
Normal file
@ -0,0 +1,79 @@
|
||||
/*
|
||||
* *****************************************************************************
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*
|
||||
* Copyright (c) 2018-2024 Gavin D. Howard and contributors.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright notice, this
|
||||
* list of conditions and the following disclaimer.
|
||||
*
|
||||
* * Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* *****************************************************************************
|
||||
*
|
||||
* Declarations for the OSS-Fuzz build of bc and dc.
|
||||
*
|
||||
*/
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#ifndef BC_OSSFUZZ_H
|
||||
#define BC_OSSFUZZ_H
|
||||
|
||||
/// The number of args in fuzzer arguments, including the NULL terminator.
|
||||
extern const size_t bc_fuzzer_args_len;
|
||||
|
||||
/// The standard arguments for the bc fuzzer with the -c argument.
|
||||
extern const char* bc_fuzzer_args_c[];
|
||||
|
||||
/// The standard arguments for the bc fuzzer with the -C argument.
|
||||
extern const char* bc_fuzzer_args_C[];
|
||||
|
||||
/// The standard arguments for the dc fuzzer with the -c argument.
|
||||
extern const char* dc_fuzzer_args_c[];
|
||||
|
||||
/// The standard arguments for the dc fuzzer with the -C argument.
|
||||
extern const char* dc_fuzzer_args_C[];
|
||||
|
||||
/// The data pointer.
|
||||
extern uint8_t* bc_fuzzer_data;
|
||||
|
||||
/**
|
||||
* The function that the fuzzer runs.
|
||||
* @param Data The data.
|
||||
* @param Size The number of bytes in @a Data.
|
||||
* @return 0 on success, -1 on error.
|
||||
* @pre @a Data must not be equal to NULL if @a Size > 0.
|
||||
*/
|
||||
int
|
||||
LLVMFuzzerTestOneInput(const uint8_t* Data, size_t Size);
|
||||
|
||||
/**
|
||||
* The initialization function for the fuzzer.
|
||||
* @param argc A pointer to the argument count.
|
||||
* @param argv A pointer to the argument list.
|
||||
* @return 0 on success, -1 on error.
|
||||
*/
|
||||
int
|
||||
LLVMFuzzerInitialize(int* argc, char*** argv);
|
||||
|
||||
#endif // BC_OSSFUZZ_H
|
@ -46,27 +46,6 @@
|
||||
#include <stdint.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
// This is used by configure.sh to test for OpenBSD.
|
||||
#ifdef BC_TEST_OPENBSD
|
||||
#ifdef __OpenBSD__
|
||||
#error On OpenBSD without _BSD_SOURCE
|
||||
#endif // __OpenBSD__
|
||||
#endif // BC_TEST_OPENBSD
|
||||
|
||||
// This is used by configure.sh to test for FreeBSD.
|
||||
#ifdef BC_TEST_FREEBSD
|
||||
#ifdef __FreeBSD__
|
||||
#error On FreeBSD with _POSIX_C_SOURCE
|
||||
#endif // __FreeBSD__
|
||||
#endif // BC_TEST_FREEBSD
|
||||
|
||||
// This is used by configure.sh to test for macOS.
|
||||
#ifdef BC_TEST_APPLE
|
||||
#ifdef __APPLE__
|
||||
#error On macOS without _DARWIN_C_SOURCE
|
||||
#endif // __APPLE__
|
||||
#endif // BC_TEST_APPLE
|
||||
|
||||
// Windows has deprecated isatty() and the rest of these. Or doesn't have them.
|
||||
// So these are just fixes for Windows.
|
||||
#ifdef _WIN32
|
||||
@ -676,9 +655,13 @@ typedef enum BcMode
|
||||
/// File mode.
|
||||
BC_MODE_FILE,
|
||||
|
||||
#if !BC_ENABLE_OSSFUZZ
|
||||
|
||||
/// stdin mode.
|
||||
BC_MODE_STDIN,
|
||||
|
||||
#endif // !BC_ENABLE_OSSFUZZ
|
||||
|
||||
} BcMode;
|
||||
|
||||
/// Do a longjmp(). This is what to use when activating an "exception", i.e., a
|
||||
|
@ -37,6 +37,6 @@
|
||||
#define BC_VERSION_H
|
||||
|
||||
/// The current version.
|
||||
#define VERSION 6.7.6
|
||||
#define VERSION 7.0.0
|
||||
|
||||
#endif // BC_VERSION_H
|
||||
|
@ -794,7 +794,7 @@ bc_vm_info(const char* const help);
|
||||
* @return A status.
|
||||
*/
|
||||
BcStatus
|
||||
bc_vm_boot(int argc, char* argv[]);
|
||||
bc_vm_boot(int argc, const char* argv[]);
|
||||
|
||||
/**
|
||||
* Initializes some of the BcVm global. This is separate to make things easier
|
||||
|
@ -25,7 +25,7 @@
|
||||
.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
.\" POSSIBILITY OF SUCH DAMAGE.
|
||||
.\"
|
||||
.TH "DC" "1" "January 2024" "Gavin D. Howard" "General Commands Manual"
|
||||
.TH "DC" "1" "August 2024" "Gavin D. Howard" "General Commands Manual"
|
||||
.nh
|
||||
.ad l
|
||||
.SH Name
|
||||
@ -1275,11 +1275,14 @@ handler for, it resets.
|
||||
This means that several things happen.
|
||||
.PP
|
||||
First, any macros that are executing are stopped and popped off the
|
||||
stack.
|
||||
execution stack.
|
||||
The behavior is not unlike that of exceptions in programming languages.
|
||||
Then the execution point is set so that any code waiting to execute
|
||||
(after all macros returned) is skipped.
|
||||
.PP
|
||||
However, the stack of values is \f[I]not\f[R] cleared; in interactive
|
||||
mode, users can inspect the stack and manipulate it.
|
||||
.PP
|
||||
Thus, when dc(1) resets, it skips any remaining code waiting to be
|
||||
executed.
|
||||
Then, if it is interactive mode, and the error was not a fatal error
|
||||
|
@ -1130,11 +1130,14 @@ the next non-space characters do not match that regex.
|
||||
When dc(1) encounters an error or a signal that it has a non-default handler
|
||||
for, it resets. This means that several things happen.
|
||||
|
||||
First, any macros that are executing are stopped and popped off the stack.
|
||||
The behavior is not unlike that of exceptions in programming languages. Then
|
||||
the execution point is set so that any code waiting to execute (after all
|
||||
First, any macros that are executing are stopped and popped off the execution
|
||||
stack. The behavior is not unlike that of exceptions in programming languages.
|
||||
Then the execution point is set so that any code waiting to execute (after all
|
||||
macros returned) is skipped.
|
||||
|
||||
However, the stack of values is *not* cleared; in interactive mode, users can
|
||||
inspect the stack and manipulate it.
|
||||
|
||||
Thus, when dc(1) resets, it skips any remaining code waiting to be executed.
|
||||
Then, if it is interactive mode, and the error was not a fatal error (see the
|
||||
**EXIT STATUS** section), it asks for more input; otherwise, it exits with the
|
||||
|
@ -25,7 +25,7 @@
|
||||
.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
.\" POSSIBILITY OF SUCH DAMAGE.
|
||||
.\"
|
||||
.TH "DC" "1" "January 2024" "Gavin D. Howard" "General Commands Manual"
|
||||
.TH "DC" "1" "August 2024" "Gavin D. Howard" "General Commands Manual"
|
||||
.nh
|
||||
.ad l
|
||||
.SH Name
|
||||
@ -1061,11 +1061,14 @@ handler for, it resets.
|
||||
This means that several things happen.
|
||||
.PP
|
||||
First, any macros that are executing are stopped and popped off the
|
||||
stack.
|
||||
execution stack.
|
||||
The behavior is not unlike that of exceptions in programming languages.
|
||||
Then the execution point is set so that any code waiting to execute
|
||||
(after all macros returned) is skipped.
|
||||
.PP
|
||||
However, the stack of values is \f[I]not\f[R] cleared; in interactive
|
||||
mode, users can inspect the stack and manipulate it.
|
||||
.PP
|
||||
Thus, when dc(1) resets, it skips any remaining code waiting to be
|
||||
executed.
|
||||
Then, if it is interactive mode, and the error was not a fatal error
|
||||
|
@ -961,11 +961,14 @@ the next non-space characters do not match that regex.
|
||||
When dc(1) encounters an error or a signal that it has a non-default handler
|
||||
for, it resets. This means that several things happen.
|
||||
|
||||
First, any macros that are executing are stopped and popped off the stack.
|
||||
The behavior is not unlike that of exceptions in programming languages. Then
|
||||
the execution point is set so that any code waiting to execute (after all
|
||||
First, any macros that are executing are stopped and popped off the execution
|
||||
stack. The behavior is not unlike that of exceptions in programming languages.
|
||||
Then the execution point is set so that any code waiting to execute (after all
|
||||
macros returned) is skipped.
|
||||
|
||||
However, the stack of values is *not* cleared; in interactive mode, users can
|
||||
inspect the stack and manipulate it.
|
||||
|
||||
Thus, when dc(1) resets, it skips any remaining code waiting to be executed.
|
||||
Then, if it is interactive mode, and the error was not a fatal error (see the
|
||||
**EXIT STATUS** section), it asks for more input; otherwise, it exits with the
|
||||
|
@ -25,7 +25,7 @@
|
||||
.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
.\" POSSIBILITY OF SUCH DAMAGE.
|
||||
.\"
|
||||
.TH "DC" "1" "January 2024" "Gavin D. Howard" "General Commands Manual"
|
||||
.TH "DC" "1" "August 2024" "Gavin D. Howard" "General Commands Manual"
|
||||
.nh
|
||||
.ad l
|
||||
.SH Name
|
||||
@ -1061,11 +1061,14 @@ handler for, it resets.
|
||||
This means that several things happen.
|
||||
.PP
|
||||
First, any macros that are executing are stopped and popped off the
|
||||
stack.
|
||||
execution stack.
|
||||
The behavior is not unlike that of exceptions in programming languages.
|
||||
Then the execution point is set so that any code waiting to execute
|
||||
(after all macros returned) is skipped.
|
||||
.PP
|
||||
However, the stack of values is \f[I]not\f[R] cleared; in interactive
|
||||
mode, users can inspect the stack and manipulate it.
|
||||
.PP
|
||||
Thus, when dc(1) resets, it skips any remaining code waiting to be
|
||||
executed.
|
||||
Then, if it is interactive mode, and the error was not a fatal error
|
||||
|
@ -961,11 +961,14 @@ the next non-space characters do not match that regex.
|
||||
When dc(1) encounters an error or a signal that it has a non-default handler
|
||||
for, it resets. This means that several things happen.
|
||||
|
||||
First, any macros that are executing are stopped and popped off the stack.
|
||||
The behavior is not unlike that of exceptions in programming languages. Then
|
||||
the execution point is set so that any code waiting to execute (after all
|
||||
First, any macros that are executing are stopped and popped off the execution
|
||||
stack. The behavior is not unlike that of exceptions in programming languages.
|
||||
Then the execution point is set so that any code waiting to execute (after all
|
||||
macros returned) is skipped.
|
||||
|
||||
However, the stack of values is *not* cleared; in interactive mode, users can
|
||||
inspect the stack and manipulate it.
|
||||
|
||||
Thus, when dc(1) resets, it skips any remaining code waiting to be executed.
|
||||
Then, if it is interactive mode, and the error was not a fatal error (see the
|
||||
**EXIT STATUS** section), it asks for more input; otherwise, it exits with the
|
||||
|
@ -25,7 +25,7 @@
|
||||
.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
.\" POSSIBILITY OF SUCH DAMAGE.
|
||||
.\"
|
||||
.TH "DC" "1" "January 2024" "Gavin D. Howard" "General Commands Manual"
|
||||
.TH "DC" "1" "August 2024" "Gavin D. Howard" "General Commands Manual"
|
||||
.nh
|
||||
.ad l
|
||||
.SH Name
|
||||
@ -1061,11 +1061,14 @@ handler for, it resets.
|
||||
This means that several things happen.
|
||||
.PP
|
||||
First, any macros that are executing are stopped and popped off the
|
||||
stack.
|
||||
execution stack.
|
||||
The behavior is not unlike that of exceptions in programming languages.
|
||||
Then the execution point is set so that any code waiting to execute
|
||||
(after all macros returned) is skipped.
|
||||
.PP
|
||||
However, the stack of values is \f[I]not\f[R] cleared; in interactive
|
||||
mode, users can inspect the stack and manipulate it.
|
||||
.PP
|
||||
Thus, when dc(1) resets, it skips any remaining code waiting to be
|
||||
executed.
|
||||
Then, if it is interactive mode, and the error was not a fatal error
|
||||
|
@ -961,11 +961,14 @@ the next non-space characters do not match that regex.
|
||||
When dc(1) encounters an error or a signal that it has a non-default handler
|
||||
for, it resets. This means that several things happen.
|
||||
|
||||
First, any macros that are executing are stopped and popped off the stack.
|
||||
The behavior is not unlike that of exceptions in programming languages. Then
|
||||
the execution point is set so that any code waiting to execute (after all
|
||||
First, any macros that are executing are stopped and popped off the execution
|
||||
stack. The behavior is not unlike that of exceptions in programming languages.
|
||||
Then the execution point is set so that any code waiting to execute (after all
|
||||
macros returned) is skipped.
|
||||
|
||||
However, the stack of values is *not* cleared; in interactive mode, users can
|
||||
inspect the stack and manipulate it.
|
||||
|
||||
Thus, when dc(1) resets, it skips any remaining code waiting to be executed.
|
||||
Then, if it is interactive mode, and the error was not a fatal error (see the
|
||||
**EXIT STATUS** section), it asks for more input; otherwise, it exits with the
|
||||
|
@ -25,7 +25,7 @@
|
||||
.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
.\" POSSIBILITY OF SUCH DAMAGE.
|
||||
.\"
|
||||
.TH "DC" "1" "January 2024" "Gavin D. Howard" "General Commands Manual"
|
||||
.TH "DC" "1" "August 2024" "Gavin D. Howard" "General Commands Manual"
|
||||
.nh
|
||||
.ad l
|
||||
.SH Name
|
||||
@ -1061,11 +1061,14 @@ handler for, it resets.
|
||||
This means that several things happen.
|
||||
.PP
|
||||
First, any macros that are executing are stopped and popped off the
|
||||
stack.
|
||||
execution stack.
|
||||
The behavior is not unlike that of exceptions in programming languages.
|
||||
Then the execution point is set so that any code waiting to execute
|
||||
(after all macros returned) is skipped.
|
||||
.PP
|
||||
However, the stack of values is \f[I]not\f[R] cleared; in interactive
|
||||
mode, users can inspect the stack and manipulate it.
|
||||
.PP
|
||||
Thus, when dc(1) resets, it skips any remaining code waiting to be
|
||||
executed.
|
||||
Then, if it is interactive mode, and the error was not a fatal error
|
||||
|
@ -961,11 +961,14 @@ the next non-space characters do not match that regex.
|
||||
When dc(1) encounters an error or a signal that it has a non-default handler
|
||||
for, it resets. This means that several things happen.
|
||||
|
||||
First, any macros that are executing are stopped and popped off the stack.
|
||||
The behavior is not unlike that of exceptions in programming languages. Then
|
||||
the execution point is set so that any code waiting to execute (after all
|
||||
First, any macros that are executing are stopped and popped off the execution
|
||||
stack. The behavior is not unlike that of exceptions in programming languages.
|
||||
Then the execution point is set so that any code waiting to execute (after all
|
||||
macros returned) is skipped.
|
||||
|
||||
However, the stack of values is *not* cleared; in interactive mode, users can
|
||||
inspect the stack and manipulate it.
|
||||
|
||||
Thus, when dc(1) resets, it skips any remaining code waiting to be executed.
|
||||
Then, if it is interactive mode, and the error was not a fatal error (see the
|
||||
**EXIT STATUS** section), it asks for more input; otherwise, it exits with the
|
||||
|
@ -25,7 +25,7 @@
|
||||
.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
.\" POSSIBILITY OF SUCH DAMAGE.
|
||||
.\"
|
||||
.TH "DC" "1" "January 2024" "Gavin D. Howard" "General Commands Manual"
|
||||
.TH "DC" "1" "August 2024" "Gavin D. Howard" "General Commands Manual"
|
||||
.nh
|
||||
.ad l
|
||||
.SH Name
|
||||
@ -1275,11 +1275,14 @@ handler for, it resets.
|
||||
This means that several things happen.
|
||||
.PP
|
||||
First, any macros that are executing are stopped and popped off the
|
||||
stack.
|
||||
execution stack.
|
||||
The behavior is not unlike that of exceptions in programming languages.
|
||||
Then the execution point is set so that any code waiting to execute
|
||||
(after all macros returned) is skipped.
|
||||
.PP
|
||||
However, the stack of values is \f[I]not\f[R] cleared; in interactive
|
||||
mode, users can inspect the stack and manipulate it.
|
||||
.PP
|
||||
Thus, when dc(1) resets, it skips any remaining code waiting to be
|
||||
executed.
|
||||
Then, if it is interactive mode, and the error was not a fatal error
|
||||
|
@ -1130,11 +1130,14 @@ the next non-space characters do not match that regex.
|
||||
When dc(1) encounters an error or a signal that it has a non-default handler
|
||||
for, it resets. This means that several things happen.
|
||||
|
||||
First, any macros that are executing are stopped and popped off the stack.
|
||||
The behavior is not unlike that of exceptions in programming languages. Then
|
||||
the execution point is set so that any code waiting to execute (after all
|
||||
First, any macros that are executing are stopped and popped off the execution
|
||||
stack. The behavior is not unlike that of exceptions in programming languages.
|
||||
Then the execution point is set so that any code waiting to execute (after all
|
||||
macros returned) is skipped.
|
||||
|
||||
However, the stack of values is *not* cleared; in interactive mode, users can
|
||||
inspect the stack and manipulate it.
|
||||
|
||||
Thus, when dc(1) resets, it skips any remaining code waiting to be executed.
|
||||
Then, if it is interactive mode, and the error was not a fatal error (see the
|
||||
**EXIT STATUS** section), it asks for more input; otherwise, it exits with the
|
||||
|
@ -25,7 +25,7 @@
|
||||
.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
.\" POSSIBILITY OF SUCH DAMAGE.
|
||||
.\"
|
||||
.TH "DC" "1" "January 2024" "Gavin D. Howard" "General Commands Manual"
|
||||
.TH "DC" "1" "August 2024" "Gavin D. Howard" "General Commands Manual"
|
||||
.nh
|
||||
.ad l
|
||||
.SH Name
|
||||
@ -1275,11 +1275,14 @@ handler for, it resets.
|
||||
This means that several things happen.
|
||||
.PP
|
||||
First, any macros that are executing are stopped and popped off the
|
||||
stack.
|
||||
execution stack.
|
||||
The behavior is not unlike that of exceptions in programming languages.
|
||||
Then the execution point is set so that any code waiting to execute
|
||||
(after all macros returned) is skipped.
|
||||
.PP
|
||||
However, the stack of values is \f[I]not\f[R] cleared; in interactive
|
||||
mode, users can inspect the stack and manipulate it.
|
||||
.PP
|
||||
Thus, when dc(1) resets, it skips any remaining code waiting to be
|
||||
executed.
|
||||
Then, if it is interactive mode, and the error was not a fatal error
|
||||
|
@ -1130,11 +1130,14 @@ the next non-space characters do not match that regex.
|
||||
When dc(1) encounters an error or a signal that it has a non-default handler
|
||||
for, it resets. This means that several things happen.
|
||||
|
||||
First, any macros that are executing are stopped and popped off the stack.
|
||||
The behavior is not unlike that of exceptions in programming languages. Then
|
||||
the execution point is set so that any code waiting to execute (after all
|
||||
First, any macros that are executing are stopped and popped off the execution
|
||||
stack. The behavior is not unlike that of exceptions in programming languages.
|
||||
Then the execution point is set so that any code waiting to execute (after all
|
||||
macros returned) is skipped.
|
||||
|
||||
However, the stack of values is *not* cleared; in interactive mode, users can
|
||||
inspect the stack and manipulate it.
|
||||
|
||||
Thus, when dc(1) resets, it skips any remaining code waiting to be executed.
|
||||
Then, if it is interactive mode, and the error was not a fatal error (see the
|
||||
**EXIT STATUS** section), it asks for more input; otherwise, it exits with the
|
||||
|
@ -25,7 +25,7 @@
|
||||
.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
.\" POSSIBILITY OF SUCH DAMAGE.
|
||||
.\"
|
||||
.TH "DC" "1" "January 2024" "Gavin D. Howard" "General Commands Manual"
|
||||
.TH "DC" "1" "August 2024" "Gavin D. Howard" "General Commands Manual"
|
||||
.nh
|
||||
.ad l
|
||||
.SH Name
|
||||
@ -1275,11 +1275,14 @@ handler for, it resets.
|
||||
This means that several things happen.
|
||||
.PP
|
||||
First, any macros that are executing are stopped and popped off the
|
||||
stack.
|
||||
execution stack.
|
||||
The behavior is not unlike that of exceptions in programming languages.
|
||||
Then the execution point is set so that any code waiting to execute
|
||||
(after all macros returned) is skipped.
|
||||
.PP
|
||||
However, the stack of values is \f[I]not\f[R] cleared; in interactive
|
||||
mode, users can inspect the stack and manipulate it.
|
||||
.PP
|
||||
Thus, when dc(1) resets, it skips any remaining code waiting to be
|
||||
executed.
|
||||
Then, if it is interactive mode, and the error was not a fatal error
|
||||
|
@ -1130,11 +1130,14 @@ the next non-space characters do not match that regex.
|
||||
When dc(1) encounters an error or a signal that it has a non-default handler
|
||||
for, it resets. This means that several things happen.
|
||||
|
||||
First, any macros that are executing are stopped and popped off the stack.
|
||||
The behavior is not unlike that of exceptions in programming languages. Then
|
||||
the execution point is set so that any code waiting to execute (after all
|
||||
First, any macros that are executing are stopped and popped off the execution
|
||||
stack. The behavior is not unlike that of exceptions in programming languages.
|
||||
Then the execution point is set so that any code waiting to execute (after all
|
||||
macros returned) is skipped.
|
||||
|
||||
However, the stack of values is *not* cleared; in interactive mode, users can
|
||||
inspect the stack and manipulate it.
|
||||
|
||||
Thus, when dc(1) resets, it skips any remaining code waiting to be executed.
|
||||
Then, if it is interactive mode, and the error was not a fatal error (see the
|
||||
**EXIT STATUS** section), it asks for more input; otherwise, it exits with the
|
||||
|
59
contrib/bc/scripts/os.c
Normal file
59
contrib/bc/scripts/os.c
Normal file
@ -0,0 +1,59 @@
|
||||
/*
|
||||
* *****************************************************************************
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*
|
||||
* Copyright (c) 2018-2024 Gavin D. Howard and contributors.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright notice, this
|
||||
* list of conditions and the following disclaimer.
|
||||
*
|
||||
* * Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* *****************************************************************************
|
||||
*
|
||||
* File for testing compilation on different platforms.
|
||||
*
|
||||
*/
|
||||
|
||||
// This is used by configure.sh to test for OpenBSD.
|
||||
#ifdef BC_TEST_OPENBSD
|
||||
#ifdef __OpenBSD__
|
||||
#error On OpenBSD without _BSD_SOURCE
|
||||
#endif // __OpenBSD__
|
||||
#endif // BC_TEST_OPENBSD
|
||||
|
||||
// This is used by configure.sh to test for FreeBSD.
|
||||
#ifdef BC_TEST_FREEBSD
|
||||
#ifdef __FreeBSD__
|
||||
#error On FreeBSD with _POSIX_C_SOURCE
|
||||
#endif // __FreeBSD__
|
||||
#endif // BC_TEST_FREEBSD
|
||||
|
||||
// This is used by configure.sh to test for macOS.
|
||||
#ifdef BC_TEST_APPLE
|
||||
#ifdef __APPLE__
|
||||
#error On macOS without _DARWIN_C_SOURCE
|
||||
#endif // __APPLE__
|
||||
#endif // BC_TEST_APPLE
|
||||
|
||||
extern int test;
|
||||
|
||||
int test;
|
@ -149,7 +149,7 @@ bc_args_redefine(const char* keyword)
|
||||
#endif // BC_ENABLED
|
||||
|
||||
void
|
||||
bc_args(int argc, char* argv[], bool exit_exprs, BcBigDig* scale,
|
||||
bc_args(int argc, const char* argv[], bool exit_exprs, BcBigDig* scale,
|
||||
BcBigDig* ibase, BcBigDig* obase)
|
||||
{
|
||||
int c;
|
||||
@ -157,7 +157,7 @@ bc_args(int argc, char* argv[], bool exit_exprs, BcBigDig* scale,
|
||||
bool do_exit = false, version = false;
|
||||
BcOpt opts;
|
||||
#if BC_ENABLE_EXTRA_MATH
|
||||
char* seed = NULL;
|
||||
const char* seed = NULL;
|
||||
#endif // BC_ENABLE_EXTRA_MATH
|
||||
|
||||
BC_SIG_ASSERT_LOCKED;
|
||||
|
@ -46,7 +46,7 @@
|
||||
* @param argv The arguments.
|
||||
*/
|
||||
BcStatus
|
||||
bc_main(int argc, char* argv[])
|
||||
bc_main(int argc, const char* argv[])
|
||||
{
|
||||
// All of these just set bc-specific items in BcVm.
|
||||
|
||||
@ -61,4 +61,5 @@ bc_main(int argc, char* argv[])
|
||||
|
||||
return bc_vm_boot(argc, argv);
|
||||
}
|
||||
|
||||
#endif // BC_ENABLED
|
||||
|
112
contrib/bc/src/bc_fuzzer.c
Normal file
112
contrib/bc/src/bc_fuzzer.c
Normal file
@ -0,0 +1,112 @@
|
||||
/*
|
||||
* *****************************************************************************
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*
|
||||
* Copyright (c) 2018-2024 Gavin D. Howard and contributors.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright notice, this
|
||||
* list of conditions and the following disclaimer.
|
||||
*
|
||||
* * Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* *****************************************************************************
|
||||
*
|
||||
* The entry point for libFuzzer when fuzzing bc.
|
||||
*
|
||||
*/
|
||||
|
||||
#include <setjmp.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <version.h>
|
||||
#include <status.h>
|
||||
#include <ossfuzz.h>
|
||||
#include <vm.h>
|
||||
#include <bc.h>
|
||||
#include <dc.h>
|
||||
|
||||
uint8_t* bc_fuzzer_data;
|
||||
|
||||
/// A boolean about whether we should use -c (false) or -C (true).
|
||||
static bool bc_C;
|
||||
|
||||
int
|
||||
LLVMFuzzerInitialize(int* argc, char*** argv)
|
||||
{
|
||||
BC_UNUSED(argc);
|
||||
|
||||
if (argv == NULL || *argv == NULL)
|
||||
{
|
||||
bc_C = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
char* name;
|
||||
|
||||
// Get the basename
|
||||
name = strrchr((*argv)[0], BC_FILE_SEP);
|
||||
name = name == NULL ? (*argv)[0] : name + 1;
|
||||
|
||||
// Figure out which to use.
|
||||
bc_C = (strcmp(name, "bc_fuzzer_C") == 0);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
LLVMFuzzerTestOneInput(const uint8_t* Data, size_t Size)
|
||||
{
|
||||
BcStatus s;
|
||||
|
||||
// I've already tested empty input, so just ignore.
|
||||
if (Size == 0 || Data[0] == '\0') return 0;
|
||||
|
||||
// Clear the global. This is to ensure a clean start.
|
||||
memset(vm, 0, sizeof(BcVm));
|
||||
|
||||
// Make sure to set the name.
|
||||
vm->name = "bc";
|
||||
|
||||
BC_SIG_LOCK;
|
||||
|
||||
// We *must* do this here. Otherwise, other code could not jump out all of
|
||||
// the way.
|
||||
bc_vec_init(&vm->jmp_bufs, sizeof(sigjmp_buf), BC_DTOR_NONE);
|
||||
|
||||
BC_SETJMP_LOCKED(vm, exit);
|
||||
|
||||
// Create a string with the data.
|
||||
bc_fuzzer_data = bc_vm_malloc(Size + 1);
|
||||
memcpy(bc_fuzzer_data, Data, Size);
|
||||
bc_fuzzer_data[Size] = '\0';
|
||||
|
||||
s = bc_main((int) (bc_fuzzer_args_len - 1),
|
||||
bc_C ? bc_fuzzer_args_C : bc_fuzzer_args_c);
|
||||
|
||||
exit:
|
||||
|
||||
BC_SIG_MAYLOCK;
|
||||
|
||||
free(bc_fuzzer_data);
|
||||
|
||||
return s == BC_STATUS_SUCCESS || s == BC_STATUS_QUIT ? 0 : -1;
|
||||
}
|
@ -115,7 +115,9 @@ bc_lex_string(BcLex* l)
|
||||
buf = l->buf;
|
||||
got_more = false;
|
||||
|
||||
#if !BC_ENABLE_OSSFUZZ
|
||||
assert(vm->mode != BC_MODE_STDIN || buf == vm->buffer.v);
|
||||
#endif // !BC_ENABLE_OSSFUZZ
|
||||
|
||||
// Fortunately for us, bc doesn't escape quotes. Instead, the equivalent
|
||||
// is '\q', which makes this loop simpler.
|
||||
|
@ -2002,7 +2002,8 @@ bc_parse_expr_err(BcParse* p, uint8_t flags, BcParseNext next)
|
||||
BcLexType top, t;
|
||||
size_t nexprs, ops_bgn;
|
||||
uint32_t i, nparens, nrelops;
|
||||
bool pfirst, rprn, done, get_token, assign, bin_last, incdec, can_assign;
|
||||
bool pfirst, rprn, array_last, done, get_token, assign;
|
||||
bool bin_last, incdec, can_assign;
|
||||
|
||||
// One of these *must* be true.
|
||||
assert(!(flags & BC_PARSE_PRINT) || !(flags & BC_PARSE_NEEDVAL));
|
||||
@ -2019,6 +2020,7 @@ bc_parse_expr_err(BcParse* p, uint8_t flags, BcParseNext next)
|
||||
// - nrelops is the number of relational operators that appear in the expr.
|
||||
// - nexprs is the number of unused expressions.
|
||||
// - rprn is a right paren encountered last.
|
||||
// - array_last is an array item encountered last.
|
||||
// - done means the expression has been fully parsed.
|
||||
// - get_token is true when a token is needed at the end of an iteration.
|
||||
// - assign is true when an assignment statement was parsed last.
|
||||
@ -2030,7 +2032,7 @@ bc_parse_expr_err(BcParse* p, uint8_t flags, BcParseNext next)
|
||||
nparens = nrelops = 0;
|
||||
nexprs = 0;
|
||||
ops_bgn = p->ops.len;
|
||||
rprn = done = get_token = assign = incdec = can_assign = false;
|
||||
rprn = array_last = done = get_token = assign = incdec = can_assign = false;
|
||||
bin_last = true;
|
||||
|
||||
// We want to eat newlines if newlines are not a valid ending token.
|
||||
@ -2046,6 +2048,14 @@ bc_parse_expr_err(BcParse* p, uint8_t flags, BcParseNext next)
|
||||
// This is the Shunting-Yard algorithm loop.
|
||||
for (; !done && BC_PARSE_EXPR(t); t = p->l.t)
|
||||
{
|
||||
// Make sure an array expression is not mixed with any others. However,
|
||||
// a right parenthesis may end the expression, so we will need to take
|
||||
// care of that right there.
|
||||
if (BC_ERR(array_last && t != BC_LEX_RPAREN))
|
||||
{
|
||||
bc_parse_err(p, BC_ERR_PARSE_EXPR);
|
||||
}
|
||||
|
||||
switch (t)
|
||||
{
|
||||
case BC_LEX_OP_INC:
|
||||
@ -2221,6 +2231,14 @@ bc_parse_expr_err(BcParse* p, uint8_t flags, BcParseNext next)
|
||||
break;
|
||||
}
|
||||
|
||||
// Now that we know the right paren has not ended the
|
||||
// expression, make sure an array expression is not mixed with
|
||||
// any others.
|
||||
if (BC_ERR(array_last))
|
||||
{
|
||||
bc_parse_err(p, BC_ERR_PARSE_EXPR);
|
||||
}
|
||||
|
||||
nparens -= 1;
|
||||
rprn = true;
|
||||
get_token = bin_last = incdec = false;
|
||||
@ -2263,6 +2281,7 @@ bc_parse_expr_err(BcParse* p, uint8_t flags, BcParseNext next)
|
||||
bc_parse_name(p, &prev, &can_assign, flags & ~BC_PARSE_NOCALL);
|
||||
|
||||
rprn = (prev == BC_INST_CALL);
|
||||
array_last = (prev == BC_INST_ARRAY);
|
||||
nexprs += 1;
|
||||
flags &= ~(BC_PARSE_ARRAY);
|
||||
|
||||
|
@ -174,6 +174,65 @@ const BcOptLong bc_args_lopt[] = {
|
||||
|
||||
};
|
||||
|
||||
#if BC_ENABLE_OSSFUZZ
|
||||
|
||||
const char* bc_fuzzer_args_c[] = {
|
||||
"bc",
|
||||
"-lqc",
|
||||
"-e",
|
||||
"seed = 82507683022933941343198991100880559238.7080266844215897551270760113"
|
||||
"4734858017748592704189096562163085637164174146616055338762825421827784"
|
||||
"566630725748836994171142578125",
|
||||
NULL,
|
||||
};
|
||||
|
||||
const char* dc_fuzzer_args_c[] = {
|
||||
"dc",
|
||||
"-xc",
|
||||
"-e",
|
||||
"82507683022933941343198991100880559238.7080266844215897551270760113"
|
||||
"4734858017748592704189096562163085637164174146616055338762825421827784"
|
||||
"566630725748836994171142578125j",
|
||||
NULL,
|
||||
};
|
||||
|
||||
const char* bc_fuzzer_args_C[] = {
|
||||
"bc",
|
||||
"-lqC",
|
||||
"-e",
|
||||
"seed = 82507683022933941343198991100880559238.7080266844215897551270760113"
|
||||
"4734858017748592704189096562163085637164174146616055338762825421827784"
|
||||
"566630725748836994171142578125",
|
||||
NULL,
|
||||
};
|
||||
|
||||
const char* dc_fuzzer_args_C[] = {
|
||||
"dc",
|
||||
"-xC",
|
||||
"-e",
|
||||
"82507683022933941343198991100880559238.7080266844215897551270760113"
|
||||
"4734858017748592704189096562163085637164174146616055338762825421827784"
|
||||
"566630725748836994171142578125j",
|
||||
NULL,
|
||||
};
|
||||
|
||||
const size_t bc_fuzzer_args_len = sizeof(bc_fuzzer_args_c) / sizeof(char*);
|
||||
|
||||
#if BC_C11
|
||||
|
||||
_Static_assert(sizeof(bc_fuzzer_args_C) / sizeof(char*) == bc_fuzzer_args_len,
|
||||
"Wrong number of bc fuzzer args");
|
||||
|
||||
_Static_assert(sizeof(dc_fuzzer_args_c) / sizeof(char*) == bc_fuzzer_args_len,
|
||||
"Wrong number of dc fuzzer args");
|
||||
|
||||
_Static_assert(sizeof(dc_fuzzer_args_C) / sizeof(char*) == bc_fuzzer_args_len,
|
||||
"Wrong number of dc fuzzer args");
|
||||
|
||||
#endif // BC_C11
|
||||
|
||||
#endif // BC_ENABLE_OSSFUZZ
|
||||
|
||||
// clang-format off
|
||||
|
||||
/// The default error category strings.
|
||||
|
@ -46,7 +46,7 @@
|
||||
* @param argv The arguments.
|
||||
*/
|
||||
BcStatus
|
||||
dc_main(int argc, char* argv[])
|
||||
dc_main(int argc, const char* argv[])
|
||||
{
|
||||
// All of these just set dc-specific items in BcVm.
|
||||
|
||||
@ -61,4 +61,5 @@ dc_main(int argc, char* argv[])
|
||||
|
||||
return bc_vm_boot(argc, argv);
|
||||
}
|
||||
|
||||
#endif // DC_ENABLED
|
||||
|
112
contrib/bc/src/dc_fuzzer.c
Normal file
112
contrib/bc/src/dc_fuzzer.c
Normal file
@ -0,0 +1,112 @@
|
||||
/*
|
||||
* *****************************************************************************
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*
|
||||
* Copyright (c) 2018-2024 Gavin D. Howard and contributors.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright notice, this
|
||||
* list of conditions and the following disclaimer.
|
||||
*
|
||||
* * Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* *****************************************************************************
|
||||
*
|
||||
* The entry point for libFuzzer when fuzzing dc.
|
||||
*
|
||||
*/
|
||||
|
||||
#include <setjmp.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <version.h>
|
||||
#include <status.h>
|
||||
#include <ossfuzz.h>
|
||||
#include <vm.h>
|
||||
#include <bc.h>
|
||||
#include <dc.h>
|
||||
|
||||
uint8_t* bc_fuzzer_data;
|
||||
|
||||
/// A boolean about whether we should use -c (false) or -C (true).
|
||||
static bool dc_C;
|
||||
|
||||
int
|
||||
LLVMFuzzerInitialize(int* argc, char*** argv)
|
||||
{
|
||||
BC_UNUSED(argc);
|
||||
|
||||
if (argv == NULL || *argv == NULL)
|
||||
{
|
||||
dc_C = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
char* name;
|
||||
|
||||
// Get the basename
|
||||
name = strrchr((*argv)[0], BC_FILE_SEP);
|
||||
name = name == NULL ? (*argv)[0] : name + 1;
|
||||
|
||||
// Figure out which to use.
|
||||
dc_C = (strcmp(name, "dc_fuzzer_C") == 0);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
LLVMFuzzerTestOneInput(const uint8_t* Data, size_t Size)
|
||||
{
|
||||
BcStatus s;
|
||||
|
||||
// I've already tested empty input, so just ignore.
|
||||
if (Size == 0 || Data[0] == '\0') return 0;
|
||||
|
||||
// Clear the global. This is to ensure a clean start.
|
||||
memset(vm, 0, sizeof(BcVm));
|
||||
|
||||
// Make sure to set the name.
|
||||
vm->name = "dc";
|
||||
|
||||
BC_SIG_LOCK;
|
||||
|
||||
// We *must* do this here. Otherwise, other code could not jump out all of
|
||||
// the way.
|
||||
bc_vec_init(&vm->jmp_bufs, sizeof(sigjmp_buf), BC_DTOR_NONE);
|
||||
|
||||
BC_SETJMP_LOCKED(vm, exit);
|
||||
|
||||
// Create a string with the data.
|
||||
bc_fuzzer_data = bc_vm_malloc(Size + 1);
|
||||
memcpy(bc_fuzzer_data, Data, Size);
|
||||
bc_fuzzer_data[Size] = '\0';
|
||||
|
||||
s = dc_main((int) (bc_fuzzer_args_len - 1),
|
||||
dc_C ? dc_fuzzer_args_C : dc_fuzzer_args_c);
|
||||
|
||||
exit:
|
||||
|
||||
BC_SIG_MAYLOCK;
|
||||
|
||||
free(bc_fuzzer_data);
|
||||
|
||||
return s == BC_STATUS_SUCCESS || s == BC_STATUS_QUIT ? 0 : -1;
|
||||
}
|
@ -114,7 +114,9 @@ dc_lex_string(BcLex* l)
|
||||
nls = 0;
|
||||
got_more = false;
|
||||
|
||||
#if !BC_ENABLE_OSSFUZZ
|
||||
assert(l->mode != BC_MODE_STDIN || l->buf == vm->buffer.v);
|
||||
#endif // !BC_ENABLE_OSSFUZZ
|
||||
|
||||
// This is the meat. As long as we don't run into the NUL byte, and we
|
||||
// have "depth", which means we haven't completely balanced brackets
|
||||
|
@ -264,7 +264,7 @@ bc_history_line(BcHistory* h, BcVec* vec, const char* prompt)
|
||||
errno = EINTR;
|
||||
|
||||
// Get the line.
|
||||
while (line == NULL && len == -1 && errno == EINTR)
|
||||
while (line == NULL && (len == -1 || errno == EINTR))
|
||||
{
|
||||
line = el_gets(h->el, &len);
|
||||
bc_history_use_prompt = false;
|
||||
|
@ -136,7 +136,7 @@ bc_func_reset(BcFunc* f)
|
||||
#endif // BC_ENABLED
|
||||
}
|
||||
|
||||
#if BC_DEBUG
|
||||
#if BC_DEBUG || BC_ENABLE_MEMCHECK
|
||||
void
|
||||
bc_func_free(void* func)
|
||||
{
|
||||
@ -155,7 +155,7 @@ bc_func_free(void* func)
|
||||
}
|
||||
#endif // BC_ENABLED
|
||||
}
|
||||
#endif // BC_DEBUG
|
||||
#endif // BC_DEBUG || BC_ENABLE_MEMCHECK
|
||||
|
||||
void
|
||||
bc_array_init(BcVec* a, bool nums)
|
||||
|
@ -79,7 +79,9 @@ bc_lex_comment(BcLex* l)
|
||||
got_more = false;
|
||||
|
||||
// If we are in stdin mode, the buffer must be the one used for stdin.
|
||||
#if !BC_ENABLE_OSSFUZZ
|
||||
assert(vm->mode != BC_MODE_STDIN || buf == vm->buffer.v);
|
||||
#endif // !BC_ENABLE_OSSFUZZ
|
||||
|
||||
// Find the end of the comment.
|
||||
for (i = l->i; !end; i += !end)
|
||||
@ -93,11 +95,13 @@ bc_lex_comment(BcLex* l)
|
||||
// If this is true, we need to request more data.
|
||||
if (BC_ERR(!c || buf[i + 1] == '\0'))
|
||||
{
|
||||
#if !BC_ENABLE_OSSFUZZ
|
||||
// Read more, if possible.
|
||||
if (!vm->eof && l->mode != BC_MODE_FILE)
|
||||
{
|
||||
got_more = bc_lex_readLine(l);
|
||||
}
|
||||
#endif // !BC_ENABLE_OSSFUZZ
|
||||
|
||||
break;
|
||||
}
|
||||
@ -363,12 +367,16 @@ bc_lex_readLine(BcLex* l)
|
||||
break;
|
||||
}
|
||||
|
||||
#if !BC_ENABLE_OSSFUZZ
|
||||
|
||||
case BC_MODE_STDIN:
|
||||
{
|
||||
good = bc_vm_readLine(false);
|
||||
break;
|
||||
}
|
||||
|
||||
#endif // !BC_ENABLE_OSSFUZZ
|
||||
|
||||
#ifdef __GNUC__
|
||||
#ifndef __clang__
|
||||
default:
|
||||
|
@ -100,20 +100,29 @@ main(int argc, char* argv[])
|
||||
|
||||
BC_SETJMP_LOCKED(vm, exit);
|
||||
|
||||
#if BC_CLANG
|
||||
#pragma clang diagnostic push
|
||||
#pragma clang diagnostic ignored "-Wcast-qual"
|
||||
#endif // BC_CLANG
|
||||
#if !DC_ENABLED
|
||||
s = bc_main(argc, argv);
|
||||
s = bc_main(argc, (const char**) argv);
|
||||
#elif !BC_ENABLED
|
||||
s = dc_main(argc, argv);
|
||||
s = dc_main(argc, (const char**) argv);
|
||||
#else
|
||||
// BC_IS_BC uses vm->name, which was set above. So we're good.
|
||||
if (BC_IS_BC) s = bc_main(argc, argv);
|
||||
else s = dc_main(argc, argv);
|
||||
if (BC_IS_BC) s = bc_main(argc, (const char**) argv);
|
||||
else s = dc_main(argc, (const char**) argv);
|
||||
#endif
|
||||
#if BC_CLANG
|
||||
#pragma clang diagnostic pop
|
||||
#endif // BC_CLANG
|
||||
|
||||
vm->status = (int) s;
|
||||
vm->status = (sig_atomic_t) s;
|
||||
|
||||
exit:
|
||||
BC_SIG_MAYLOCK;
|
||||
|
||||
return vm->status == BC_STATUS_QUIT ? BC_STATUS_SUCCESS : vm->status;
|
||||
s = bc_vm_atexit((BcStatus) vm->status);
|
||||
|
||||
return (int) s;
|
||||
}
|
||||
|
@ -274,6 +274,8 @@ bc_num_nonZeroLen(const BcNum* restrict n)
|
||||
return i + 1;
|
||||
}
|
||||
|
||||
#if BC_ENABLE_EXTRA_MATH
|
||||
|
||||
/**
|
||||
* Returns the power of 10 that a number with an absolute value less than 1
|
||||
* needs to be multiplied by in order to be greater than 1 or less than -1.
|
||||
@ -301,6 +303,8 @@ bc_num_negPow10(const BcNum* restrict n)
|
||||
return places + (BC_NUM_RDX_VAL(n) - (idx + 1)) * BC_BASE_DIGS;
|
||||
}
|
||||
|
||||
#endif // BC_ENABLE_EXTRA_MATH
|
||||
|
||||
/**
|
||||
* Performs a one-limb add with a carry.
|
||||
* @param a The first limb.
|
||||
|
@ -143,8 +143,8 @@ static int
|
||||
bc_opt_parseShort(BcOpt* o, const BcOptLong* longopts)
|
||||
{
|
||||
int type;
|
||||
char* next;
|
||||
char* option = o->argv[o->optind];
|
||||
const char* next;
|
||||
const char* option = o->argv[o->optind];
|
||||
int ret = -1;
|
||||
|
||||
// Make sure to clear these.
|
||||
@ -273,8 +273,8 @@ bc_opt_longoptsMatch(const char* name, const char* option)
|
||||
* @param option The option to find the argument of.
|
||||
* @return A pointer to the argument of the option, or NULL if none.
|
||||
*/
|
||||
static char*
|
||||
bc_opt_longoptsArg(char* option)
|
||||
static const char*
|
||||
bc_opt_longoptsArg(const char* option)
|
||||
{
|
||||
// Find the end or equals sign.
|
||||
for (; *option && *option != '='; ++option)
|
||||
@ -290,7 +290,7 @@ int
|
||||
bc_opt_parse(BcOpt* o, const BcOptLong* longopts)
|
||||
{
|
||||
size_t i;
|
||||
char* option;
|
||||
const char* option;
|
||||
bool empty;
|
||||
|
||||
// This just eats empty options.
|
||||
@ -332,7 +332,7 @@ bc_opt_parse(BcOpt* o, const BcOptLong* longopts)
|
||||
// If we have a match...
|
||||
if (bc_opt_longoptsMatch(name, option))
|
||||
{
|
||||
char* arg;
|
||||
const char* arg;
|
||||
|
||||
// Get the option char and the argument.
|
||||
o->optopt = longopts[i].val;
|
||||
@ -385,7 +385,7 @@ bc_opt_parse(BcOpt* o, const BcOptLong* longopts)
|
||||
}
|
||||
|
||||
void
|
||||
bc_opt_init(BcOpt* o, char* argv[])
|
||||
bc_opt_init(BcOpt* o, const char* argv[])
|
||||
{
|
||||
o->argv = argv;
|
||||
o->optind = 1;
|
||||
|
@ -2803,7 +2803,7 @@ bc_program_insertFunc(BcProgram* p, const char* name)
|
||||
return idx;
|
||||
}
|
||||
|
||||
#if BC_DEBUG
|
||||
#if BC_DEBUG || BC_ENABLE_MEMCHECK
|
||||
void
|
||||
bc_program_free(BcProgram* p)
|
||||
{
|
||||
@ -2850,7 +2850,7 @@ bc_program_free(BcProgram* p)
|
||||
if (BC_IS_DC) bc_vec_free(&p->tail_calls);
|
||||
#endif // DC_ENABLED
|
||||
}
|
||||
#endif // BC_DEBUG
|
||||
#endif // BC_DEBUG || BC_ENABLE_MEMCHECK
|
||||
|
||||
void
|
||||
bc_program_init(BcProgram* p)
|
||||
@ -2977,9 +2977,8 @@ bc_program_reset(BcProgram* p)
|
||||
|
||||
BC_SIG_ASSERT_LOCKED;
|
||||
|
||||
// Pop all but the last execution and all results.
|
||||
// Pop all but the last execution.
|
||||
bc_vec_npop(&p->stack, p->stack.len - 1);
|
||||
bc_vec_popAll(&p->results);
|
||||
|
||||
#if DC_ENABLED
|
||||
// We need to pop tail calls too.
|
||||
@ -2987,6 +2986,12 @@ bc_program_reset(BcProgram* p)
|
||||
#endif // DC_ENABLED
|
||||
|
||||
#if BC_ENABLED
|
||||
// Clear the stack if we are in bc. We have to do this in bc because bc's
|
||||
// stack is implicit.
|
||||
//
|
||||
// XXX: We don't do this in dc because other dc implementations don't.
|
||||
if (BC_IS_BC || !BC_I) bc_vec_popAll(&p->results);
|
||||
|
||||
// Clear the globals' stacks.
|
||||
if (BC_G) bc_program_popGlobals(p, true);
|
||||
#endif // BC_ENABLED
|
||||
|
@ -66,6 +66,9 @@
|
||||
#if BC_ENABLE_LIBRARY
|
||||
#include <library.h>
|
||||
#endif // BC_ENABLE_LIBRARY
|
||||
#if BC_ENABLE_OSSFUZZ
|
||||
#include <ossfuzz.h>
|
||||
#endif // BC_ENABLE_OSSFUZZ
|
||||
|
||||
#if !BC_ENABLE_LIBRARY
|
||||
|
||||
@ -674,7 +677,7 @@ bc_vm_shutdown(void)
|
||||
#endif // BC_ENABLE_HISTORY
|
||||
#endif // !BC_ENABLE_LIBRARY
|
||||
|
||||
#if BC_DEBUG
|
||||
#if BC_DEBUG || BC_ENABLE_MEMCHECK
|
||||
#if !BC_ENABLE_LIBRARY
|
||||
bc_vec_free(&vm->env_args);
|
||||
free(vm->env_args_buffer);
|
||||
@ -694,7 +697,7 @@ bc_vm_shutdown(void)
|
||||
#endif // !BC_ENABLE_LIBRARY
|
||||
|
||||
bc_vm_freeTemps();
|
||||
#endif // BC_DEBUG
|
||||
#endif // BC_DEBUG || BC_ENABLE_MEMCHECK
|
||||
|
||||
#if !BC_ENABLE_LIBRARY
|
||||
// We always want to flush.
|
||||
@ -1140,6 +1143,8 @@ bc_vm_file(const char* file)
|
||||
BC_LONGJMP_CONT(vm);
|
||||
}
|
||||
|
||||
#if !BC_ENABLE_OSSFUZZ
|
||||
|
||||
bool
|
||||
bc_vm_readLine(bool clear)
|
||||
{
|
||||
@ -1276,6 +1281,8 @@ bc_vm_stdin(void)
|
||||
BC_LONGJMP_CONT(vm);
|
||||
}
|
||||
|
||||
#endif // BC_ENABLE_OSSFUZZ
|
||||
|
||||
bool
|
||||
bc_vm_readBuf(bool clear)
|
||||
{
|
||||
@ -1495,6 +1502,8 @@ bc_vm_exec(void)
|
||||
}
|
||||
#endif // BC_ENABLED
|
||||
|
||||
assert(!BC_ENABLE_OSSFUZZ || BC_EXPR_EXIT == 0);
|
||||
|
||||
// If there are expressions to execute...
|
||||
if (vm->exprs.len)
|
||||
{
|
||||
@ -1502,7 +1511,11 @@ bc_vm_exec(void)
|
||||
bc_vm_exprs();
|
||||
|
||||
// Sometimes, executing expressions means we need to quit.
|
||||
if (!vm->no_exprs && vm->exit_exprs && BC_EXPR_EXIT) return;
|
||||
if (vm->status != BC_STATUS_SUCCESS ||
|
||||
(!vm->no_exprs && vm->exit_exprs && BC_EXPR_EXIT))
|
||||
{
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// Process files.
|
||||
@ -1514,6 +1527,8 @@ bc_vm_exec(void)
|
||||
has_file = true;
|
||||
#endif // DC_ENABLED
|
||||
bc_vm_file(path);
|
||||
|
||||
if (vm->status != BC_STATUS_SUCCESS) return;
|
||||
}
|
||||
|
||||
#if BC_ENABLE_EXTRA_MATH
|
||||
@ -1542,12 +1557,25 @@ bc_vm_exec(void)
|
||||
__AFL_INIT();
|
||||
#endif // BC_ENABLE_AFL
|
||||
|
||||
#if BC_ENABLE_OSSFUZZ
|
||||
|
||||
if (BC_VM_RUN_STDIN(has_file))
|
||||
{
|
||||
// XXX: Yes, this is a hack to run the fuzzer for OSS-Fuzz, but it
|
||||
// works.
|
||||
bc_vm_load("<stdin>", (const char*) bc_fuzzer_data);
|
||||
}
|
||||
|
||||
#else // BC_ENABLE_OSSFUZZ
|
||||
|
||||
// Execute from stdin. bc always does.
|
||||
if (BC_VM_RUN_STDIN(has_file)) bc_vm_stdin();
|
||||
|
||||
#endif // BC_ENABLE_OSSFUZZ
|
||||
}
|
||||
|
||||
BcStatus
|
||||
bc_vm_boot(int argc, char* argv[])
|
||||
bc_vm_boot(int argc, const char* argv[])
|
||||
{
|
||||
int ttyin, ttyout, ttyerr;
|
||||
bool tty;
|
||||
@ -1739,7 +1767,7 @@ bc_vm_boot(int argc, char* argv[])
|
||||
BC_SIG_LOCK;
|
||||
|
||||
// Exit.
|
||||
return bc_vm_atexit((BcStatus) vm->status);
|
||||
return (BcStatus) vm->status;
|
||||
}
|
||||
#endif // !BC_ENABLE_LIBRARY
|
||||
|
||||
|
37
contrib/bc/tests/bc/errors/37.txt
Normal file
37
contrib/bc/tests/bc/errors/37.txt
Normal file
@ -0,0 +1,37 @@
|
||||
print f
|
||||
if(6)H
|
||||
if(6)streafoob#! /q
|
||||
|
||||
define printarray(a[], len) {
|
||||
|
||||
auto i
|
||||
|
||||
for (i = 0; i < len; ++i) {
|
||||
m[i]
|
||||
}
|
||||
}
|
||||
|
||||
define a2(a[], len) {
|
||||
|
||||
auto i
|
||||
|
||||
for (i = 0; i < len; ++i) {
|
||||
a[i] = a[i] * a[i]
|
||||
}
|
||||
|
||||
printarray(a[], len)
|
||||
}
|
||||
define a1(*a[], len) {
|
||||
|
||||
auto i
|
||||
|
||||
for (i = 0; i < len; ++i) {
|
||||
a[i] = i
|
||||
}
|
||||
|
||||
a2(a[], len)
|
||||
|
||||
printarray(a[], len)
|
||||
}
|
||||
len = 16
|
||||
a1(b[] ++ase^= , len)
|
37
contrib/bc/tests/bc/errors/38.txt
Normal file
37
contrib/bc/tests/bc/errors/38.txt
Normal file
@ -0,0 +1,37 @@
|
||||
print f
|
||||
if(6)H
|
||||
if(6)streafoob#! /q
|
||||
|
||||
define printarray(a[], len) {
|
||||
|
||||
auto i
|
||||
|
||||
for (i = 0; i < len; ++i) {
|
||||
m[i]
|
||||
}
|
||||
}
|
||||
|
||||
define a2(a[], len) {
|
||||
|
||||
auto i
|
||||
|
||||
for (i = 0; i < len; ++i) {
|
||||
a[i] = a[i] * a[i]
|
||||
}
|
||||
|
||||
printarray(a[], len)
|
||||
}
|
||||
define a1(*a[], len) {
|
||||
|
||||
auto i
|
||||
|
||||
for (i = 0; i < len; ++i) {
|
||||
a[i] = i
|
||||
}
|
||||
|
||||
a2(a[], len)
|
||||
|
||||
printarray(a[], len)
|
||||
}
|
||||
len = 16
|
||||
a1((b[]) + ++ase^= , len)
|
@ -29,26 +29,26 @@
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>true</UseDebugLibraries>
|
||||
<PlatformToolset>v142</PlatformToolset>
|
||||
<PlatformToolset>v143</PlatformToolset>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>false</UseDebugLibraries>
|
||||
<PlatformToolset>v142</PlatformToolset>
|
||||
<PlatformToolset>v143</PlatformToolset>
|
||||
<WholeProgramOptimization>true</WholeProgramOptimization>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>true</UseDebugLibraries>
|
||||
<PlatformToolset>v142</PlatformToolset>
|
||||
<PlatformToolset>v143</PlatformToolset>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>false</UseDebugLibraries>
|
||||
<PlatformToolset>v142</PlatformToolset>
|
||||
<PlatformToolset>v143</PlatformToolset>
|
||||
<WholeProgramOptimization>true</WholeProgramOptimization>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
</PropertyGroup>
|
||||
@ -103,7 +103,7 @@
|
||||
<AdditionalOptions>/std:c17 /MP $(AdditionalOptions)</AdditionalOptions>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<SDLCheck>true</SDLCheck>
|
||||
<PreprocessorDefinitions>BC_ENABLED=1;DC_ENABLED=1;BC_ENABLE_EXTRA_MATH=1;BC_ENABLE_HISTORY=1;BC_ENABLE_NLS=0;BC_DEBUG_CODE=0;BC_ENABLE_LIBRARY=0;BC_ENABLE_EDITLINE=0;BC_ENABLE_READLINE=0;BUILD_TYPE=N;BC_DEFAULT_BANNER=1;BC_DEFAULT_SIGINT_RESET=0;DC_DEFAULT_SIGINT_RESET=0;BC_DEFAULT_TTY_MODE=1;DC_DEFAULT_TTY_MODE=1;BC_DEFAULT_PROMPT=1;DC_DEFAULT_PROMPT=1;BC_DEFAULT_EXPR_EXIT=1;DC_DEFAULT_EXPR_EXIT=1;BC_DEFAULT_DIGIT_CLAMP=1;DC_DEFAULT_DIGIT_CLAMP=1;WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<PreprocessorDefinitions>BC_ENABLED=1;DC_ENABLED=1;BC_ENABLE_EXTRA_MATH=1;BC_ENABLE_HISTORY=1;BC_ENABLE_NLS=0;BC_DEBUG_CODE=0;BC_ENABLE_LIBRARY=0;BC_ENABLE_EDITLINE=0;BC_ENABLE_READLINE=0;BC_ENABLE_OSSFUZZ=0;BUILD_TYPE=N;BC_DEFAULT_BANNER=1;BC_DEFAULT_SIGINT_RESET=0;DC_DEFAULT_SIGINT_RESET=0;BC_DEFAULT_TTY_MODE=1;DC_DEFAULT_TTY_MODE=1;BC_DEFAULT_PROMPT=1;DC_DEFAULT_PROMPT=1;BC_DEFAULT_EXPR_EXIT=1;DC_DEFAULT_EXPR_EXIT=1;BC_DEFAULT_DIGIT_CLAMP=1;DC_DEFAULT_DIGIT_CLAMP=1;WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<AdditionalIncludeDirectories>..\include</AdditionalIncludeDirectories>
|
||||
<RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary>
|
||||
<ConformanceMode>true</ConformanceMode>
|
||||
@ -125,7 +125,7 @@
|
||||
<FunctionLevelLinking>true</FunctionLevelLinking>
|
||||
<IntrinsicFunctions>true</IntrinsicFunctions>
|
||||
<SDLCheck>true</SDLCheck>
|
||||
<PreprocessorDefinitions>BC_ENABLED=1;DC_ENABLED=1;BC_ENABLE_EXTRA_MATH=1;BC_ENABLE_HISTORY=1;BC_ENABLE_NLS=0;BC_DEBUG_CODE=0;BC_ENABLE_LIBRARY=0;BC_ENABLE_EDITLINE=0;BC_ENABLE_READLINE=0;BUILD_TYPE=N;BC_DEFAULT_BANNER=1;BC_DEFAULT_SIGINT_RESET=0;DC_DEFAULT_SIGINT_RESET=0;BC_DEFAULT_TTY_MODE=1;DC_DEFAULT_TTY_MODE=1;BC_DEFAULT_PROMPT=1;DC_DEFAULT_PROMPT=1;BC_DEFAULT_EXPR_EXIT=1;DC_DEFAULT_EXPR_EXIT=1;BC_DEFAULT_DIGIT_CLAMP=1;DC_DEFAULT_DIGIT_CLAMP=1;WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<PreprocessorDefinitions>BC_ENABLED=1;DC_ENABLED=1;BC_ENABLE_EXTRA_MATH=1;BC_ENABLE_HISTORY=1;BC_ENABLE_NLS=0;BC_DEBUG_CODE=0;BC_ENABLE_LIBRARY=0;BC_ENABLE_EDITLINE=0;BC_ENABLE_READLINE=0;BC_ENABLE_OSSFUZZ=0;BUILD_TYPE=N;BC_DEFAULT_BANNER=1;BC_DEFAULT_SIGINT_RESET=0;DC_DEFAULT_SIGINT_RESET=0;BC_DEFAULT_TTY_MODE=1;DC_DEFAULT_TTY_MODE=1;BC_DEFAULT_PROMPT=1;DC_DEFAULT_PROMPT=1;BC_DEFAULT_EXPR_EXIT=1;DC_DEFAULT_EXPR_EXIT=1;BC_DEFAULT_DIGIT_CLAMP=1;DC_DEFAULT_DIGIT_CLAMP=1;WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<AdditionalIncludeDirectories>..\include</AdditionalIncludeDirectories>
|
||||
<RuntimeLibrary>MultiThreaded</RuntimeLibrary>
|
||||
<ConformanceMode>true</ConformanceMode>
|
||||
@ -147,7 +147,7 @@
|
||||
<AdditionalOptions>/std:c17 /MP $(AdditionalOptions)</AdditionalOptions>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<SDLCheck>true</SDLCheck>
|
||||
<PreprocessorDefinitions>BC_ENABLED=1;DC_ENABLED=1;BC_ENABLE_EXTRA_MATH=1;BC_ENABLE_HISTORY=1;BC_ENABLE_NLS=0;BC_DEBUG_CODE=0;BC_ENABLE_LIBRARY=0;BC_ENABLE_EDITLINE=0;BC_ENABLE_READLINE=0;BUILD_TYPE=N;BC_DEFAULT_BANNER=1;BC_DEFAULT_SIGINT_RESET=0;DC_DEFAULT_SIGINT_RESET=0;BC_DEFAULT_TTY_MODE=1;DC_DEFAULT_TTY_MODE=1;BC_DEFAULT_PROMPT=1;DC_DEFAULT_PROMPT=1;BC_DEFAULT_EXPR_EXIT=1;DC_DEFAULT_EXPR_EXIT=1;BC_DEFAULT_DIGIT_CLAMP=1;DC_DEFAULT_DIGIT_CLAMP=1;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<PreprocessorDefinitions>BC_ENABLED=1;DC_ENABLED=1;BC_ENABLE_EXTRA_MATH=1;BC_ENABLE_HISTORY=1;BC_ENABLE_NLS=0;BC_DEBUG_CODE=0;BC_ENABLE_LIBRARY=0;BC_ENABLE_EDITLINE=0;BC_ENABLE_READLINE=0;BC_ENABLE_OSSFUZZ=0;BUILD_TYPE=N;BC_DEFAULT_BANNER=1;BC_DEFAULT_SIGINT_RESET=0;DC_DEFAULT_SIGINT_RESET=0;BC_DEFAULT_TTY_MODE=1;DC_DEFAULT_TTY_MODE=1;BC_DEFAULT_PROMPT=1;DC_DEFAULT_PROMPT=1;BC_DEFAULT_EXPR_EXIT=1;DC_DEFAULT_EXPR_EXIT=1;BC_DEFAULT_DIGIT_CLAMP=1;DC_DEFAULT_DIGIT_CLAMP=1;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<AdditionalIncludeDirectories>..\include</AdditionalIncludeDirectories>
|
||||
<RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary>
|
||||
<ConformanceMode>true</ConformanceMode>
|
||||
@ -168,7 +168,7 @@
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<IntrinsicFunctions>true</IntrinsicFunctions>
|
||||
<SDLCheck>true</SDLCheck>
|
||||
<PreprocessorDefinitions>BC_ENABLED=1;DC_ENABLED=1;BC_ENABLE_EXTRA_MATH=1;BC_ENABLE_HISTORY=1;BC_ENABLE_NLS=0;BC_DEBUG_CODE=0;BC_ENABLE_LIBRARY=0;BC_ENABLE_EDITLINE=0;BC_ENABLE_READLINE=0;BUILD_TYPE=N;BC_DEFAULT_BANNER=1;BC_DEFAULT_SIGINT_RESET=0;DC_DEFAULT_SIGINT_RESET=0;BC_DEFAULT_TTY_MODE=1;DC_DEFAULT_TTY_MODE=1;BC_DEFAULT_PROMPT=1;DC_DEFAULT_PROMPT=1;BC_DEFAULT_EXPR_EXIT=1;DC_DEFAULT_EXPR_EXIT=1;BC_DEFAULT_DIGIT_CLAMP=1;DC_DEFAULT_DIGIT_CLAMP=1;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<PreprocessorDefinitions>BC_ENABLED=1;DC_ENABLED=1;BC_ENABLE_EXTRA_MATH=1;BC_ENABLE_HISTORY=1;BC_ENABLE_NLS=0;BC_DEBUG_CODE=0;BC_ENABLE_LIBRARY=0;BC_ENABLE_EDITLINE=0;BC_ENABLE_READLINE=0;BC_ENABLE_OSSFUZZ=0;BUILD_TYPE=N;BC_DEFAULT_BANNER=1;BC_DEFAULT_SIGINT_RESET=0;DC_DEFAULT_SIGINT_RESET=0;BC_DEFAULT_TTY_MODE=1;DC_DEFAULT_TTY_MODE=1;BC_DEFAULT_PROMPT=1;DC_DEFAULT_PROMPT=1;BC_DEFAULT_EXPR_EXIT=1;DC_DEFAULT_EXPR_EXIT=1;BC_DEFAULT_DIGIT_CLAMP=1;DC_DEFAULT_DIGIT_CLAMP=1;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<AdditionalIncludeDirectories>..\include</AdditionalIncludeDirectories>
|
||||
<RuntimeLibrary>MultiThreaded</RuntimeLibrary>
|
||||
<FunctionLevelLinking>true</FunctionLevelLinking>
|
||||
@ -299,4 +299,4 @@
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
||||
<ImportGroup Label="ExtensionTargets">
|
||||
</ImportGroup>
|
||||
</Project>
|
||||
</Project>
|
79
include/ossfuzz.h
Normal file
79
include/ossfuzz.h
Normal file
@ -0,0 +1,79 @@
|
||||
/*
|
||||
* *****************************************************************************
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*
|
||||
* Copyright (c) 2018-2024 Gavin D. Howard and contributors.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright notice, this
|
||||
* list of conditions and the following disclaimer.
|
||||
*
|
||||
* * Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* *****************************************************************************
|
||||
*
|
||||
* Declarations for the OSS-Fuzz build of bc and dc.
|
||||
*
|
||||
*/
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#ifndef BC_OSSFUZZ_H
|
||||
#define BC_OSSFUZZ_H
|
||||
|
||||
/// The number of args in fuzzer arguments, including the NULL terminator.
|
||||
extern const size_t bc_fuzzer_args_len;
|
||||
|
||||
/// The standard arguments for the bc fuzzer with the -c argument.
|
||||
extern const char* bc_fuzzer_args_c[];
|
||||
|
||||
/// The standard arguments for the bc fuzzer with the -C argument.
|
||||
extern const char* bc_fuzzer_args_C[];
|
||||
|
||||
/// The standard arguments for the dc fuzzer with the -c argument.
|
||||
extern const char* dc_fuzzer_args_c[];
|
||||
|
||||
/// The standard arguments for the dc fuzzer with the -C argument.
|
||||
extern const char* dc_fuzzer_args_C[];
|
||||
|
||||
/// The data pointer.
|
||||
extern uint8_t* bc_fuzzer_data;
|
||||
|
||||
/**
|
||||
* The function that the fuzzer runs.
|
||||
* @param Data The data.
|
||||
* @param Size The number of bytes in @a Data.
|
||||
* @return 0 on success, -1 on error.
|
||||
* @pre @a Data must not be equal to NULL if @a Size > 0.
|
||||
*/
|
||||
int
|
||||
LLVMFuzzerTestOneInput(const uint8_t* Data, size_t Size);
|
||||
|
||||
/**
|
||||
* The initialization function for the fuzzer.
|
||||
* @param argc A pointer to the argument count.
|
||||
* @param argv A pointer to the argument list.
|
||||
* @return 0 on success, -1 on error.
|
||||
*/
|
||||
int
|
||||
LLVMFuzzerInitialize(int* argc, char*** argv);
|
||||
|
||||
#endif // BC_OSSFUZZ_H
|
Loading…
Reference in New Issue
Block a user