Module Name:    src
Committed By:   christos
Date:           Mon Apr 10 16:37:49 UTC 2017

Modified Files:
        src/usr.bin/dc: Makefile bcode.c dc.1 dc.c inout.c main.c mem.c stack.c
        src/usr.bin/dc/USD.doc: Makefile
Added Files:
        src/usr.bin/dc: misc.c

Log Message:
build fixes.


To generate a diff of this commit:
cvs rdiff -u -r1.1.1.1 -r1.2 src/usr.bin/dc/Makefile src/usr.bin/dc/bcode.c \
    src/usr.bin/dc/dc.1 src/usr.bin/dc/dc.c src/usr.bin/dc/inout.c \
    src/usr.bin/dc/main.c src/usr.bin/dc/mem.c src/usr.bin/dc/stack.c
cvs rdiff -u -r0 -r1.1 src/usr.bin/dc/misc.c
cvs rdiff -u -r1.1.1.1 -r1.2 src/usr.bin/dc/USD.doc/Makefile

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/usr.bin/dc/Makefile
diff -u src/usr.bin/dc/Makefile:1.1.1.1 src/usr.bin/dc/Makefile:1.2
--- src/usr.bin/dc/Makefile:1.1.1.1	Mon Apr 10 12:34:18 2017
+++ src/usr.bin/dc/Makefile	Mon Apr 10 12:37:48 2017
@@ -1,9 +1,25 @@
-#	$OpenBSD: Makefile,v 1.3 2015/10/10 19:28:54 deraadt Exp $
+#	$NetBSD: Makefile,v 1.2 2017/04/10 16:37:48 christos Exp $
+
+.include <bsd.own.mk>
 
 PROG=	dc
 SRCS=	main.c dc.c bcode.c inout.c mem.c stack.c
-COPTS+= -Wall
+
+.if ${MKCRYPTO:Uno} == "yes"
+WARNS=6
 LDADD=	-lcrypto
 DPADD=	${LIBCRYPTO}
+.else
+OPENSSL=${NETBSDSRCDIR}/crypto/external/bsd/openssl/dist
+.PATH: ${OPENSSL}/crypto/bn
+CPPFLAGS+=-I${OPENSSL} -I${OPENSSL}/crypto
+SRCS+= bn_lib.c bn_add.c bn_mul.c bn_div.c bn_asm.c bn_word.c bn_shift.c
+SRCS+= bn_ctx.c bn_exp.c bn_mod.c bn_sqr.c bn_mont.c bn_recp.c bn_gcd.c
+SRCS+= misc.c
+COPTS.bn_lib.c += -Wno-cast-qual
+.endif
+
+SUBDIR+=USD.doc
 
 .include <bsd.prog.mk>
+.include <bsd.subdir.mk>
Index: src/usr.bin/dc/bcode.c
diff -u src/usr.bin/dc/bcode.c:1.1.1.1 src/usr.bin/dc/bcode.c:1.2
--- src/usr.bin/dc/bcode.c:1.1.1.1	Mon Apr 10 12:34:18 2017
+++ src/usr.bin/dc/bcode.c	Mon Apr 10 12:37:48 2017
@@ -1,3 +1,4 @@
+/*	$NetBSD: bcode.c,v 1.2 2017/04/10 16:37:48 christos Exp $	*/
 /*	$OpenBSD: bcode.c,v 1.51 2017/02/26 11:29:55 otto Exp $	*/
 
 /*
@@ -15,6 +16,8 @@
  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  */
+#include <sys/cdefs.h>
+__RCSID("$NetBSD: bcode.c,v 1.2 2017/04/10 16:37:48 christos Exp $");
 
 #include <err.h>
 #include <limits.h>
