bc: better handle optional args of bc_program_pushVar()
authorDenys Vlasenko <vda.linux@googlemail.com>
Sun, 2 Dec 2018 19:57:17 +0000 (20:57 +0100)
committerDenys Vlasenko <vda.linux@googlemail.com>
Wed, 5 Dec 2018 14:43:35 +0000 (15:43 +0100)
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
miscutils/bc.c

index 4257511f0aabbffc556f6e71b4fe15ff8742a085..ee05cd4b4cdcf3c60dec4337f81e51e3e3a83b91 100644 (file)
@@ -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