hust testsuite: fix a false positive
[oweals/busybox.git] / miscutils / dc.c
index a7bd360d223eedbee91fe38228b93e93280ed4b3..4d92bc3d04244359849d663bbd31611f041ee927 100644 (file)
@@ -4,6 +4,7 @@
  */
 
 #include "libbb.h"
+#include "common_bufsiz.h"
 #include <math.h>
 
 //usage:#define dc_trivial_usage
@@ -47,15 +48,22 @@ struct globals {
        double stack[1];
 } FIX_ALIASING;
 enum { STACK_SIZE = (COMMON_BUFSIZE - offsetof(struct globals, stack)) / sizeof(double) };
-#define G (*(struct globals*)&bb_common_bufsiz1)
+#define G (*(struct globals*)bb_common_bufsiz1)
 #define pointer   (G.pointer   )
 #define base      (G.base      )
 #define stack     (G.stack     )
 #define INIT_G() do { \
+       setup_common_bufsiz(); \
        base = 10; \
 } while (0)
 
 
+static void check_under(void)
+{
+       if (pointer == 0)
+               bb_error_msg_and_die("stack underflow");
+}
+
 static void push(double a)
 {
        if (pointer >= STACK_SIZE)
@@ -65,8 +73,7 @@ static void push(double a)
 
 static double pop(void)
 {
-       if (pointer == 0)
-               bb_error_msg_and_die("stack underflow");
+       check_under();
        return stack[--pointer];
 }
 
@@ -187,6 +194,7 @@ static void print_stack_no_pop(void)
 
 static void print_no_pop(void)
 {
+       check_under();
        print_base(stack[pointer-1]);
 }
 
@@ -244,9 +252,9 @@ static void stack_machine(const char *argument)
 
        o = operators;
        do {
-               const size_t name_len = strlen(o->name);
-               if (strncmp(o->name, argument, name_len) == 0) {
-                       argument += name_len;
+               char *after_name = is_prefixed_with(argument, o->name);
+               if (after_name) {
+                       argument = after_name;
                        o->function();
                        goto next;
                }