@@ -227,7 +230,7 @@ sighandler(int ignored)
 void
 init_bmachine(bool extended_registers)
 {
-	int i;
+	size_t i;
 
 	bmachine.extended_regs = extended_registers;
 	bmachine.reg_array_size = bmachine.extended_regs ?
@@ -342,12 +345,12 @@ static unsigned long factors[] = {
 void
 scale_number(BIGNUM *n, int s)
 {
-	int abs_scale;
+	size_t abs_scale;
 
 	if (s == 0)
 		return;
 
-	abs_scale = s > 0 ? s : -s;
+	abs_scale = (size_t)(s > 0 ? s : -s);
 
 	if (abs_scale < sizeof(factors)/sizeof(factors[0])) {
 		if (s > 0)
@@ -415,7 +418,7 @@ split_number(const struct number *n, BIG
 void
 normalize(struct number *n, u_int s)
 {
-	scale_number(n->number, s - n->scale);
+	scale_number(n->number, (int)(s - n->scale));
 	n->scale = s;
 }
 
@@ -785,7 +788,7 @@ readreg(void)
 		} else
 			idx = (ch1 << 8) + ch2 + UCHAR_MAX + 1;
 	}
-	if (idx < 0 || idx >= bmachine.reg_array_size) {
+	if (idx < 0 || (size_t)idx >= bmachine.reg_array_size) {
 		warnx("internal error: reg num = %d", idx);
 		idx = -1;
 	}
@@ -1244,7 +1247,7 @@ bexp(void)
 			bn_check(BN_one(one));
 			ctx = BN_CTX_new();
 			bn_checkp(ctx);
-			scale_number(one, r->scale + rscale);
+			scale_number(one, (int)(r->scale + rscale));
 
 			if (BN_is_zero(r->number))
 				warnx("divide by zero");
@@ -1683,11 +1686,10 @@ eval_string(char *p)
 	}
 	if (bmachine.readsp == bmachine.readstack_sz - 1) {
 		size_t newsz = bmachine.readstack_sz * 2;
-		struct source *stack;
-		stack = reallocarray(bmachine.readstack, newsz,
-		    sizeof(struct source));
-		if (stack == NULL)
-			err(1, "recursion too deep");
+		struct source *stack = bmachine.readstack;
+		int ret = reallocarr(&stack, newsz, sizeof(struct source));
+		if (ret)
+			errc(1, ret, "recursion too deep");
 		bmachine.readstack_sz = newsz;
 		bmachine.readstack = stack;
 	}
Index: src/usr.bin/dc/dc.1
diff -u src/usr.bin/dc/dc.1:1.1.1.1 src/usr.bin/dc/dc.1:1.2
--- src/usr.bin/dc/dc.1:1.1.1.1	Mon Apr 10 12:34:18 2017
+++ src/usr.bin/dc/dc.1	Mon Apr 10 12:37:48 2017
@@ -1,3 +1,4 @@
+.\"	$NetBSD: dc.1,v 1.2 2017/04/10 16:37:48 christos Exp $
 .\"	$OpenBSD: dc.1,v 1.30 2017/02/23 06:40:17 otto Exp $
 .\"
 .\" Copyright (C) Caldera International Inc.  2001-2002.
@@ -34,7 +35,7 @@
 .\"
 .\"	@(#)dc.1	8.1 (Berkeley) 6/6/93
 .\"
-.Dd $Mdocdate: February 23 2017 $
+.Dd February 23, 2017
 .Dt DC 1
 .Os
 .Sh NAME
Index: src/usr.bin/dc/dc.c
diff -u src/usr.bin/dc/dc.c:1.1.1.1 src/usr.bin/dc/dc.c:1.2
--- src/usr.bin/dc/dc.c:1.1.1.1	Mon Apr 10 12:34:18 2017
+++ src/usr.bin/dc/dc.c	Mon Apr 10 12:37:48 2017
@@ -1,3 +1,4 @@
+/*	$NetBSD: dc.c,v 1.2 2017/04/10 16:37:48 christos Exp $	*/
 /*	$OpenBSD: dc.c,v 1.18 2016/07/17 17:30:47 otto Exp $	*/
 
 /*
@@ -15,6 +16,8 @@
  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  */
+#include <sys/cdefs.h>
+__RCSID("$NetBSD: dc.c,v 1.2 2017/04/10 16:37:48 christos Exp $");
 
 #include <sys/stat.h>
 #include <err.h>
@@ -27,13 +30,11 @@
 
 static __dead void	usage(void);
 
-extern char		*__progname;
-
 static __dead void
 usage(void)
 {
 	(void)fprintf(stderr, "usage: %s [-x] [-e expression] [file]\n",
-	    __progname);
+	    getprogname());
 	exit(1);
 }
 
@@ -91,8 +92,10 @@ dc_main(int argc, char *argv[])
 		if (file == NULL)
 			err(1, "cannot open file %s", argv[0]);
 
+#ifdef __OpenBSD__
 		if (pledge("stdio", NULL) == -1)
 			err(1, "pledge");
+#endif
 
 		if (fstat(fileno(file), &st) == -1)
 			err(1, "%s", argv[0]);
@@ -109,8 +112,10 @@ dc_main(int argc, char *argv[])
 		 return (0);
 	}
 
+#ifdef __OpenBSD__
 	if (pledge("stdio", NULL) == -1)
 		err(1, "pledge");
+#endif
 
 	src_setstream(&src, stdin);
 	reset_bmachine(&src);
Index: src/usr.bin/dc/inout.c
diff -u src/usr.bin/dc/inout.c:1.1.1.1 src/usr.bin/dc/inout.c:1.2
--- src/usr.bin/dc/inout.c:1.1.1.1	Mon Apr 10 12:34:18 2017
+++ src/usr.bin/dc/inout.c	Mon Apr 10 12:37:48 2017
@@ -1,3 +1,4 @@
+/*	$NetBSD: inout.c,v 1.2 2017/04/10 16:37:48 christos Exp $	*/
 /*	$OpenBSD: inout.c,v 1.20 2017/02/26 11:29:55 otto Exp $	*/
 
 /*
@@ -15,6 +16,8 @@
  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  */
+#include <sys/cdefs.h>
+__RCSID("$NetBSD: inout.c,v 1.2 2017/04/10 16:37:48 christos Exp $");
 
 #include <ctype.h>
 #include <err.h>
@@ -129,7 +132,7 @@ src_getlinestring(struct source *src)
 		ch = src_getcharstring(src);
 		if (ch == EOF)
 			break;
-		buf[i++] = ch;
+		buf[i++] = (char)ch;
 		if (ch == '\n')
 			break;
 	}
