[PATCH] dc: Fix segfault when executing strings generated using asciify
Brian Foley
bpfoley at google.com
Sun Jun 30 03:18:09 UTC 2019
---
miscutils/bc.c | 10 ++++++++--
testsuite/dc.tests | 6 ++++++
2 files changed, 14 insertions(+), 2 deletions(-)
diff --git a/miscutils/bc.c b/miscutils/bc.c
index 82425b39c..6b2c75ac0 100644
--- a/miscutils/bc.c
+++ b/miscutils/bc.c
@@ -4973,7 +4973,9 @@ static void dc_parse_string(void)
xc_parse_pushInst_and_Index(XC_INST_STR, len);
bc_vec_push(&G.prog.strs, &str);
- // Explanation needed here
+ // Add an empty function so that if zdc_program_execStr ever needs to
+ // parse the string into code (from the 'x' command) there's somewhere
+ // to store the bytecode.
xc_program_add_fn();
p->func = xc_program_func(p->fidx);
@@ -6398,7 +6400,11 @@ static BC_STATUS zdc_program_asciify(void)
str = xzalloc(2);
str[0] = c;
//str[1] = '\0'; - already is
- bc_vec_push(&G.prog.strs, &str);
+ idx = bc_vec_push(&G.prog.strs, &str);
+ // Add an empty function so that if zdc_program_execStr ever needs to
+ // parse the string into code (from the 'x' command) there's somewhere
+ // to store the bytecode.
+ xc_program_add_fn();
dup:
res.t = XC_RESULT_STR;
res.d.id.idx = idx;
diff --git a/testsuite/dc.tests b/testsuite/dc.tests
index 89c5c2406..65b71101d 100755
--- a/testsuite/dc.tests
+++ b/testsuite/dc.tests
@@ -51,6 +51,12 @@ testing "dc: x should not execute or pop non-strings" \
"42\n" \
"" ""
+testing "dc: x should work with strings created from a" \
+ "dc -e'42 112 a x'" \
+ "42\n" \
+ "" ""
+
+
optional FEATURE_DC_BIG
# All tests below depend on FEATURE_DC_BIG
--
2.17.1
More information about the busybox
mailing list