summaryrefslogtreecommitdiff
path: root/usr.bin/dc
diff options
context:
space:
mode:
authorPedro F. Giffuni <pfg@FreeBSD.org>2017-02-26 22:17:06 +0000
committerPedro F. Giffuni <pfg@FreeBSD.org>2017-02-26 22:17:06 +0000
commit6ef0daee41ed4e6932af5716aab34417780037c2 (patch)
treec9124fecde79bbc9e0700ef2c43fc0ee54e3ffb8 /usr.bin/dc
parentb62c1f2b18a00ff0fa83e07ba9287b7c1d98aab0 (diff)
downloadsrc-test2-6ef0daee41ed4e6932af5716aab34417780037c2.tar.gz
src-test2-6ef0daee41ed4e6932af5716aab34417780037c2.zip
dc(1): Merge minor changes from OpenBSD.
Prefer setvbuf() to setlinebuf() for portability. Some style(9) and redundant tests for NULL. These are only meant to ease up merging newer changes but we are skipping changes done in order to accomodate OpenBSD's pledge support. Obtained from: OpenBSD MFC after: 2 weeks
Notes
Notes: svn path=/head/; revision=314321
Diffstat (limited to 'usr.bin/dc')
-rw-r--r--usr.bin/dc/bcode.c41
-rw-r--r--usr.bin/dc/dc.c4
-rw-r--r--usr.bin/dc/stack.c21
3 files changed, 23 insertions, 43 deletions
diff --git a/usr.bin/dc/bcode.c b/usr.bin/dc/bcode.c
index 52ce85c00c9d..2834e4f2b1c9 100644
--- a/usr.bin/dc/bcode.c
+++ b/usr.bin/dc/bcode.c
@@ -960,9 +960,8 @@ badd(void)
struct number *a, *b, *r;
a = pop_number();
- if (a == NULL) {
+ if (a == NULL)
return;
- }
b = pop_number();
if (b == NULL) {
push_number(a);
@@ -987,9 +986,8 @@ bsub(void)
struct number *a, *b, *r;
a = pop_number();
- if (a == NULL) {
+ if (a == NULL)
return;
- }
b = pop_number();
if (b == NULL) {
push_number(a);
@@ -1035,9 +1033,8 @@ bmul(void)
struct number *a, *b, *r;
a = pop_number();
- if (a == NULL) {
+ if (a == NULL)
return;
- }
b = pop_number();
if (b == NULL) {
push_number(a);
@@ -1060,9 +1057,8 @@ bdiv(void)
u_int scale;
a = pop_number();
- if (a == NULL) {
+ if (a == NULL)
return;
- }
b = pop_number();
if (b == NULL) {
push_number(a);
@@ -1097,9 +1093,8 @@ bmod(void)
u_int scale;
a = pop_number();
- if (a == NULL) {
+ if (a == NULL)
return;
- }
b = pop_number();
if (b == NULL) {
push_number(a);
@@ -1134,9 +1129,8 @@ bdivmod(void)
u_int scale;
a = pop_number();
- if (a == NULL) {
+ if (a == NULL)
return;
- }
b = pop_number();
if (b == NULL) {
push_number(a);
@@ -1176,9 +1170,8 @@ bexp(void)
u_int rscale;
p = pop_number();
- if (p == NULL) {
+ if (p == NULL)
return;
- }
a = pop_number();
if (a == NULL) {
push_number(p);
@@ -1299,9 +1292,8 @@ bsqrt(void)
onecount = 0;
n = pop_number();
- if (n == NULL) {
+ if (n == NULL)
return;
- }
if (BN_is_zero(n->number)) {
r = new_number();
push_number(r);
@@ -1342,9 +1334,8 @@ not(void)
struct number *a;
a = pop_number();
- if (a == NULL) {
+ if (a == NULL)
return;
- }
a->scale = 0;
bn_check(BN_set_word(a->number, BN_get_word(a->number) ? 0 : 1));
push_number(a);
@@ -1363,9 +1354,8 @@ equal_numbers(void)
struct number *a, *b, *r;
a = pop_number();
- if (a == NULL) {
+ if (a == NULL)
return;
- }
b = pop_number();
if (b == NULL) {
push_number(a);
@@ -1383,9 +1373,8 @@ less_numbers(void)
struct number *a, *b, *r;
a = pop_number();
- if (a == NULL) {
+ if (a == NULL)
return;
- }
b = pop_number();
if (b == NULL) {
push_number(a);
@@ -1403,9 +1392,8 @@ lesseq_numbers(void)
struct number *a, *b, *r;
a = pop_number();
- if (a == NULL) {
+ if (a == NULL)
return;
- }
b = pop_number();
if (b == NULL) {
push_number(a);
@@ -1736,9 +1724,8 @@ eval_tos(void)
char *p;
p = pop_string();
- if (p == NULL)
- return;
- eval_string(p);
+ if (p != NULL)
+ eval_string(p);
}
void
diff --git a/usr.bin/dc/dc.c b/usr.bin/dc/dc.c
index 8f2cf51fb3bd..a2cf8c92e346 100644
--- a/usr.bin/dc/dc.c
+++ b/usr.bin/dc/dc.c
@@ -125,8 +125,8 @@ main(int argc, char *argv[])
if (!preproc_done)
init_bmachine(extended_regs);
- setlinebuf(stdout);
- setlinebuf(stderr);
+ (void)setvbuf(stdout, NULL, _IOLBF, 0);
+ (void)setvbuf(stderr, NULL, _IOLBF, 0);
if (argc > 1)
usage();
diff --git a/usr.bin/dc/stack.c b/usr.bin/dc/stack.c
index 6b0c0d189193..33082c77ec04 100644
--- a/usr.bin/dc/stack.c
+++ b/usr.bin/dc/stack.c
@@ -68,10 +68,8 @@ stack_free_value(struct value *v)
free(v->u.string);
break;
}
- if (v->array != NULL) {
- array_free(v->array);
- v->array = NULL;
- }
+ array_free(v->array);
+ v->array = NULL;
}
/* Copy number or string content into already allocated target */
@@ -225,10 +223,8 @@ stack_popnumber(struct stack *stack)
if (stack_empty(stack))
return (NULL);
- if (stack->stack[stack->sp].array != NULL) {
- array_free(stack->stack[stack->sp].array);
- stack->stack[stack->sp].array = NULL;
- }
+ array_free(stack->stack[stack->sp].array);
+ stack->stack[stack->sp].array = NULL;
if (stack->stack[stack->sp].type != BCODE_NUMBER) {
warnx("not a number"); /* XXX remove */
return (NULL);
@@ -242,10 +238,8 @@ stack_popstring(struct stack *stack)
if (stack_empty(stack))
return (NULL);
- if (stack->stack[stack->sp].array != NULL) {
- array_free(stack->stack[stack->sp].array);
- stack->stack[stack->sp].array = NULL;
- }
+ array_free(stack->stack[stack->sp].array);
+ stack->stack[stack->sp].array = NULL;
if (stack->stack[stack->sp].type != BCODE_STRING) {
warnx("not a string"); /* XXX remove */
return (NULL);
@@ -257,9 +251,8 @@ void
stack_clear(struct stack *stack)
{
- while (stack->sp >= 0) {
+ while (stack->sp >= 0)
stack_free_value(&stack->stack[stack->sp--]);
- }
free(stack->stack);
stack_init(stack);
}