[Midnightbsd-cvs] src [11557] trunk/usr.bin/dc: sync with freebsd.

laffer1 at midnightbsd.org laffer1 at midnightbsd.org
Sat Jul 7 17:55:06 EDT 2018


Revision: 11557
          http://svnweb.midnightbsd.org/src/?rev=11557
Author:   laffer1
Date:     2018-07-07 17:55:05 -0400 (Sat, 07 Jul 2018)
Log Message:
-----------
sync with freebsd.

Modified Paths:
--------------
    trunk/usr.bin/dc/Makefile
    trunk/usr.bin/dc/bcode.c
    trunk/usr.bin/dc/bcode.h
    trunk/usr.bin/dc/dc.1
    trunk/usr.bin/dc/dc.c
    trunk/usr.bin/dc/extern.h
    trunk/usr.bin/dc/inout.c
    trunk/usr.bin/dc/mem.c
    trunk/usr.bin/dc/stack.c

Property Changed:
----------------
    trunk/usr.bin/dc/dc.1

Modified: trunk/usr.bin/dc/Makefile
===================================================================
--- trunk/usr.bin/dc/Makefile	2018-07-07 21:54:14 UTC (rev 11556)
+++ trunk/usr.bin/dc/Makefile	2018-07-07 21:55:05 UTC (rev 11557)
@@ -1,9 +1,9 @@
-#	$MidnightBSD$
+# $MidnightBSD$
+#	$FreeBSD: stable/10/usr.bin/dc/Makefile 227299 2011-11-07 09:42:22Z ed $
 #	$OpenBSD: Makefile,v 1.2 2006/11/26 11:31:09 deraadt Exp $
 
 PROG=	dc
 SRCS=	dc.c bcode.c inout.c mem.c stack.c
-CFLAGS+=--param max-inline-insns-single=64
 DPADD=	${LIBCRYPTO}
 LDADD=	-lcrypto
 

Modified: trunk/usr.bin/dc/bcode.c
===================================================================
--- trunk/usr.bin/dc/bcode.c	2018-07-07 21:54:14 UTC (rev 11556)
+++ trunk/usr.bin/dc/bcode.c	2018-07-07 21:55:05 UTC (rev 11557)
@@ -1,4 +1,5 @@
-/*	$OpenBSD: bcode.c,v 1.40 2009/10/27 23:59:37 deraadt Exp $	*/
+/* $MidnightBSD$ */
+/*	$OpenBSD: bcode.c,v 1.45 2012/11/07 11:06:14 otto Exp $	*/
 
 /*
  * Copyright (c) 2003, Otto Moerbeek <otto at drijf.net>
@@ -17,7 +18,7 @@
  */
 
 #include <sys/cdefs.h>
-__MBSDID("$MidnightBSD$");
+__FBSDID("$FreeBSD: stable/10/usr.bin/dc/bcode.c 315135 2017-03-12 05:36:31Z pfg $");
 
 #include <err.h>
 #include <limits.h>
@@ -29,10 +30,8 @@
 
 #include "extern.h"
 
-BIGNUM		zero;
+/* #define	DEBUGGING */
 
-#define __inline	
-
 #define MAX_ARRAY_INDEX		2048
 #define READSTACK_SIZE		8
 
@@ -250,10 +249,14 @@
 	if (bmachine.readstack == NULL)
 		err(1, NULL);
 	bmachine.obase = bmachine.ibase = 10;
-	BN_init(&zero);
-	bn_check(BN_zero(&zero));
 }
 
+u_int
+bmachine_scale(void)
+{
+	return bmachine.scale;
+}
+
 /* Reset the things needed before processing a (new) file */
 void
 reset_bmachine(struct source *src)
@@ -407,7 +410,7 @@
 	}
 }
 