@@ -191,9 +194,9 @@ readnumber(struct source *src, u_int bas
 	while ((ch = (*src->vtable->readchar)(src)) != EOF) {
 
 		if ('0' <= ch && ch <= '9')
-			v = ch - '0';
+			v = (BN_ULONG)(ch - '0');
 		else if ('A' <= ch && ch <= 'F')
-			v = ch - 'A' + 10;
+			v = (BN_ULONG)(ch - 'A' + 10);
 		else if (ch == '_') {
 			sign = true;
 			continue;
@@ -218,7 +221,7 @@ readnumber(struct source *src, u_int bas
 			bn_check(BN_add_word(n->number, v));
 	}
 	if (base != 10) {
-		scale_number(n->number, n->scale);
+		scale_number(n->number, (int)n->scale);
 		for (i = 0; i < n->scale; i++)
 			(void)BN_div_word(n->number, base);
 	}
@@ -230,7 +233,8 @@ readnumber(struct source *src, u_int bas
 char *
 read_string(struct source *src)
 {
-	int count, i, sz, new_sz, ch;
+	size_t count, i, sz, new_sz;
+	int ch;
 	char *p;
 	bool escape;
 
@@ -258,7 +262,7 @@ read_string(struct source *src)
 				p = breallocarray(p, 1, new_sz + 1);
 				sz = new_sz;
 			}
-			p[i++] = ch;
+			p[i++] = (char)ch;
 		}
 	}
 	p[i] = '\0';
@@ -272,7 +276,7 @@ get_digit(u_long num, int digits, u_int 
 
 	if (base <= 16) {
 		p = bmalloc(2);
-		p[0] = num >= 10 ? num + 'A' - 10 : num + '0';
+		p[0] = (char)(num >= 10 ? num + 'A' - 10 : num + '0');
 		p[1] = '\0';
 	} else {
 		if (asprintf(&p, "%0*lu", digits, num) == -1)
@@ -287,8 +291,7 @@ printnumber(FILE *f, const struct number
 	struct number	*int_part, *fract_part;
 	int		digits;
 	char		buf[11];
-	size_t		sz;
-	int		i;
+	size_t		sz, i;
 	struct stack	stack;
 	char		*p;
 
@@ -337,7 +340,7 @@ printnumber(FILE *f, const struct number
 		bn_check(BN_one(&mult));
 		BN_init(&stop);
 		bn_check(BN_one(&stop));
-		scale_number(&stop, b->scale);
+		scale_number(&stop, (int)b->scale);
 
 		i = 0;
 		while (BN_cmp(&mult, &stop) < 0) {
Index: src/usr.bin/dc/main.c
diff -u src/usr.bin/dc/main.c:1.1.1.1 src/usr.bin/dc/main.c:1.2
--- src/usr.bin/dc/main.c:1.1.1.1	Mon Apr 10 12:34:18 2017
+++ src/usr.bin/dc/main.c	Mon Apr 10 12:37:48 2017
@@ -1,3 +1,4 @@
+/*	$NetBSD: main.c,v 1.2 2017/04/10 16:37:48 christos Exp $	*/
 /*	$OpenBSD: main.c,v 1.1 2015/10/10 19:28:54 deraadt Exp $	*/
 
 /*
@@ -15,6 +16,8 @@
  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  */
+#include <sys/cdefs.h>
+__RCSID("$NetBSD: main.c,v 1.2 2017/04/10 16:37:48 christos Exp $");
 
 #include <err.h>
 #include <stdlib.h>
@@ -27,8 +30,10 @@ main(int argc, char *argv[])
 {
 	setproctitle("dc");
 
+#ifdef __OpenBSD__
 	if (pledge("stdio rpath", NULL) == -1)
 		err(1, "pledge");
+#endif
 
 	return dc_main(argc, argv);
 }
Index: src/usr.bin/dc/mem.c
diff -u src/usr.bin/dc/mem.c:1.1.1.1 src/usr.bin/dc/mem.c:1.2
--- src/usr.bin/dc/mem.c:1.1.1.1	Mon Apr 10 12:34:18 2017
+++ src/usr.bin/dc/mem.c	Mon Apr 10 12:37:48 2017
@@ -1,3 +1,4 @@
+/*	$NetBSD: mem.c,v 1.2 2017/04/10 16:37:48 christos Exp $	*/
 /*	$OpenBSD: mem.c,v 1.7 2015/02/16 20:53:34 jca Exp $	*/
 
 /*
@@ -15,6 +16,8 @@
  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  */
+#include <sys/cdefs.h>
+__RCSID("$NetBSD: mem.c,v 1.2 2017/04/10 16:37:48 christos Exp $");
 
 #include <openssl/err.h>
 
@@ -70,12 +73,10 @@ bmalloc(size_t sz)
 void *
 breallocarray(void *p, size_t nmemb, size_t size)
 {
-	void *q;
-
-	q = reallocarray(p, nmemb, size);
-	if (q == NULL)
-		err(1, NULL);
-	return q;
+	int ret = reallocarr(&p, nmemb, size);
+	if (ret)
+		errc(1, ret, NULL);
+	return p;
 }
 
 char *
Index: src/usr.bin/dc/stack.c
diff -u src/usr.bin/dc/stack.c:1.1.1.1 src/usr.bin/dc/stack.c:1.2
--- src/usr.bin/dc/stack.c:1.1.1.1	Mon Apr 10 12:34:18 2017
+++ src/usr.bin/dc/stack.c	Mon Apr 10 12:37:48 2017
@@ -1,3 +1,4 @@
+/*	$NetBSD: stack.c,v 1.2 2017/04/10 16:37:48 christos Exp $	*/
 /*	$OpenBSD: stack.c,v 1.14 2016/03/27 15:55:13 otto Exp $	*/
 
 /*
@@ -15,6 +16,8 @@
  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  */
+#include <sys/cdefs.h>
+__RCSID("$NetBSD: stack.c,v 1.2 2017/04/10 16:37:48 christos Exp $");
 
 #include <err.h>
 #include <stdlib.h>
@@ -93,7 +96,7 @@ stack_dup_value(const struct value *a, s
 size_t
 stack_size(const struct stack *stack)
 {
-	return stack->sp + 1;
+	return (size_t)(stack->sp + 1);
 }
 
 void
@@ -129,7 +132,7 @@ stack_grow(struct stack *stack)
 {
 	size_t new_size;
 
-	if (++stack->sp == stack->size) {
+	if ((size_t)++stack->sp == stack->size) {
 		new_size = stack->size * 2 + 1;
 		stack->stack = breallocarray(stack->stack,
 		    new_size, sizeof(*stack->stack));

Index: src/usr.bin/dc/USD.doc/Makefile
diff -u src/usr.bin/dc/USD.doc/Makefile:1.1.1.1 src/usr.bin/dc/USD.doc/Makefile:1.2
--- src/usr.bin/dc/USD.doc/Makefile:1.1.1.1	Mon Apr 10 12:34:18 2017
+++ src/usr.bin/dc/USD.doc/Makefile	Mon Apr 10 12:37:48 2017
@@ -1,13 +1,8 @@
-#	$OpenBSD: Makefile,v 1.2 2004/02/01 15:18:01 jmc Exp $
+#	$NetBSD: Makefile,v 1.2 2017/04/10 16:37:48 christos Exp $
 
-DIR=	usd/05.dc
+SECTION=reference/ref1
+ARTICLE=dc
 SRCS=	dc
 MACROS=	-ms
 
-paper.ps: ${SRCS}
-	${EQN} ${SRCS} | ${ROFF} > ${.TARGET}
-
-paper.txt: ${SRCS}
-	${EQN} -Tascii ${SRCS} | ${ROFF} -Tascii > ${.TARGET}
-
 .include <bsd.doc.mk>

Added files:

Index: src/usr.bin/dc/misc.c
diff -u /dev/null src/usr.bin/dc/misc.c:1.1
--- /dev/null	Mon Apr 10 12:37:49 2017
+++ src/usr.bin/dc/misc.c	Mon Apr 10 12:37:48 2017
@@ -0,0 +1,73 @@
+/*	$NetBSD: misc.c,v 1.1 2017/04/10 16:37:48 christos Exp $	*/
+
+/*-
+ * Copyright (c) 2017 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+#include <sys/cdefs.h>
+__RCSID("$NetBSD: misc.c,v 1.1 2017/04/10 16:37:48 christos Exp $")
+
+#include <stdlib.h>
+#include <err.h>
+#include <string.h>
+#include <openssl/crypto.h>
+#include <openssl/err.h>
+
+void *
+CRYPTO_malloc(int len, const char *file, int line)
+{
+	void *p = malloc(len);
+	if (p == NULL)
+		err(1, "%s,%d: Can't allocate %d bytes", file, line, len);
+	return p;
+}
+
+void
+CRYPTO_free(void *p)
+{
+	free(p);
+}
+
+void
+CRYPTO_lock(int mode, int type, const char *file, int line)
+{
+}
+
+unsigned long
+ERR_get_error(void)
+{ 
+
+	return 0;
+}
+
+void
+ERR_put_error(int lib, int func, int reason, const char *file, int line)
+{
+}
+
+void
+OPENSSL_cleanse(void *p, size_t l)
+{
+	explicit_memset(p, 0, l);
+}

Reply via email to