Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.busybox.net/busybox.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBrian Foley <bpfoley@google.com>2019-09-05 11:46:22 +0300
committerDenys Vlasenko <vda.linux@googlemail.com>2019-10-21 17:54:40 +0300
commit4699b932446f809d747d97f8e24b5d48608f7276 (patch)
tree5d761ac8e1b891871ddf6d96490e28df541bc945
parent244c0ebb4f71fb9f400d2242bbdeaca0c138c547 (diff)
dc: execute shouldn't pop if stack head is not a string
This matches the behaviour of both GNU dc (as specified in its man page), and BSD dc (where stack_popstring() pops only if the head is a string.) Add a couple of tests to verify this behavior. function old new delta zxc_vm_process 6882 6884 +2 Signed-off-by: Brian Foley <bpfoley@google.com> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r--miscutils/bc.c3
-rwxr-xr-xtestsuite/dc.tests10
2 files changed, 12 insertions, 1 deletions
diff --git a/miscutils/bc.c b/miscutils/bc.c
index aba51e5f8..9a9880706 100644
--- a/miscutils/bc.c
+++ b/miscutils/bc.c
@@ -6521,7 +6521,7 @@ static BC_STATUS zdc_program_execStr(char *code, size_t *bgn, bool cond)
if (s || !BC_PROG_STR(n)) goto exit;
sidx = n->rdx;
} else
- goto exit;
+ goto exit_nopop;
}
fidx = sidx + BC_PROG_REQ_FUNCS;
@@ -6561,6 +6561,7 @@ static BC_STATUS zdc_program_execStr(char *code, size_t *bgn, bool cond)
RETURN_STATUS(BC_STATUS_SUCCESS);
exit:
bc_vec_pop(&G.prog.results);
+ exit_nopop:
RETURN_STATUS(s);
}
#define zdc_program_execStr(...) (zdc_program_execStr(__VA_ARGS__) COMMA_SUCCESS)
diff --git a/testsuite/dc.tests b/testsuite/dc.tests
index 8c3af4156..f74e3f0f5 100755
--- a/testsuite/dc.tests
+++ b/testsuite/dc.tests
@@ -44,6 +44,16 @@ testing "dc complex without spaces (multiple args)" \
optional FEATURE_DC_BIG
# All tests below depend on FEATURE_DC_BIG
+testing "dc: x should execute strings" \
+ "dc -e'[40 2 +] x f'" \
+ "42\n" \
+ "" ""
+
+testing "dc: x should not execute or pop non-strings" \
+ "dc -e'42 x f'" \
+ "42\n" \
+ "" ""
+
testing "dc read" \
"dc -finput" \
"2\n9\n1\n" \