-__inline void
+void
 normalize(struct number *n, u_int s)
 {
 
@@ -426,8 +429,7 @@
 void
 negate(struct number *n)
 {
-
-	bn_check(BN_sub(n->number, &zero, n->number));
+	BN_set_negative(n->number, !BN_is_negative(n->number));
 }
 
 static __inline void
@@ -581,7 +583,7 @@
 
 	n = pop_number();
 	if (n != NULL) {
-		if (BN_cmp(n->number, &zero) < 0)
+		if (BN_is_negative(n->number))
 			warnx("scale must be a nonnegative number");
 		else {
 			scale = get_ulong(n);
@@ -693,7 +695,7 @@
 	u_int i;
 
 	if (BN_is_zero(n->number))
-		return (n->scale ? n->scale : 1);
+		return n->scale ? n->scale : 1;
 
 	int_part = new_number();
 	fract_part = new_number();
@@ -878,7 +880,7 @@
 		if (inumber == NULL)
 			return;
 		idx = get_ulong(inumber);
-		if (BN_cmp(inumber->number, &zero) < 0)
+		if (BN_is_negative(inumber->number))
 			warnx("negative idx");
 		else if (idx == BN_MASK2 || idx > MAX_ARRAY_INDEX)
 			warnx("idx too big");
@@ -917,7 +919,7 @@
 			return;
 		}
 		idx = get_ulong(inumber);
-		if (BN_cmp(inumber->number, &zero) < 0) {
+		if (BN_is_negative(inumber->number)) {
 			warnx("negative idx");
 			stack_free_value(value);
 		} else if (idx == BN_MASK2 || idx > MAX_ARRAY_INDEX) {
@@ -959,9 +961,8 @@
 	struct number	*a, *b, *r;
 
 	a = pop_number();
-	if (a == NULL) {
+	if (a == NULL)
 		return;
-	}
 	b = pop_number();
 	if (b == NULL) {
 		push_number(a);
@@ -986,9 +987,8 @@
 	struct number	*a, *b, *r;
 
 	a = pop_number();
-	if (a == NULL) {
+	if (a == NULL)
 		return;
-	}
 	b = pop_number();
 	if (b == NULL) {
 		push_number(a);
@@ -1009,7 +1009,7 @@
 }
 
 void
-bmul_number(struct number *r, struct number *a, struct number *b)
+bmul_number(struct number *r, struct number *a, struct number *b, u_int scale)
 {
 	BN_CTX *ctx;
 
@@ -1023,11 +1023,9 @@
 	bn_check(BN_mul(r->number, a->number, b->number, ctx));
 	BN_CTX_free(ctx);
 
-	if (rscale > bmachine.scale && rscale > ascale && rscale > bscale) {
-		r->scale = rscale;
-		normalize(r, max(bmachine.scale, max(ascale, bscale)));
-	} else
-		r->scale = rscale;
+	r->scale = rscale;
+	if (rscale > bmachine.scale && rscale > ascale && rscale > bscale)
+		normalize(r, max(scale, max(ascale, bscale)));
 }
 
 static void
@@ -1036,9 +1034,8 @@
 	struct number *a, *b, *r;
 
 	a = pop_number();
-	if (a == NULL) {
+	if (a == NULL)
 		return;
-	}
 	b = pop_number();
 	if (b == NULL) {
 		push_number(a);
@@ -1046,7 +1043,7 @@
 	}
 
 	r = new_number();
-	bmul_number(r, a, b);
+	bmul_number(r, a, b, bmachine.scale);
 
 	push_number(r);
 	free_number(a);
@@ -1061,9 +1058,8 @@
 	u_int scale;
 
 	a = pop_number();
-	if (a == NULL) {
+	if (a == NULL)
 		return;
-	}
 	b = pop_number();
 	if (b == NULL) {
 		push_number(a);
@@ -1098,9 +1094,8 @@
 	u_int scale;
 
 	a = pop_number();
-	if (a == NULL) {
+	if (a == NULL)
 		return;
-	}
 	b = pop_number();
 	if (b == NULL) {
 		push_number(a);
@@ -1135,9 +1130,8 @@
 	u_int scale;
 
 	a = pop_number();
-	if (a == NULL) {
+	if (a == NULL)
 		return;
-	}
 	b = pop_number();
 	if (b == NULL) {
 		push_number(a);
@@ -1171,14 +1165,14 @@
 static void
 bexp(void)
 {
-	struct number *a, *p, *r;
-	u_int scale;
-	bool neg;
+	struct number	*a, *p;
+	struct number	*r;
+	bool		neg;
+	u_int		rscale;
 
 	p = pop_number();
-	if (p == NULL) {
+	if (p == NULL)
 		return;
-	}
 	a = pop_number();
 	if (a == NULL) {
 		push_number(p);
@@ -1185,15 +1179,26 @@
 		return;
 	}
 
-	if (p->scale != 0)
-		warnx("Runtime warning: non-zero scale in exponent");
+	if (p->scale != 0) {
+		BIGNUM *i, *f;
+		i = BN_new();
+		bn_checkp(i);
+		f = BN_new();
+		bn_checkp(f);
+		split_number(p, i, f);
+		if (!BN_is_zero(f))
+			warnx("Runtime warning: non-zero fractional part in exponent");
+		BN_free(i);
+		BN_free(f);
+	}
+
 	normalize(p, 0);
 
 	neg = false;
-	if (BN_cmp(p->number, &zero) < 0) {
+	if (BN_is_negative(p->number)) {
 		neg = true;
 		negate(p);
-		scale = bmachine.scale;
+		rscale = bmachine.scale;
 	} else {
 		/* Posix bc says min(a.scale * b, max(a.scale, scale) */
 		u_long b;
@@ -1201,30 +1206,37 @@
 
 		b = BN_get_word(p->number);
 		m = max(a->scale, bmachine.scale);
-		scale = a->scale * (u_int)b;
-		if (scale > m || (a->scale > 0 && (b == BN_MASK2 ||
+		rscale = a->scale * (u_int)b;
+		if (rscale > m || (a->scale > 0 && (b == BN_MASK2 ||
 		    b > UINT_MAX)))
-			scale = m;
+			rscale = m;
 	}
 
 	if (BN_is_zero(p->number)) {
 		r = new_number();
 		bn_check(BN_one(r->number));
-		normalize(r, scale);
+		normalize(r, rscale);
 	} else {
+		u_int ascale, mscale;
+
+		ascale = a->scale;
 		while (!BN_is_bit_set(p->number, 0)) {
-			bmul_number(a, a, a);
+			ascale *= 2;
+			bmul_number(a, a, a, ascale);
 			bn_check(BN_rshift1(p->number, p->number));
 		}
 
 		r = dup_number(a);
-		normalize(r, scale);
 		bn_check(BN_rshift1(p->number, p->number));
 
+		mscale = ascale;
 		while (!BN_is_zero(p->number)) {
-			bmul_number(a, a, a);
-			if (BN_is_bit_set(p->number, 0))
-				bmul_number(r, r, a);
+			ascale *= 2;
+			bmul_number(a, a, a, ascale);
+			if (BN_is_bit_set(p->number, 0)) {
+				mscale += ascale;
+				bmul_number(r, r, a, mscale);
+			}
 			bn_check(BN_rshift1(p->number, p->number));
 		}
 
@@ -1237,13 +1249,18 @@
 			bn_check(BN_one(one));
 			ctx = BN_CTX_new();
 			bn_checkp(ctx);
-			scale_number(one, r->scale + scale);
-			normalize(r, scale);
-			bn_check(BN_div(r->number, NULL, one, r->number, ctx));
+			scale_number(one, r->scale + rscale);
+
+			if (BN_is_zero(r->number))
+				warnx("divide by zero");
+			else
+				bn_check(BN_div(r->number, NULL, one,
+				    r->number, ctx));
 			BN_free(one);
 			BN_CTX_free(ctx);
+			r->scale = rscale;
 		} else
-			normalize(r, scale);
+			normalize(r, rscale);
 	}
 	push_number(r);
 	free_number(a);
@@ -1276,13 +1293,12 @@
 
 	onecount = 0;
 	n = pop_number();
-	if (n == NULL) {
+	if (n == NULL)
 		return;
-	}
 	if (BN_is_zero(n->number)) {
 		r = new_number();
 		push_number(r);
-	} else if (BN_cmp(n->number, &zero) < 0)
+	} else if (BN_is_negative(n->number))
 		warnx("square root of negative number");
 	else {
 		scale = max(bmachine.scale, n->scale);
@@ -1319,9 +1335,8 @@
 	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);
@@ -1340,9 +1355,8 @@
 	struct number *a, *b, *r;
 
 	a = pop_number();
-	if (a == NULL) {
+	if (a == NULL)
 		return;
-	}
 	b = pop_number();
 	if (b == NULL) {
 		push_number(a);
@@ -1360,9 +1374,8 @@
 	struct number *a, *b, *r;
 
 	a = pop_number();
-	if (a == NULL) {
+	if (a == NULL)
 		return;
-	}
 	b = pop_number();
 	if (b == NULL) {
 		push_number(a);
@@ -1380,9 +1393,8 @@
 	struct number *a, *b, *r;
 
 	a = pop_number();
-	if (a == NULL) {
+	if (a == NULL)
 		return;
-	}
 	b = pop_number();
 	if (b == NULL) {
 		push_number(a);
@@ -1713,9 +1725,8 @@
 	char *p;
 
 	p = pop_string();
-	if (p == NULL)
-		return;
-	eval_string(p);
+	if (p != NULL)
+		eval_string(p);
 }
 
 void

Modified: trunk/usr.bin/dc/bcode.h
===================================================================
--- trunk/usr.bin/dc/bcode.h	2018-07-07 21:54:14 UTC (rev 11556)
+++ trunk/usr.bin/dc/bcode.h	2018-07-07 21:55:05 UTC (rev 11557)
@@ -1,5 +1,6 @@
-/*	$MidnightBSD$						*/
-/*	$OpenBSD: bcode.h,v 1.5 2006/01/16 08:09:25 otto Exp $	*/
+/* $MidnightBSD$ */
+/*	$FreeBSD: stable/10/usr.bin/dc/bcode.h 265533 2014-05-07 08:06:54Z delphij $						*/
+/*	$OpenBSD: bcode.h,v 1.7 2012/11/07 11:06:14 otto Exp $	*/
 
 /*
  * Copyright (c) 2003, Otto Moerbeek <otto at drijf.net>
@@ -83,16 +84,15 @@
 	int		 lastchar;
 };
 
-void			 init_bmachine(bool);
-void			 reset_bmachine(struct source *);
-void			 scale_number(BIGNUM *, int);
-void			 normalize(struct number *, u_int);
-void			 eval(void);
-void			 pn(const char *, const struct number *);
-void			 pbn(const char *, const BIGNUM *);
-void			 negate(struct number *);
-void			 split_number(const struct number *, BIGNUM *, BIGNUM *);
-void			 bmul_number(struct number *, struct number *,
-			    struct number *);
-
-extern BIGNUM		 zero;
+void			init_bmachine(bool);
+void			reset_bmachine(struct source *);
+u_int			bmachine_scale(void);
+void			scale_number(BIGNUM *, int);
+void			normalize(struct number *, u_int);
+void			eval(void);
+void			pn(const char *, const struct number *);
+void			pbn(const char *, const BIGNUM *);
+void			negate(struct number *);
+void			split_number(const struct number *, BIGNUM *, BIGNUM *);
+void			bmul_number(struct number *, struct number *,
+			    struct number *, u_int scale);

Modified: trunk/usr.bin/dc/dc.1
===================================================================
--- trunk/usr.bin/dc/dc.1	2018-07-07 21:54:14 UTC (rev 11556)
+++ trunk/usr.bin/dc/dc.1	2018-07-07 21:55:05 UTC (rev 11557)
@@ -1,5 +1,6 @@
-.\"	$MidnightBSD$
-.\"	$OpenBSD: dc.1,v 1.24 2010/01/02 19:48:56 schwarze Exp $
+.\" $MidnightBSD$
+.\"	$FreeBSD: stable/10/usr.bin/dc/dc.1 265533 2014-05-07 08:06:54Z delphij $
+.\"	$OpenBSD: dc.1,v 1.27 2012/08/19 12:07:21 jmc Exp $
 .\"
 .\" Copyright (C) Caldera International Inc.  2001-2002.
 .\" All rights reserved.
@@ -35,7 +36,7 @@
 .\"
 .\"	@(#)dc.1	8.1 (Berkeley) 6/6/93
 .\"
-.Dd January 22, 2010
+.Dd April 16, 2014
 .Dt DC 1
 .Os
 .Sh NAME
@@ -73,12 +74,6 @@
 If multiple
 .Fl e
 options are specified, they will be processed in the order given.
-If no
-.Ar filename
-argument is given, execution will stop after processing the expressions
-given on the command line,
-otherwise processing will continue with the contents of
-.Ar filename .
 .It Fl f Ar filename , Fl Fl file Ar filename
 Process the content of the given file before further calculations are done.
 If multiple
@@ -98,14 +93,26 @@
 for a more detailed description.
 .El
 .Pp
+If neither
+.Ar expression
+nor
+.Ar file
+are specified on the command line,
+.Nm
+reads from the standard input.
+Otherwise
+.Ar expression
+and
+.Ar file
+are processed and
+.Nm
+exits.
+.Pp
 Ordinarily,
 .Nm
 operates on decimal integers,
 but one may specify an input base, output base,
 and a number of fractional digits (scale) to be maintained.
-If an argument is given,
-input is taken from that file until its end,
-then from the standard input.
 Whitespace is ignored, except where it signals the end of a number,
 end of a line or when a register name is expected.
 The following constructions are recognized:
@@ -315,7 +322,7 @@
 and decimal point.
 .It Ic z
 The stack level is pushed onto the stack.
-.It Cm [ Ns ... Ns Cm ]
+.It Cm \&[ Ns ... Ns Cm \&]
 Puts the bracketed
 .Tn ASCII
 string onto the top of the stack.
@@ -375,12 +382,12 @@
 .It Ic \&?
 A line of input is taken from the input source (usually the terminal)
 and executed.
-.It Ic : Ns Ar r
+.It Ic \&: Ns Ar r
 Pop two values from the stack.
 The second value on the stack is stored into the array
 .Ar r
 indexed by the top of stack.
-.It Ic ; Ns Ar r
+.It Ic \&; Ns Ar r
 Pop a value from the stack.
 The value is used as an index into register
 .Ar r .


Property changes on: trunk/usr.bin/dc/dc.1
___________________________________________________________________
Added: svn:keywords
## -0,0 +1 ##
+MidnightBSD=%H
\ No newline at end of property
Modified: trunk/usr.bin/dc/dc.c
===================================================================
--- trunk/usr.bin/dc/dc.c	2018-07-07 21:54:14 UTC (rev 11556)
+++ trunk/usr.bin/dc/dc.c	2018-07-07 21:55:05 UTC (rev 11557)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*	$OpenBSD: dc.c,v 1.11 2009/10/27 23:59:37 deraadt Exp $	*/
 
 /*
@@ -18,7 +19,7 @@
  */
 
 #include <sys/cdefs.h>
-__MBSDID("$MidnightBSD$");
+__FBSDID("$FreeBSD: stable/10/usr.bin/dc/dc.c 315135 2017-03-12 05:36:31Z pfg $");
 
 #include <sys/stat.h>
 
@@ -39,9 +40,9 @@
 
 extern char		*__progname;
 
-struct source		 src;
+static struct source	 src;
 
-struct option long_options[] =
+static const struct option long_options[] =
 {
 	{"expression",		required_argument,	NULL,	'e'},
 	{"file",		required_argument,	NULL,	'f'},
@@ -120,8 +121,8 @@
 
 	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();

Modified: trunk/usr.bin/dc/extern.h
===================================================================
--- trunk/usr.bin/dc/extern.h	2018-07-07 21:54:14 UTC (rev 11556)
+++ trunk/usr.bin/dc/extern.h	2018-07-07 21:55:05 UTC (rev 11557)
@@ -1,4 +1,5 @@
-/*	$MidnightBSD$						*/
+/* $MidnightBSD$ */
+/*	$FreeBSD: stable/10/usr.bin/dc/extern.h 202719 2010-01-20 21:30:52Z gabor $						*/
 /*	$OpenBSD: extern.h,v 1.3 2006/01/16 08:09:25 otto Exp $	*/
 
 /*

Modified: trunk/usr.bin/dc/inout.c
===================================================================
--- trunk/usr.bin/dc/inout.c	2018-07-07 21:54:14 UTC (rev 11556)
+++ trunk/usr.bin/dc/inout.c	2018-07-07 21:55:05 UTC (rev 11557)
@@ -1,4 +1,5 @@
-/*	$OpenBSD: inout.c,v 1.15 2009/10/27 23:59:37 deraadt Exp $	*/
+/* $MidnightBSD$ */
+/*	$OpenBSD: inout.c,v 1.17 2012/11/07 11:06:14 otto Exp $	*/
 
 /*
  * Copyright (c) 2003, Otto Moerbeek <otto at drijf.net>
@@ -17,7 +18,7 @@
  */
 
 #include <sys/cdefs.h>
-__MBSDID("$MidnightBSD$");
+__FBSDID("$FreeBSD: stable/10/usr.bin/dc/inout.c 265533 2014-05-07 08:06:54Z delphij $");
 
 #include <openssl/ssl.h>
 #include <ctype.h>
@@ -322,7 +323,7 @@
 		i++;
 	}
 	sz = i;
-	if (BN_cmp(b->number, &zero) < 0)
+	if (BN_is_negative(b->number))
 		putcharwrap(f, '-');
 	for (i = 0; i < sz; i++) {
 		p = stack_popstring(&stack);
@@ -353,7 +354,8 @@
 				putcharwrap(f, ' ');
 			i = 1;
 
-			bmul_number(fract_part, fract_part, num_base);
+			bmul_number(fract_part, fract_part, num_base,
+			    bmachine_scale());
 			split_number(fract_part, int_part->number, NULL);
 			rem = BN_get_word(int_part->number);
 			p = get_digit(rem, digits, base);
@@ -402,8 +404,8 @@
 	v = BN_dup(n->number);
 	bn_checkp(v);
 
-	if (BN_cmp(v, &zero) < 0)
-		bn_check(BN_sub(v, &zero, v));
+	if (BN_is_negative(v))
+		BN_set_negative(v, 0);
 
 	numbits = BN_num_bytes(v) * 8;
 	while (numbits > 0) {

Modified: trunk/usr.bin/dc/mem.c
===================================================================
--- trunk/usr.bin/dc/mem.c	2018-07-07 21:54:14 UTC (rev 11556)
+++ trunk/usr.bin/dc/mem.c	2018-07-07 21:55:05 UTC (rev 11557)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*	$OpenBSD: mem.c,v 1.5 2009/10/27 23:59:37 deraadt Exp $	*/
 
 /*
@@ -17,7 +18,7 @@
  */
 
 #include <sys/cdefs.h>
-__MBSDID("$MidnightBSD$");
+__FBSDID("$FreeBSD: stable/10/usr.bin/dc/mem.c 203443 2010-02-03 21:06:13Z gabor $");
 
 #include <openssl/err.h>
 

Modified: trunk/usr.bin/dc/stack.c
===================================================================
--- trunk/usr.bin/dc/stack.c	2018-07-07 21:54:14 UTC (rev 11556)
+++ trunk/usr.bin/dc/stack.c	2018-07-07 21:55:05 UTC (rev 11557)
@@ -1,4 +1,5 @@
-/*	$OpenBSD: stack.c,v 1.11 2009/10/27 23:59:37 deraadt Exp $	*/
+/* $MidnightBSD$ */
+/*	$OpenBSD: stack.c,v 1.12 2014/11/26 15:05:51 otto Exp $	*/
 
 /*
  * Copyright (c) 2003, Otto Moerbeek <otto at drijf.net>
@@ -17,7 +18,7 @@
  */
 
 #include <sys/cdefs.h>
-__MBSDID("$MidnightBSD$");
+__FBSDID("$FreeBSD: stable/10/usr.bin/dc/stack.c 315135 2017-03-12 05:36:31Z pfg $");
 
 #include <err.h>
 #include <stdlib.h>
@@ -68,10 +69,8 @@
 		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 */
@@ -137,14 +136,12 @@
 static void
 stack_grow(struct stack *stack)
 {
-	size_t i, new_size;
+	size_t new_size;
 
 	if (++stack->sp == stack->size) {
 		new_size = stack->size * 2 + 1;
 		stack->stack = brealloc(stack->stack,
 		    new_size * sizeof(*stack->stack));
-		for (i = stack->size; i < new_size; i++)
-			stack->stack[i].array = NULL;
 		stack->size = new_size;
 	}
 }
@@ -156,6 +153,7 @@
 	stack_grow(stack);
 	stack->stack[stack->sp].type = BCODE_NUMBER;
 	stack->stack[stack->sp].u.num = b;
+	stack->stack[stack->sp].array = NULL;
 }
 
 void
@@ -165,6 +163,7 @@
 	stack_grow(stack);
 	stack->stack[stack->sp].type = BCODE_STRING;
 	stack->stack[stack->sp].u.string = string;
+	stack->stack[stack->sp].array = NULL;
 }
 
 void
@@ -225,10 +224,8 @@
 
 	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 +239,8 @@
 
 	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 +252,8 @@
 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);
 }



More information about the Midnightbsd-cvs mailing list