hust testsuite: fix a false positive
[oweals/busybox.git] / miscutils / dc.c
index f94d6fa6b301c17119cfe0bcabfc6c227c24e880..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]);
 }