summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2018-12-02 20:57:17 +0100
committerDenys Vlasenko <vda.linux@googlemail.com>2018-12-05 15:43:35 +0100
commit416ce76bcd26084099f430367f88387fced1c34e (patch)
treed9c172123233e762f5a47be1a3fbd1e32c12e028
parent9721f6c8b0b5a22313fb546af5959d69ac6b59ef (diff)
bc: better handle optional args of bc_program_pushVar()
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r--miscutils/bc.c49
1 files changed, 25 insertions, 24 deletions
diff --git a/miscutils/bc.c b/miscutils/bc.c
index 4257511f0..ee05cd4b4 100644
--- a/miscutils/bc.c
+++ b/miscutils/bc.c
@@ -5872,49 +5872,50 @@ static BcStatus bc_program_assign(char inst)
return s;
}
+#if !ENABLE_DC
+#define bc_program_pushVar(code, bgn, pop, copy) \
+ bc_program_pushVar(code, bgn)
+// for bc, 'pop' and 'copy' are always false
+#endif
static BcStatus bc_program_pushVar(char *code, size_t *bgn,
bool pop, bool copy)
{
BcStatus s = BC_STATUS_SUCCESS;
BcResult r;
char *name = bc_program_name(code, bgn);
-#if ENABLE_DC // Exclude
- BcNum *num;
- BcVec *v;
-#else
- (void) pop, (void) copy;
-#endif
r.t = BC_RESULT_VAR;
r.d.id.name = name;
#if ENABLE_DC
- v = bc_program_search(name, true);
- num = bc_vec_top(v);
+ {
+ BcVec *v = bc_program_search(name, true);
+ BcNum *num = bc_vec_top(v);
- if (pop || copy) {
+ if (pop || copy) {
+
+ if (!BC_PROG_STACK(v, 2 - copy)) {
+ free(name);
+ return BC_STATUS_EXEC_STACK;
+ }
- if (!BC_PROG_STACK(v, 2 - copy)) {
free(name);
- return BC_STATUS_EXEC_STACK;
- }
+ name = NULL;
- free(name);
- name = NULL;
+ if (!BC_PROG_STR(num)) {
- if (!BC_PROG_STR(num)) {
+ r.t = BC_RESULT_TEMP;
- r.t = BC_RESULT_TEMP;
+ bc_num_init(&r.d.n, BC_NUM_DEF_SIZE);
+ bc_num_copy(&r.d.n, num);
+ }
+ else {
+ r.t = BC_RESULT_STR;
+ r.d.id.idx = num->rdx;
+ }
- bc_num_init(&r.d.n, BC_NUM_DEF_SIZE);
- bc_num_copy(&r.d.n, num);
- }
- else {
- r.t = BC_RESULT_STR;
- r.d.id.idx = num->rdx;
+ if (!copy) bc_vec_pop(v);
}
-
- if (!copy) bc_vec_pop(v);
}
#endif // ENABLE_DC