aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorStefan Eßer <se@FreeBSD.org>2023-03-03 22:15:06 +0000
committerStefan Eßer <se@FreeBSD.org>2023-03-03 22:15:06 +0000
commit0ff539eb7ca570d65a23a7ad13a91a673d89abcf (patch)
treed22a622e1a23b8541471a7a7531aa2fd9c48f937 /tests
parent61e1a12bb6c3bfdb0a4e499c88e8eaa2b548e427 (diff)
vendor/bc: import version 6.4.0vendor/bc/6.4.0
This version contains a fix for an issue that can affect complex bc scripts that use multiple read() functions that receive input from an interactive user. The same value could be returned multiple times.
Diffstat (limited to 'tests')
-rw-r--r--tests/bcl.c52
-rwxr-xr-xtests/read.sh13
2 files changed, 58 insertions, 7 deletions
diff --git a/tests/bcl.c b/tests/bcl.c
index cea63f457cd4..5bb50c29a753 100644
--- a/tests/bcl.c
+++ b/tests/bcl.c
@@ -55,7 +55,7 @@ main(void)
BclError e;
BclContext ctxt;
size_t scale;
- BclNumber n, n2, n3, n4, n5, n6;
+ BclNumber n, n2, n3, n4, n5, n6, n7;
char* res;
BclBigDig b = 0;
@@ -124,9 +124,21 @@ main(void)
if (!bcl_num_neg(n4)) err(BCL_ERROR_FATAL_UNKNOWN_ERR);
// Add them and check the result.
+ n5 = bcl_add_keep(n3, n4);
+ err(bcl_err(n5));
+ res = bcl_string(n5);
+ if (res == NULL) err(BCL_ERROR_FATAL_ALLOC_ERR);
+ if (strcmp(res, "-25452.9108273")) err(BCL_ERROR_FATAL_UNKNOWN_ERR);
+
+ // We want to ensure all memory gets freed because we run this under
+ // Valgrind.
+ free(res);
+
+ // Add them and check the result.
n3 = bcl_add(n3, n4);
err(bcl_err(n3));
- res = bcl_string(bcl_dup(n3));
+ res = bcl_string_keep(n3);
+ if (res == NULL) err(BCL_ERROR_FATAL_ALLOC_ERR);
if (strcmp(res, "-25452.9108273")) err(BCL_ERROR_FATAL_UNKNOWN_ERR);
// We want to ensure all memory gets freed because we run this under
@@ -136,19 +148,29 @@ main(void)
// Ensure that divmod, a special case, works.
n4 = bcl_parse("8937458902.2890347");
err(bcl_err(n4));
- e = bcl_divmod(bcl_dup(n4), n3, &n5, &n6);
+ e = bcl_divmod_keep(n4, n3, &n5, &n6);
err(e);
res = bcl_string(n5);
-
if (strcmp(res, "-351137.0060159482")) err(BCL_ERROR_FATAL_UNKNOWN_ERR);
-
free(res);
res = bcl_string(n6);
-
if (strcmp(res, ".00000152374405414")) err(BCL_ERROR_FATAL_UNKNOWN_ERR);
+ free(res);
+
+ // Ensure that divmod, a special case, works.
+ n4 = bcl_parse("8937458902.2890347");
+ err(bcl_err(n4));
+ e = bcl_divmod(bcl_dup(n4), n3, &n5, &n6);
+ err(e);
+
+ res = bcl_string(n5);
+ if (strcmp(res, "-351137.0060159482")) err(BCL_ERROR_FATAL_UNKNOWN_ERR);
+ free(res);
+ res = bcl_string(n6);
+ if (strcmp(res, ".00000152374405414")) err(BCL_ERROR_FATAL_UNKNOWN_ERR);
free(res);
// Ensure that sqrt works. This is also a special case. The reason is
@@ -214,10 +236,18 @@ main(void)
err(bcl_err(n3));
// Repeat.
+ n2 = bcl_ifrand_keep(n3, 10);
+ err(bcl_err(n2));
+
+ // Repeat.
n2 = bcl_ifrand(bcl_dup(n3), 10);
err(bcl_err(n2));
// Still checking asserts.
+ e = bcl_rand_seedWithNum_keep(n3);
+ err(e);
+
+ // Still checking asserts.
e = bcl_rand_seedWithNum(n3);
err(e);
@@ -229,9 +259,12 @@ main(void)
n5 = bcl_parse("10");
err(bcl_err(n5));
- n6 = bcl_modexp(bcl_dup(n5), bcl_dup(n5), bcl_dup(n5));
+ n6 = bcl_modexp_keep(n5, n5, n5);
err(bcl_err(n6));
+ n7 = bcl_modexp(bcl_dup(n5), bcl_dup(n5), bcl_dup(n5));
+ err(bcl_err(n7));
+
// Clean up.
bcl_num_free(n);
@@ -250,6 +283,11 @@ main(void)
n4 = bcl_parse("-1.01");
err(bcl_err(n4));
+ res = bcl_string_keep(n);
+ if (strcmp(res, ".01")) err(BCL_ERROR_FATAL_UNKNOWN_ERR);
+
+ free(res);
+
res = bcl_string(bcl_dup(n));
if (strcmp(res, ".01")) err(BCL_ERROR_FATAL_UNKNOWN_ERR);
diff --git a/tests/read.sh b/tests/read.sh
index d7be18fdcecb..4881c10db58c 100755
--- a/tests/read.sh
+++ b/tests/read.sh
@@ -74,6 +74,7 @@ results="$testdir/$d/read_results.txt"
errors="$testdir/$d/read_errors.txt"
out="$outputdir/${d}_outputs/read_results.txt"
+multiple_res="$outputdir/${d}_outputs/read_multiple_results.txt"
outdir=$(dirname "$out")
# Make sure the directory exists.
@@ -89,11 +90,13 @@ if [ "$d" = "bc" ]; then
halt="halt"
read_call="read()"
read_expr="${read_call}\n5+5;"
+ read_multiple=$(printf '%s\n%s\n%s\n' "3" "2" "1")
else
options="-x"
halt="q"
read_call="?"
read_expr="${read_call}"
+ read_multiple=$(printf '%spR\n%spR\n%spR\n' "3" "2" "1")
fi
# I use these, so unset them to make the tests work.
@@ -116,6 +119,16 @@ done < "$name"
printf 'pass\n'
+printf 'Running %s read multiple...' "$d"
+
+printf '3\n2\n1\n' > "$multiple_res"
+
+# Run multiple read() calls.
+printf '%s\n' "$read_multiple" | "$exe" "$@" "$options" -e "$read_call" -e "$read_call" -e "$read_call" > "$out"
+checktest "$d" "$?" 'read multiple' "$multiple_res" "$out"
+
+printf 'pass\n'
+
printf 'Running %s read errors...' "$d"
# Run read on every line.