aboutsummaryrefslogtreecommitdiff
path: root/miscutils
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2015-05-25 13:31:25 +0200
committerDenys Vlasenko <vda.linux@googlemail.com>2015-05-25 13:31:25 +0200
commitc4603fb09aa2ec06bc8c0ad51b69fe7995a8ea17 (patch)
tree659cdbc8b34b5caa584f3d49738f57cd5f5fd28f /miscutils
parentb878121e76730f7f7e458180363371dbe10fd253 (diff)
downloadbusybox-w32-c4603fb09aa2ec06bc8c0ad51b69fe7995a8ea17.tar.gz
busybox-w32-c4603fb09aa2ec06bc8c0ad51b69fe7995a8ea17.tar.bz2
busybox-w32-c4603fb09aa2ec06bc8c0ad51b69fe7995a8ea17.zip
dc: fix "dc p" prinitng bogus data
function old new delta check_under - 20 +20 print_no_pop 27 32 +5 pop 33 24 -9 ------------------------------------------------------------------------------ (add/remove: 1/0 grow/shrink: 1/1 up/down: 25/-9) Total: 16 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'miscutils')
-rw-r--r--miscutils/dc.c10
1 files changed, 8 insertions, 2 deletions
diff --git a/miscutils/dc.c b/miscutils/dc.c
index f94d6fa6b..9c74172ba 100644
--- a/miscutils/dc.c
+++ b/miscutils/dc.c
@@ -56,6 +56,12 @@ enum { STACK_SIZE = (COMMON_BUFSIZE - offsetof(struct globals, stack)) / sizeof(
56} while (0) 56} while (0)
57 57
58 58
59static void check_under(void)
60{
61 if (pointer == 0)
62 bb_error_msg_and_die("stack underflow");
63}
64
59static void push(double a) 65static void push(double a)
60{ 66{
61 if (pointer >= STACK_SIZE) 67 if (pointer >= STACK_SIZE)
@@ -65,8 +71,7 @@ static void push(double a)
65 71
66static double pop(void) 72static double pop(void)
67{ 73{
68 if (pointer == 0) 74 check_under();
69 bb_error_msg_and_die("stack underflow");
70 return stack[--pointer]; 75 return stack[--pointer];
71} 76}
72 77
@@ -187,6 +192,7 @@ static void print_stack_no_pop(void)
187 192
188static void print_no_pop(void) 193static void print_no_pop(void)
189{ 194{
195 check_under();
190 print_base(stack[pointer-1]); 196 print_base(stack[pointer-1]);
191} 197}
192 198