CVS commit: src/lib/libc/stdlib

2021-10-29 Thread Nia Alarie
Module Name:src
Committed By:   nia
Date:   Fri Oct 29 10:29:51 UTC 2021

Modified Files:
src/lib/libc/stdlib: radixsort.c

Log Message:
radixsort(3): use reallocarr instead of malloc(x * y)


To generate a diff of this commit:
cvs rdiff -u -r1.19 -r1.20 src/lib/libc/stdlib/radixsort.c

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



CVS commit: src/lib/libc/stdlib

2021-10-29 Thread Nia Alarie
Module Name:src
Committed By:   nia
Date:   Fri Oct 29 10:29:51 UTC 2021

Modified Files:
src/lib/libc/stdlib: radixsort.c

Log Message:
radixsort(3): use reallocarr instead of malloc(x * y)


To generate a diff of this commit:
cvs rdiff -u -r1.19 -r1.20 src/lib/libc/stdlib/radixsort.c

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

Modified files:

Index: src/lib/libc/stdlib/radixsort.c
diff -u src/lib/libc/stdlib/radixsort.c:1.19 src/lib/libc/stdlib/radixsort.c:1.20
--- src/lib/libc/stdlib/radixsort.c:1.19	Sat Sep  5 08:53:06 2009
+++ src/lib/libc/stdlib/radixsort.c	Fri Oct 29 10:29:51 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: radixsort.c,v 1.19 2009/09/05 08:53:06 dsl Exp $	*/
+/*	$NetBSD: radixsort.c,v 1.20 2021/10/29 10:29:51 nia Exp $	*/
 
 /*-
  * Copyright (c) 1990, 1993
@@ -37,7 +37,7 @@
 #if 0
 static char sccsid[] = "@(#)radixsort.c	8.2 (Berkeley) 4/28/95";
 #else
-__RCSID("$NetBSD: radixsort.c,v 1.19 2009/09/05 08:53:06 dsl Exp $");
+__RCSID("$NetBSD: radixsort.c,v 1.20 2021/10/29 10:29:51 nia Exp $");
 #endif
 #endif /* LIBC_SCCS and not lint */
 
@@ -129,7 +129,8 @@ sradixsort(const u_char **a, int n, cons
 	if (n < THRESHOLD)
 		simplesort(a, n, 0, tr, endch);
 	else {
-		if ((ta = malloc(n * sizeof(a))) == NULL)
+		ta = NULL;
+		if (reallocarr(, n, sizeof(a)) != 0)
 			return (-1);
 		r_sort_b(a, ta, n, 0, tr, endch);
 		free(ta);



CVS commit: src/games/atc

2021-10-29 Thread Nia Alarie
Module Name:src
Committed By:   nia
Date:   Fri Oct 29 11:44:22 UTC 2021

Modified Files:
src/games/atc: grammar.y

Log Message:
atc(6): simplify reallocation logic


To generate a diff of this commit:
cvs rdiff -u -r1.12 -r1.13 src/games/atc/grammar.y

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

Modified files:

Index: src/games/atc/grammar.y
diff -u src/games/atc/grammar.y:1.12 src/games/atc/grammar.y:1.13
--- src/games/atc/grammar.y:1.12	Fri Jun 19 06:02:31 2015
+++ src/games/atc/grammar.y	Fri Oct 29 11:44:22 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: grammar.y,v 1.12 2015/06/19 06:02:31 dholland Exp $	*/
+/*	$NetBSD: grammar.y,v 1.13 2021/10/29 11:44:22 nia Exp $	*/
 
 /*-
  * Copyright (c) 1990, 1993
@@ -62,7 +62,7 @@
 #if 0
 static char sccsid[] = "@(#)grammar.y	8.1 (Berkeley) 5/31/93";
 #else
-__RCSID("$NetBSD: grammar.y,v 1.12 2015/06/19 06:02:31 dholland Exp $");
+__RCSID("$NetBSD: grammar.y,v 1.13 2021/10/29 11:44:22 nia Exp $");
 #endif
 #endif /* not lint */
 
@@ -179,14 +179,8 @@ Bpoint:
 	'(' ConstOp ConstOp ')'
 		{
 		if (sp->num_beacons % REALLOC == 0) {
-			if (sp->beacon == NULL)
-sp->beacon = malloc((sp->num_beacons
-	+ REALLOC) * sizeof (BEACON));
-			else
-sp->beacon = realloc(sp->beacon,
-	(sp->num_beacons + REALLOC) * 
-	sizeof (BEACON));
-			if (sp->beacon == NULL)
+			if (reallocarr(>beacon,
+			sp->num_beacons + REALLOC, sizeof(BEACON)) != 0)
 return (yyerror("No memory available."));
 		}
 		sp->beacon[sp->num_beacons].x = $2;



CVS commit: src/games/atc

2021-10-29 Thread Nia Alarie
Module Name:src
Committed By:   nia
Date:   Fri Oct 29 11:44:22 UTC 2021

Modified Files:
src/games/atc: grammar.y

Log Message:
atc(6): simplify reallocation logic


To generate a diff of this commit:
cvs rdiff -u -r1.12 -r1.13 src/games/atc/grammar.y

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



CVS commit: src/lib/libcrypt

2021-10-29 Thread Nia Alarie
Module Name:src
Committed By:   nia
Date:   Fri Oct 29 13:22:08 UTC 2021

Modified Files:
src/lib/libcrypt: crypt-sha1.c

Log Message:
libcrypt: Fix a floating point exception when a low number of HMAC-SHA1
iterations are specified.


To generate a diff of this commit:
cvs rdiff -u -r1.9 -r1.10 src/lib/libcrypt/crypt-sha1.c

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

Modified files:

Index: src/lib/libcrypt/crypt-sha1.c
diff -u src/lib/libcrypt/crypt-sha1.c:1.9 src/lib/libcrypt/crypt-sha1.c:1.10
--- src/lib/libcrypt/crypt-sha1.c:1.9	Sat Oct 16 10:53:33 2021
+++ src/lib/libcrypt/crypt-sha1.c	Fri Oct 29 13:22:08 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: crypt-sha1.c,v 1.9 2021/10/16 10:53:33 nia Exp $ */
+/* $NetBSD: crypt-sha1.c,v 1.10 2021/10/29 13:22:08 nia Exp $ */
 
 /*
  * Copyright (c) 2004, Juniper Networks, Inc.
@@ -31,7 +31,7 @@
 
 #include 
 #if !defined(lint)
-__RCSID("$NetBSD: crypt-sha1.c,v 1.9 2021/10/16 10:53:33 nia Exp $");
+__RCSID("$NetBSD: crypt-sha1.c,v 1.10 2021/10/29 13:22:08 nia Exp $");
 #endif /* not lint */
 
 #include 
@@ -71,24 +71,15 @@ __RCSID("$NetBSD: crypt-sha1.c,v 1.9 202
 crypt_private unsigned int
 __crypt_sha1_iterations (unsigned int hint)
 {
-static int once = 1;
-
 /*
  * We treat CRYPT_SHA1_ITERATIONS as a hint.
  * Make it harder for someone to pre-compute hashes for a
  * dictionary attack by not using the same iteration count for
  * every entry.
  */
-
-if (once) {
-	int pid = getpid();
-	
-	srandom(time(NULL) ^ (pid * pid));
-	once = 0;
-}
-if (hint == 0)
+if (hint < 4)
 	hint = CRYPT_SHA1_ITERATIONS;
-return hint - (random() % (hint / 4));
+return hint - arc4random_uniform(hint / 4);
 }
 
 /*



CVS commit: src/lib/libcrypt

2021-10-29 Thread Nia Alarie
Module Name:src
Committed By:   nia
Date:   Fri Oct 29 13:22:08 UTC 2021

Modified Files:
src/lib/libcrypt: crypt-sha1.c

Log Message:
libcrypt: Fix a floating point exception when a low number of HMAC-SHA1
iterations are specified.


To generate a diff of this commit:
cvs rdiff -u -r1.9 -r1.10 src/lib/libcrypt/crypt-sha1.c

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



CVS commit: src/lib/libc/citrus

2021-10-29 Thread Nia Alarie
Module Name:src
Committed By:   nia
Date:   Fri Oct 29 10:54:56 UTC 2021

Modified Files:
src/lib/libc/citrus: citrus_db_factory.c

Log Message:
citrus: Use calloc instead of malloc'ing and clearing the array manually


To generate a diff of this commit:
cvs rdiff -u -r1.10 -r1.11 src/lib/libc/citrus/citrus_db_factory.c

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



CVS commit: src/lib/libc/citrus

2021-10-29 Thread Nia Alarie
Module Name:src
Committed By:   nia
Date:   Fri Oct 29 10:54:56 UTC 2021

Modified Files:
src/lib/libc/citrus: citrus_db_factory.c

Log Message:
citrus: Use calloc instead of malloc'ing and clearing the array manually


To generate a diff of this commit:
cvs rdiff -u -r1.10 -r1.11 src/lib/libc/citrus/citrus_db_factory.c

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

Modified files:

Index: src/lib/libc/citrus/citrus_db_factory.c
diff -u src/lib/libc/citrus/citrus_db_factory.c:1.10 src/lib/libc/citrus/citrus_db_factory.c:1.11
--- src/lib/libc/citrus/citrus_db_factory.c:1.10	Sat Sep 14 13:05:51 2013
+++ src/lib/libc/citrus/citrus_db_factory.c	Fri Oct 29 10:54:56 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: citrus_db_factory.c,v 1.10 2013/09/14 13:05:51 joerg Exp $	*/
+/*	$NetBSD: citrus_db_factory.c,v 1.11 2021/10/29 10:54:56 nia Exp $	*/
 
 /*-
  * Copyright (c)2003 Citrus Project,
@@ -32,7 +32,7 @@
 
 #include 
 #if defined(LIBC_SCCS) && !defined(lint)
-__RCSID("$NetBSD: citrus_db_factory.c,v 1.10 2013/09/14 13:05:51 joerg Exp $");
+__RCSID("$NetBSD: citrus_db_factory.c,v 1.11 2021/10/29 10:54:56 nia Exp $");
 #endif /* LIBC_SCCS and not lint */
 
 #include 
@@ -274,11 +274,9 @@ _citrus_db_factory_serialize(struct _cit
 		return 0;
 	}
 	/* allocate hash table */
-	depp = malloc(sizeof(*depp) * df->df_num_entries);
+	depp = calloc(df->df_num_entries, sizeof(*depp));
 	if (depp == NULL)
 		return -1;
-	for (i = 0; i < df->df_num_entries; i++)
-		depp[i] = NULL;
 
 	/* step1: store the entries which are not conflicting */
 	SIMPLEQ_FOREACH(de, >df_entries, de_entry) {



CVS commit: src/share/man/man4

2021-10-29 Thread Nia Alarie
Module Name:src
Committed By:   nia
Date:   Fri Oct 29 10:26:10 UTC 2021

Modified Files:
src/share/man/man4: pdcsata.4

Log Message:
pdcsata.4: Add HISTORY section, fix stray space.


To generate a diff of this commit:
cvs rdiff -u -r1.6 -r1.7 src/share/man/man4/pdcsata.4

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



CVS commit: src/share/man/man4

2021-10-29 Thread Nia Alarie
Module Name:src
Committed By:   nia
Date:   Fri Oct 29 10:26:10 UTC 2021

Modified Files:
src/share/man/man4: pdcsata.4

Log Message:
pdcsata.4: Add HISTORY section, fix stray space.


To generate a diff of this commit:
cvs rdiff -u -r1.6 -r1.7 src/share/man/man4/pdcsata.4

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

Modified files:

Index: src/share/man/man4/pdcsata.4
diff -u src/share/man/man4/pdcsata.4:1.6 src/share/man/man4/pdcsata.4:1.7
--- src/share/man/man4/pdcsata.4:1.6	Mon Oct 19 18:41:09 2009
+++ src/share/man/man4/pdcsata.4	Fri Oct 29 10:26:10 2021
@@ -1,4 +1,4 @@
-.\"	$NetBSD: pdcsata.4,v 1.6 2009/10/19 18:41:09 bouyer Exp $
+.\"	$NetBSD: pdcsata.4,v 1.7 2021/10/29 10:26:10 nia Exp $
 .\"
 .\" Copyright (c) 2003 Manuel Bouyer.
 .\"
@@ -35,7 +35,7 @@ The
 .Nm
 driver supports the Promise SATA150 (PDC20571, PDC20575, PDC20579, PDC20318,
 PDC20319, PDC20371, PDC20375, PDC20376, PDC20377, PDC20378, and PDC20379) and
-SATA300 (PDC20775, PDC40518, PDC40519, PDC40718 , PDC40719 and PDC40779)
+SATA300 (PDC20775, PDC40518, PDC40519, PDC40718, PDC40719 and PDC40779)
 families of serial-ATA controllers, and provides the interface with the
 hardware for the
 .Xr ata 4
@@ -48,3 +48,8 @@ driver.
 .Xr pciide 4 ,
 .Xr wd 4 ,
 .Xr wdc 4
+.Sh HISTORY
+The
+.Nm
+device driver first appeared in
+.Nx 2.1 .



CVS commit: src/games/sail

2021-10-29 Thread Nia Alarie
Module Name:src
Committed By:   nia
Date:   Fri Oct 29 11:42:34 UTC 2021

Modified Files:
src/games/sail: array.c

Log Message:
sail(6): convert realloc(x * y) to reallocarr


To generate a diff of this commit:
cvs rdiff -u -r1.1 -r1.2 src/games/sail/array.c

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

Modified files:

Index: src/games/sail/array.c
diff -u src/games/sail/array.c:1.1 src/games/sail/array.c:1.2
--- src/games/sail/array.c:1.1	Sun Mar 15 03:33:56 2009
+++ src/games/sail/array.c	Fri Oct 29 11:42:34 2021
@@ -73,18 +73,14 @@ int
 array_setsize(struct array *a, unsigned num)
 {
 	unsigned newmax;
-	void **newptr;
 
 	if (num > a->max) {
 		newmax = a->max;
 		while (num > newmax) {
 			newmax = newmax ? newmax*2 : 4;
 		}
-		newptr = realloc(a->v, newmax*sizeof(*a->v));
-		if (newptr == NULL) {
+		if (reallocarr(>v, newmax, sizeof(*a->v)) != 0)
 			return -1;
-		}
-		a->v = newptr;
 		a->max = newmax;
 	}
 	a->num = num;



CVS commit: src/lib/libc

2021-10-29 Thread Nia Alarie
Module Name:src
Committed By:   nia
Date:   Fri Oct 29 11:03:46 UTC 2021

Modified Files:
src/lib/libc/stdlib: radixsort.c
src/lib/libc/string: wcsdup.c

Log Message:
reallocarr does not set errno.


To generate a diff of this commit:
cvs rdiff -u -r1.20 -r1.21 src/lib/libc/stdlib/radixsort.c
cvs rdiff -u -r1.4 -r1.5 src/lib/libc/string/wcsdup.c

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

Modified files:

Index: src/lib/libc/stdlib/radixsort.c
diff -u src/lib/libc/stdlib/radixsort.c:1.20 src/lib/libc/stdlib/radixsort.c:1.21
--- src/lib/libc/stdlib/radixsort.c:1.20	Fri Oct 29 10:29:51 2021
+++ src/lib/libc/stdlib/radixsort.c	Fri Oct 29 11:03:46 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: radixsort.c,v 1.20 2021/10/29 10:29:51 nia Exp $	*/
+/*	$NetBSD: radixsort.c,v 1.21 2021/10/29 11:03:46 nia Exp $	*/
 
 /*-
  * Copyright (c) 1990, 1993
@@ -37,7 +37,7 @@
 #if 0
 static char sccsid[] = "@(#)radixsort.c	8.2 (Berkeley) 4/28/95";
 #else
-__RCSID("$NetBSD: radixsort.c,v 1.20 2021/10/29 10:29:51 nia Exp $");
+__RCSID("$NetBSD: radixsort.c,v 1.21 2021/10/29 11:03:46 nia Exp $");
 #endif
 #endif /* LIBC_SCCS and not lint */
 
@@ -130,8 +130,10 @@ sradixsort(const u_char **a, int n, cons
 		simplesort(a, n, 0, tr, endch);
 	else {
 		ta = NULL;
-		if (reallocarr(, n, sizeof(a)) != 0)
+		if (reallocarr(, n, sizeof(a)) != 0) {
+			errno = ENOMEM;
 			return (-1);
+		}
 		r_sort_b(a, ta, n, 0, tr, endch);
 		free(ta);
 	}

Index: src/lib/libc/string/wcsdup.c
diff -u src/lib/libc/string/wcsdup.c:1.4 src/lib/libc/string/wcsdup.c:1.5
--- src/lib/libc/string/wcsdup.c:1.4	Fri Oct 29 10:11:57 2021
+++ src/lib/libc/string/wcsdup.c	Fri Oct 29 11:03:46 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: wcsdup.c,v 1.4 2021/10/29 10:11:57 nia Exp $	*/
+/*	$NetBSD: wcsdup.c,v 1.5 2021/10/29 11:03:46 nia Exp $	*/
 
 /*
  * Copyright (C) 2006 Aleksey Cheusov
@@ -14,12 +14,13 @@
 #include 
 
 #if defined(LIBC_SCCS) && !defined(lint) 
-__RCSID("$NetBSD: wcsdup.c,v 1.4 2021/10/29 10:11:57 nia Exp $"); 
+__RCSID("$NetBSD: wcsdup.c,v 1.5 2021/10/29 11:03:46 nia Exp $"); 
 #endif /* LIBC_SCCS and not lint */ 
 
 #include "namespace.h"
 #include 
 #include 
+#include 
 #include 
 
 __weak_alias(wcsdup,_wcsdup)
@@ -35,8 +36,10 @@ wcsdup(const wchar_t *str)
 	len = wcslen(str) + 1;
 
 	copy = NULL;
-	if (reallocarr(, len, sizeof(wchar_t)) != 0)
+	if (reallocarr(, len, sizeof(wchar_t)) != 0) {
+		errno = ENOMEM;
 		return NULL;
+	}
 
 	return wmemcpy(copy, str, len);
 }



CVS commit: src/lib/libc

2021-10-29 Thread Nia Alarie
Module Name:src
Committed By:   nia
Date:   Fri Oct 29 11:03:46 UTC 2021

Modified Files:
src/lib/libc/stdlib: radixsort.c
src/lib/libc/string: wcsdup.c

Log Message:
reallocarr does not set errno.


To generate a diff of this commit:
cvs rdiff -u -r1.20 -r1.21 src/lib/libc/stdlib/radixsort.c
cvs rdiff -u -r1.4 -r1.5 src/lib/libc/string/wcsdup.c

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



CVS commit: src/games/hunt/hunt

2021-10-29 Thread Nia Alarie
Module Name:src
Committed By:   nia
Date:   Fri Oct 29 11:40:23 UTC 2021

Modified Files:
src/games/hunt/hunt: server.c

Log Message:
huntd(6): convert malloc(x * y) and realloc(x * y) to reallocarr


To generate a diff of this commit:
cvs rdiff -u -r1.8 -r1.9 src/games/hunt/hunt/server.c

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



CVS commit: src/games/hunt/hunt

2021-10-29 Thread Nia Alarie
Module Name:src
Committed By:   nia
Date:   Fri Oct 29 11:40:23 UTC 2021

Modified Files:
src/games/hunt/hunt: server.c

Log Message:
huntd(6): convert malloc(x * y) and realloc(x * y) to reallocarr


To generate a diff of this commit:
cvs rdiff -u -r1.8 -r1.9 src/games/hunt/hunt/server.c

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

Modified files:

Index: src/games/hunt/hunt/server.c
diff -u src/games/hunt/hunt/server.c:1.8 src/games/hunt/hunt/server.c:1.9
--- src/games/hunt/hunt/server.c:1.8	Sun Mar 30 04:57:37 2014
+++ src/games/hunt/hunt/server.c	Fri Oct 29 11:40:23 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: server.c,v 1.8 2014/03/30 04:57:37 dholland Exp $	*/
+/*	$NetBSD: server.c,v 1.9 2021/10/29 11:40:23 nia Exp $	*/
 /*
  * Copyright (c) 1983-2003, Regents of the University of California.
  * All rights reserved.
@@ -31,7 +31,7 @@
  */
 
 #include 
-__RCSID("$NetBSD: server.c,v 1.8 2014/03/30 04:57:37 dholland Exp $");
+__RCSID("$NetBSD: server.c,v 1.9 2021/10/29 11:40:23 nia Exp $");
 
 #include 
 #include 
@@ -85,10 +85,9 @@ serverlist_setup(const char *explicit_ho
 
 	numdaemons = 0;
 	maxdaemons = 20;
-	daemons = malloc(maxdaemons * sizeof(daemons[0]));
-	if (daemons == NULL) {
+	daemons = NULL;
+	if (reallocarr(, maxdaemons, sizeof(daemons[0])) != 0)
 		leavex(1, "Out of memory.");
-	}
 
 	if (explicit_host_arg) {
 		explicit_host = explicit_host_arg;
@@ -111,10 +110,8 @@ add_daemon_addr(const struct sockaddr_st
 	assert(numdaemons <= maxdaemons);
 	if (numdaemons == maxdaemons) {
 		maxdaemons += 20;
-		daemons = realloc(daemons, maxdaemons * sizeof(daemons[0]));
-		if (daemons == NULL) {
+		if (reallocarr(, maxdaemons, sizeof(daemons[0])) != 0)
 			leave(1, "realloc");
-		}
 	}
 
 	/*
@@ -181,10 +178,9 @@ getbroadcastaddrs(void)
 		}
 	}
 
-	broadcastaddrs = malloc(num * sizeof(broadcastaddrs[0]));
-	if (broadcastaddrs == NULL) {
+	broadcastaddrs = NULL;
+	if (reallocarr(, num, sizeof(broadcastaddrs[0])) != 0)
 		leavex(1, "Out of memory");
-	}
 
 	i = 0;
 	for (ip = ifp; ip; ip = ip->ifa_next) {



CVS commit: src/games/cgram

2021-10-29 Thread Nia Alarie
Module Name:src
Committed By:   nia
Date:   Fri Oct 29 11:45:39 UTC 2021

Modified Files:
src/games/cgram: cgram.c

Log Message:
cgram(6): realloc(x * y) -> reallocarr


To generate a diff of this commit:
cvs rdiff -u -r1.25 -r1.26 src/games/cgram/cgram.c

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



CVS commit: src/games/cgram

2021-10-29 Thread Nia Alarie
Module Name:src
Committed By:   nia
Date:   Fri Oct 29 11:45:39 UTC 2021

Modified Files:
src/games/cgram: cgram.c

Log Message:
cgram(6): realloc(x * y) -> reallocarr


To generate a diff of this commit:
cvs rdiff -u -r1.25 -r1.26 src/games/cgram/cgram.c

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

Modified files:

Index: src/games/cgram/cgram.c
diff -u src/games/cgram/cgram.c:1.25 src/games/cgram/cgram.c:1.26
--- src/games/cgram/cgram.c:1.25	Fri May 28 03:55:45 2021
+++ src/games/cgram/cgram.c	Fri Oct 29 11:45:39 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: cgram.c,v 1.25 2021/05/28 03:55:45 dholland Exp $ */
+/* $NetBSD: cgram.c,v 1.26 2021/10/29 11:45:39 nia Exp $ */
 
 /*-
  * Copyright (c) 2013, 2021 The NetBSD Foundation, Inc.
@@ -31,7 +31,7 @@
 
 #include 
 #if defined(__RCSID) && !defined(lint)
-__RCSID("$NetBSD: cgram.c,v 1.25 2021/05/28 03:55:45 dholland Exp $");
+__RCSID("$NetBSD: cgram.c,v 1.26 2021/10/29 11:45:39 nia Exp $");
 #endif
 
 #include 
@@ -154,8 +154,7 @@ static void
 stringarray_add(struct stringarray *a, struct string *s)
 {
 	size_t num = a->num++;
-	a->v = realloc(a->v, a->num * sizeof a->v[0]);
-	if (a->v == NULL)
+	if (reallocarr(>v, a->num, sizeof(a->v[0])) != 0)
 		errx(1, "Out of memory");
 	a->v[num] = *s;
 }



CVS commit: src/lib/libc/gen

2021-10-29 Thread Nia Alarie
Module Name:src
Committed By:   nia
Date:   Fri Oct 29 10:40:00 UTC 2021

Modified Files:
src/lib/libc/gen: scandir.c

Log Message:
scandir(3): Convert malloc(x * y) and realloc(x * y) to reallocarr


To generate a diff of this commit:
cvs rdiff -u -r1.28 -r1.29 src/lib/libc/gen/scandir.c

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

Modified files:

Index: src/lib/libc/gen/scandir.c
diff -u src/lib/libc/gen/scandir.c:1.28 src/lib/libc/gen/scandir.c:1.29
--- src/lib/libc/gen/scandir.c:1.28	Fri Dec 16 04:45:04 2016
+++ src/lib/libc/gen/scandir.c	Fri Oct 29 10:40:00 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: scandir.c,v 1.28 2016/12/16 04:45:04 mrg Exp $	*/
+/*	$NetBSD: scandir.c,v 1.29 2021/10/29 10:40:00 nia Exp $	*/
 
 /*
  * Copyright (c) 1983, 1993
@@ -34,7 +34,7 @@
 #if 0
 static char sccsid[] = "@(#)scandir.c	8.3 (Berkeley) 1/2/94";
 #else
-__RCSID("$NetBSD: scandir.c,v 1.28 2016/12/16 04:45:04 mrg Exp $");
+__RCSID("$NetBSD: scandir.c,v 1.29 2021/10/29 10:40:00 nia Exp $");
 #endif
 #endif /* LIBC_SCCS and not lint */
 
@@ -91,7 +91,7 @@ scandir(const char *dirname, struct dire
 int (*selectfn)(const struct dirent *),
 int (*dcomp)(const COMPARARG, const COMPARARG))
 {
-	struct dirent *d, *p, **names, **newnames;
+	struct dirent *d, *p, **names;
 	size_t nitems, arraysz;
 	DIR *dirp;
 
@@ -104,8 +104,8 @@ scandir(const char *dirname, struct dire
 	if ((arraysz = dirsize(dirp->dd_fd, 0)) == 0)
 		goto bad;
 
-	names = malloc(arraysz * sizeof(*names));
-	if (names == NULL)
+	names = NULL;
+	if (reallocarr(, arraysz, sizeof(*names)) != 0)
 		goto bad;
 
 	nitems = 0;
@@ -120,10 +120,8 @@ scandir(const char *dirname, struct dire
 		if (nitems >= arraysz) {
 			if ((arraysz = dirsize(dirp->dd_fd, arraysz)) == 0)
 goto bad2;
-			newnames = realloc(names, arraysz * sizeof(*names));
-			if (newnames == NULL)
+			if (reallocarr(, arraysz, sizeof(*names)) != 0)
 goto bad2;
-			names = newnames;
 		}
 
 		/*



CVS commit: src/lib/libc/gen

2021-10-29 Thread Nia Alarie
Module Name:src
Committed By:   nia
Date:   Fri Oct 29 10:40:00 UTC 2021

Modified Files:
src/lib/libc/gen: scandir.c

Log Message:
scandir(3): Convert malloc(x * y) and realloc(x * y) to reallocarr


To generate a diff of this commit:
cvs rdiff -u -r1.28 -r1.29 src/lib/libc/gen/scandir.c

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



CVS commit: src/games/sail

2021-10-29 Thread Nia Alarie
Module Name:src
Committed By:   nia
Date:   Fri Oct 29 11:42:34 UTC 2021

Modified Files:
src/games/sail: array.c

Log Message:
sail(6): convert realloc(x * y) to reallocarr


To generate a diff of this commit:
cvs rdiff -u -r1.1 -r1.2 src/games/sail/array.c

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



CVS commit: src/tests/usr.bin/indent

2021-10-29 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Fri Oct 29 16:49:46 UTC 2021

Modified Files:
src/tests/usr.bin/indent: t_errors.sh

Log Message:
tests/indent: provoke the third occurrence of 'unbalanced parens'


To generate a diff of this commit:
cvs rdiff -u -r1.9 -r1.10 src/tests/usr.bin/indent/t_errors.sh

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



CVS commit: src/tests/usr.bin/indent

2021-10-29 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Fri Oct 29 16:49:46 UTC 2021

Modified Files:
src/tests/usr.bin/indent: t_errors.sh

Log Message:
tests/indent: provoke the third occurrence of 'unbalanced parens'


To generate a diff of this commit:
cvs rdiff -u -r1.9 -r1.10 src/tests/usr.bin/indent/t_errors.sh

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

Modified files:

Index: src/tests/usr.bin/indent/t_errors.sh
diff -u src/tests/usr.bin/indent/t_errors.sh:1.9 src/tests/usr.bin/indent/t_errors.sh:1.10
--- src/tests/usr.bin/indent/t_errors.sh:1.9	Fri Oct 29 16:43:05 2021
+++ src/tests/usr.bin/indent/t_errors.sh	Fri Oct 29 16:49:46 2021
@@ -1,5 +1,5 @@
 #! /bin/sh
-# $NetBSD: t_errors.sh,v 1.9 2021/10/29 16:43:05 rillig Exp $
+# $NetBSD: t_errors.sh,v 1.10 2021/10/29 16:49:46 rillig Exp $
 #
 # Copyright (c) 2021 The NetBSD Foundation, Inc.
 # All rights reserved.
@@ -388,6 +388,26 @@ unbalanced_parentheses_2_body()
 	"$indent" code.c
 }
 
+atf_test_case 'unbalanced_parentheses_3'
+unbalanced_parentheses_3_body()
+{
+	# '({...})' is the GCC extension "Statement expression".
+	cat <<-\EOF > code.c
+		int var =
+		(
+		1
+		}
+		;
+	EOF
+	cat <<-\EOF > stderr.exp
+		error: code.c:4: Unbalanced parens
+		error: code.c:4: Statement nesting error
+	EOF
+
+	atf_check -s 'exit:1' -e 'file:stderr.exp' \
+	"$indent" code.c
+}
+
 
 atf_init_test_cases()
 {
@@ -419,4 +439,5 @@ atf_init_test_cases()
 	atf_add_test_case 'preprocessing_unrecognized'
 	atf_add_test_case 'unbalanced_parentheses_1'
 	atf_add_test_case 'unbalanced_parentheses_2'
+	atf_add_test_case 'unbalanced_parentheses_3'
 }



CVS commit: src

2021-10-29 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Fri Oct 29 16:54:52 UTC 2021

Modified Files:
src/tests/usr.bin/indent: t_errors.sh t_misc.sh token_lparen.c
src/usr.bin/indent: indent.c indent.h lexi.c

Log Message:
indent: spell 'parentheses' properly in messages and comments


To generate a diff of this commit:
cvs rdiff -u -r1.10 -r1.11 src/tests/usr.bin/indent/t_errors.sh
cvs rdiff -u -r1.9 -r1.10 src/tests/usr.bin/indent/t_misc.sh
cvs rdiff -u -r1.7 -r1.8 src/tests/usr.bin/indent/token_lparen.c
cvs rdiff -u -r1.167 -r1.168 src/usr.bin/indent/indent.c
cvs rdiff -u -r1.55 -r1.56 src/usr.bin/indent/indent.h
cvs rdiff -u -r1.107 -r1.108 src/usr.bin/indent/lexi.c

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



CVS commit: src

2021-10-29 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Fri Oct 29 16:54:52 UTC 2021

Modified Files:
src/tests/usr.bin/indent: t_errors.sh t_misc.sh token_lparen.c
src/usr.bin/indent: indent.c indent.h lexi.c

Log Message:
indent: spell 'parentheses' properly in messages and comments


To generate a diff of this commit:
cvs rdiff -u -r1.10 -r1.11 src/tests/usr.bin/indent/t_errors.sh
cvs rdiff -u -r1.9 -r1.10 src/tests/usr.bin/indent/t_misc.sh
cvs rdiff -u -r1.7 -r1.8 src/tests/usr.bin/indent/token_lparen.c
cvs rdiff -u -r1.167 -r1.168 src/usr.bin/indent/indent.c
cvs rdiff -u -r1.55 -r1.56 src/usr.bin/indent/indent.h
cvs rdiff -u -r1.107 -r1.108 src/usr.bin/indent/lexi.c

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

Modified files:

Index: src/tests/usr.bin/indent/t_errors.sh
diff -u src/tests/usr.bin/indent/t_errors.sh:1.10 src/tests/usr.bin/indent/t_errors.sh:1.11
--- src/tests/usr.bin/indent/t_errors.sh:1.10	Fri Oct 29 16:49:46 2021
+++ src/tests/usr.bin/indent/t_errors.sh	Fri Oct 29 16:54:51 2021
@@ -1,5 +1,5 @@
 #! /bin/sh
-# $NetBSD: t_errors.sh,v 1.10 2021/10/29 16:49:46 rillig Exp $
+# $NetBSD: t_errors.sh,v 1.11 2021/10/29 16:54:51 rillig Exp $
 #
 # Copyright (c) 2021 The NetBSD Foundation, Inc.
 # All rights reserved.
@@ -358,8 +358,8 @@ unbalanced_parentheses_1_body()
 		;
 	EOF
 	cat <<-\EOF > stderr.exp
-		error: code.c:3: Unbalanced parens
-		warning: code.c:4: Extra )
+		error: code.c:3: Unbalanced parentheses
+		warning: code.c:4: Extra ')'
 	EOF
 
 	atf_check -s 'exit:1' -e 'file:stderr.exp' \
@@ -380,8 +380,8 @@ unbalanced_parentheses_2_body()
 		;
 	EOF
 	cat <<-\EOF > stderr.exp
-		error: code.c:3: Unbalanced parens
-		warning: code.c:6: Extra )
+		error: code.c:3: Unbalanced parentheses
+		warning: code.c:6: Extra ')'
 	EOF
 
 	atf_check -s 'exit:1' -e 'file:stderr.exp' \
@@ -400,7 +400,7 @@ unbalanced_parentheses_3_body()
 		;
 	EOF
 	cat <<-\EOF > stderr.exp
-		error: code.c:4: Unbalanced parens
+		error: code.c:4: Unbalanced parentheses
 		error: code.c:4: Statement nesting error
 	EOF
 

Index: src/tests/usr.bin/indent/t_misc.sh
diff -u src/tests/usr.bin/indent/t_misc.sh:1.9 src/tests/usr.bin/indent/t_misc.sh:1.10
--- src/tests/usr.bin/indent/t_misc.sh:1.9	Thu Oct 28 21:02:05 2021
+++ src/tests/usr.bin/indent/t_misc.sh	Fri Oct 29 16:54:51 2021
@@ -1,5 +1,5 @@
 #! /bin/sh
-# $NetBSD: t_misc.sh,v 1.9 2021/10/28 21:02:05 rillig Exp $
+# $NetBSD: t_misc.sh,v 1.10 2021/10/29 16:54:51 rillig Exp $
 #
 # Copyright (c) 2021 The NetBSD Foundation, Inc.
 # All rights reserved.
@@ -316,7 +316,7 @@ line_no_counting_body()
 	EOF
 
 	cat <<-\EOF > code.err
-		warning: code.c:3: Extra )
+		warning: code.c:3: Extra ')'
 	EOF
 
 	atf_check -o 'ignore' -e 'file:code.err' \

Index: src/tests/usr.bin/indent/token_lparen.c
diff -u src/tests/usr.bin/indent/token_lparen.c:1.7 src/tests/usr.bin/indent/token_lparen.c:1.8
--- src/tests/usr.bin/indent/token_lparen.c:1.7	Mon Oct 25 20:16:16 2021
+++ src/tests/usr.bin/indent/token_lparen.c	Fri Oct 29 16:54:51 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: token_lparen.c,v 1.7 2021/10/25 20:16:16 rillig Exp $ */
+/* $NetBSD: token_lparen.c,v 1.8 2021/10/29 16:54:51 rillig Exp $ */
 /* $FreeBSD$ */
 
 /*
@@ -52,7 +52,7 @@ function(void)
 
 /* GCC statement expression */
 /* expr = ({if(expr)debug();expr;}); */
-/* $ XXX: Generates wrong 'error: Standard Input:36: Unbalanced parens'. */
+/* $ XXX: Generates 'error: Standard Input:36: Unbalanced parentheses'. */
 }
 #indent end
 

Index: src/usr.bin/indent/indent.c
diff -u src/usr.bin/indent/indent.c:1.167 src/usr.bin/indent/indent.c:1.168
--- src/usr.bin/indent/indent.c:1.167	Thu Oct 28 22:20:08 2021
+++ src/usr.bin/indent/indent.c	Fri Oct 29 16:54:51 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: indent.c,v 1.167 2021/10/28 22:20:08 rillig Exp $	*/
+/*	$NetBSD: indent.c,v 1.168 2021/10/29 16:54:51 rillig Exp $	*/
 
 /*-
  * SPDX-License-Identifier: BSD-4-Clause
@@ -43,7 +43,7 @@ static char sccsid[] = "@(#)indent.c	5.1
 
 #include 
 #if defined(__NetBSD__)
-__RCSID("$NetBSD: indent.c,v 1.167 2021/10/28 22:20:08 rillig Exp $");
+__RCSID("$NetBSD: indent.c,v 1.168 2021/10/29 16:54:51 rillig Exp $");
 #elif defined(__FreeBSD__)
 __FBSDID("$FreeBSD: head/usr.bin/indent/indent.c 340138 2018-11-04 19:24:49Z oshogbo $");
 #endif
@@ -722,7 +722,7 @@ static void
 process_lparen_or_lbracket(int decl_ind, bool tabs_to_var, bool spaced_expr)
 {
 if (++ps.p_l_follow == array_length(ps.paren_indents)) {
-	diag(0, "Reached internal limit of %zu unclosed parens",
+	diag(0, "Reached internal limit of %zu unclosed parentheses",
 	array_length(ps.paren_indents));
 	ps.p_l_follow--;
 }
@@ -776,7 +776,7 @@ process_rparen_or_rbracket(bool *spaced_
 
 if (--ps.p_l_follow < 0) {
 	ps.p_l_follow = 0;
-	diag(0, "Extra %c", *token.s);
+	diag(0, "Extra '%c'", *token.s);
 }
 
 if (code.e == code.s)	/* if the paren starts the line */
@@ -903,10 

CVS commit: src/usr.bin/indent

2021-10-29 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Fri Oct 29 17:32:22 UTC 2021

Modified Files:
src/usr.bin/indent: indent.c indent.h io.c

Log Message:
indent: rename ps.dumped_decl_indent and indent_declaration

The word 'dump' in 'ps.dumped_decl_indent' was too close to dump_line,
which led to confusion since the variable controls whether the
indentation has been added to the code buffer, which happens way before
actually dumping the current line to the output file.

The function name 'indent_declaration' was too unspecific, it did not
reveal where the indentation of the declaration actually happened.

No functional change.


To generate a diff of this commit:
cvs rdiff -u -r1.169 -r1.170 src/usr.bin/indent/indent.c
cvs rdiff -u -r1.57 -r1.58 src/usr.bin/indent/indent.h
cvs rdiff -u -r1.103 -r1.104 src/usr.bin/indent/io.c

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



CVS commit: src/usr.bin/indent

2021-10-29 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Fri Oct 29 17:32:22 UTC 2021

Modified Files:
src/usr.bin/indent: indent.c indent.h io.c

Log Message:
indent: rename ps.dumped_decl_indent and indent_declaration

The word 'dump' in 'ps.dumped_decl_indent' was too close to dump_line,
which led to confusion since the variable controls whether the
indentation has been added to the code buffer, which happens way before
actually dumping the current line to the output file.

The function name 'indent_declaration' was too unspecific, it did not
reveal where the indentation of the declaration actually happened.

No functional change.


To generate a diff of this commit:
cvs rdiff -u -r1.169 -r1.170 src/usr.bin/indent/indent.c
cvs rdiff -u -r1.57 -r1.58 src/usr.bin/indent/indent.h
cvs rdiff -u -r1.103 -r1.104 src/usr.bin/indent/io.c

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/indent/indent.c
diff -u src/usr.bin/indent/indent.c:1.169 src/usr.bin/indent/indent.c:1.170
--- src/usr.bin/indent/indent.c:1.169	Fri Oct 29 16:59:35 2021
+++ src/usr.bin/indent/indent.c	Fri Oct 29 17:32:22 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: indent.c,v 1.169 2021/10/29 16:59:35 rillig Exp $	*/
+/*	$NetBSD: indent.c,v 1.170 2021/10/29 17:32:22 rillig Exp $	*/
 
 /*-
  * SPDX-License-Identifier: BSD-4-Clause
@@ -43,7 +43,7 @@ static char sccsid[] = "@(#)indent.c	5.1
 
 #include 
 #if defined(__NetBSD__)
-__RCSID("$NetBSD: indent.c,v 1.169 2021/10/29 16:59:35 rillig Exp $");
+__RCSID("$NetBSD: indent.c,v 1.170 2021/10/29 17:32:22 rillig Exp $");
 #elif defined(__FreeBSD__)
 __FBSDID("$FreeBSD: head/usr.bin/indent/indent.c 340138 2018-11-04 19:24:49Z oshogbo $");
 #endif
@@ -604,7 +604,7 @@ main_prepare_parsing(void)
 }
 
 static void
-indent_declaration(int cur_decl_ind, bool tabs_to_var)
+code_add_decl_indent(int cur_decl_ind, bool tabs_to_var)
 {
 int ind = (int)buf_len();
 char *orig_code_e = code.e;
@@ -728,11 +728,11 @@ process_lparen_or_lbracket(int decl_ind,
 }
 
 if (token.s[0] == '(' && ps.in_decl
-	&& !ps.block_init && !ps.dumped_decl_indent &&
+	&& !ps.block_init && !ps.decl_indent_done &&
 	ps.procname[0] == '\0' && ps.paren_level == 0) {
 	/* function pointer declarations */
-	indent_declaration(decl_ind, tabs_to_var);
-	ps.dumped_decl_indent = true;
+	code_add_decl_indent(decl_ind, tabs_to_var);
+	ps.decl_indent_done = true;
 } else if (want_blank_before_lparen())
 	*code.e++ = ' ';
 ps.want_blank = false;
@@ -804,11 +804,11 @@ process_rparen_or_rbracket(bool *spaced_
 static void
 process_unary_op(int decl_ind, bool tabs_to_var)
 {
-if (!ps.dumped_decl_indent && ps.in_decl && !ps.block_init &&
+if (!ps.decl_indent_done && ps.in_decl && !ps.block_init &&
 	ps.procname[0] == '\0' && ps.paren_level == 0) {
 	/* pointer declarations */
-	indent_declaration(decl_ind - (int)buf_len(), tabs_to_var);
-	ps.dumped_decl_indent = true;
+	code_add_decl_indent(decl_ind - (int)buf_len(), tabs_to_var);
+	ps.decl_indent_done = true;
 } else if (ps.want_blank)
 	*code.e++ = ' ';
 
@@ -890,10 +890,10 @@ process_semicolon(bool *seen_case, int *
 ps.just_saw_decl--;
 
 if (ps.in_decl && code.s == code.e && !ps.block_init &&
-	!ps.dumped_decl_indent && ps.paren_level == 0) {
+	!ps.decl_indent_done && ps.paren_level == 0) {
 	/* indent stray semicolons in declarations */
-	indent_declaration(decl_ind - 1, tabs_to_var);
-	ps.dumped_decl_indent = true;
+	code_add_decl_indent(decl_ind - 1, tabs_to_var);
+	ps.decl_indent_done = true;
 }
 
 ps.in_decl = ps.decl_nest > 0;	/* if we were in a first level
@@ -1122,11 +1122,10 @@ process_ident(lexer_symbol lsym, int dec
 	}
 	ps.want_blank = false;
 
-	} else if (!ps.block_init && !ps.dumped_decl_indent &&
-	ps.paren_level == 0) {	/* if we are in a declaration, we must
-	 * indent identifier */
-	indent_declaration(decl_ind, tabs_to_var);
-	ps.dumped_decl_indent = true;
+	} else if (!ps.block_init && !ps.decl_indent_done &&
+	ps.paren_level == 0) {
+	code_add_decl_indent(decl_ind, tabs_to_var);
+	ps.decl_indent_done = true;
 	ps.want_blank = false;
 	}
 
@@ -1170,10 +1169,10 @@ process_comma(int decl_ind, bool tabs_to
 	 * does not start the line */
 
 if (ps.in_decl && ps.procname[0] == '\0' && !ps.block_init &&
-	!ps.dumped_decl_indent && ps.paren_level == 0) {
+	!ps.decl_indent_done && ps.paren_level == 0) {
 	/* indent leading commas and not the actual identifiers */
-	indent_declaration(decl_ind - 1, tabs_to_var);
-	ps.dumped_decl_indent = true;
+	code_add_decl_indent(decl_ind - 1, tabs_to_var);
+	ps.decl_indent_done = true;
 }
 
 *code.e++ = ',';

Index: src/usr.bin/indent/indent.h
diff -u src/usr.bin/indent/indent.h:1.57 src/usr.bin/indent/indent.h:1.58
--- src/usr.bin/indent/indent.h:1.57	Fri Oct 29 16:59:35 2021
+++ src/usr.bin/indent/indent.h	Fri Oct 29 17:32:22 2021
@@ -1,4 

Re: CVS commit: src/lib/libc/string

2021-10-29 Thread Joerg Sonnenberger
On Fri, Oct 29, 2021 at 10:11:57AM +, Nia Alarie wrote:
> Module Name:  src
> Committed By: nia
> Date: Fri Oct 29 10:11:57 UTC 2021
> 
> Modified Files:
>   src/lib/libc/string: wcsdup.c
> 
> Log Message:
> wcsdup(3): use reallocarr to catch integer overflow

Except that no such integer overflow can happen, since the input string
already has done the same computation.

Joerg


CVS commit: src/tests/usr.bin/indent

2021-10-29 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Fri Oct 29 16:43:05 UTC 2021

Modified Files:
src/tests/usr.bin/indent: t_errors.sh

Log Message:
tests/indent: provoke error messages for unbalanced parentheses


To generate a diff of this commit:
cvs rdiff -u -r1.8 -r1.9 src/tests/usr.bin/indent/t_errors.sh

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



CVS commit: src/tests/usr.bin/indent

2021-10-29 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Fri Oct 29 16:43:05 UTC 2021

Modified Files:
src/tests/usr.bin/indent: t_errors.sh

Log Message:
tests/indent: provoke error messages for unbalanced parentheses


To generate a diff of this commit:
cvs rdiff -u -r1.8 -r1.9 src/tests/usr.bin/indent/t_errors.sh

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

Modified files:

Index: src/tests/usr.bin/indent/t_errors.sh
diff -u src/tests/usr.bin/indent/t_errors.sh:1.8 src/tests/usr.bin/indent/t_errors.sh:1.9
--- src/tests/usr.bin/indent/t_errors.sh:1.8	Thu Oct 28 21:35:57 2021
+++ src/tests/usr.bin/indent/t_errors.sh	Fri Oct 29 16:43:05 2021
@@ -1,5 +1,5 @@
 #! /bin/sh
-# $NetBSD: t_errors.sh,v 1.8 2021/10/28 21:35:57 rillig Exp $
+# $NetBSD: t_errors.sh,v 1.9 2021/10/29 16:43:05 rillig Exp $
 #
 # Copyright (c) 2021 The NetBSD Foundation, Inc.
 # All rights reserved.
@@ -347,6 +347,48 @@ preprocessing_unrecognized_body()
 	"$indent" code.c
 }
 
+atf_test_case 'unbalanced_parentheses_1'
+unbalanced_parentheses_1_body()
+{
+	cat <<-\EOF > code.c
+		int var =
+		(
+		;
+		)
+		;
+	EOF
+	cat <<-\EOF > stderr.exp
+		error: code.c:3: Unbalanced parens
+		warning: code.c:4: Extra )
+	EOF
+
+	atf_check -s 'exit:1' -e 'file:stderr.exp' \
+	"$indent" code.c
+}
+
+atf_test_case 'unbalanced_parentheses_2'
+unbalanced_parentheses_2_body()
+{
+	# '({...})' is the GCC extension "Statement expression".
+	cat <<-\EOF > code.c
+		int var =
+		(
+		{
+		1
+		}
+		)
+		;
+	EOF
+	cat <<-\EOF > stderr.exp
+		error: code.c:3: Unbalanced parens
+		warning: code.c:6: Extra )
+	EOF
+
+	atf_check -s 'exit:1' -e 'file:stderr.exp' \
+	"$indent" code.c
+}
+
+
 atf_init_test_cases()
 {
 	atf_add_test_case 'option_unknown'
@@ -375,4 +417,6 @@ atf_init_test_cases()
 	atf_add_test_case 'unexpected_closing_brace_decl'
 	atf_add_test_case 'preprocessing_overflow'
 	atf_add_test_case 'preprocessing_unrecognized'
+	atf_add_test_case 'unbalanced_parentheses_1'
+	atf_add_test_case 'unbalanced_parentheses_2'
 }



CVS commit: src/usr.bin/indent

2021-10-29 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Fri Oct 29 16:59:35 UTC 2021

Modified Files:
src/usr.bin/indent: indent.c indent.h lexi.c

Log Message:
indent: keep p_l_follow nonnegative, use consistent comparison

No functional change.


To generate a diff of this commit:
cvs rdiff -u -r1.168 -r1.169 src/usr.bin/indent/indent.c
cvs rdiff -u -r1.56 -r1.57 src/usr.bin/indent/indent.h
cvs rdiff -u -r1.108 -r1.109 src/usr.bin/indent/lexi.c

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



CVS commit: src/usr.bin/indent

2021-10-29 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Fri Oct 29 16:59:35 UTC 2021

Modified Files:
src/usr.bin/indent: indent.c indent.h lexi.c

Log Message:
indent: keep p_l_follow nonnegative, use consistent comparison

No functional change.


To generate a diff of this commit:
cvs rdiff -u -r1.168 -r1.169 src/usr.bin/indent/indent.c
cvs rdiff -u -r1.56 -r1.57 src/usr.bin/indent/indent.h
cvs rdiff -u -r1.108 -r1.109 src/usr.bin/indent/lexi.c

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/indent/indent.c
diff -u src/usr.bin/indent/indent.c:1.168 src/usr.bin/indent/indent.c:1.169
--- src/usr.bin/indent/indent.c:1.168	Fri Oct 29 16:54:51 2021
+++ src/usr.bin/indent/indent.c	Fri Oct 29 16:59:35 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: indent.c,v 1.168 2021/10/29 16:54:51 rillig Exp $	*/
+/*	$NetBSD: indent.c,v 1.169 2021/10/29 16:59:35 rillig Exp $	*/
 
 /*-
  * SPDX-License-Identifier: BSD-4-Clause
@@ -43,7 +43,7 @@ static char sccsid[] = "@(#)indent.c	5.1
 
 #include 
 #if defined(__NetBSD__)
-__RCSID("$NetBSD: indent.c,v 1.168 2021/10/29 16:54:51 rillig Exp $");
+__RCSID("$NetBSD: indent.c,v 1.169 2021/10/29 16:59:35 rillig Exp $");
 #elif defined(__FreeBSD__)
 __FBSDID("$FreeBSD: head/usr.bin/indent/indent.c 340138 2018-11-04 19:24:49Z oshogbo $");
 #endif
@@ -774,10 +774,10 @@ process_rparen_or_rbracket(bool *spaced_
 	ps.want_blank = true;
 ps.not_cast_mask &= (1 << ps.p_l_follow) - 1;
 
-if (--ps.p_l_follow < 0) {
-	ps.p_l_follow = 0;
+if (ps.p_l_follow > 0)
+	ps.p_l_follow--;
+else
 	diag(0, "Extra '%c'", *token.s);
-}
 
 if (code.e == code.s)	/* if the paren starts the line */
 	ps.paren_level = ps.p_l_follow;	/* then indent it */
@@ -915,8 +915,7 @@ process_semicolon(bool *seen_case, int *
 }
 *code.e++ = ';';
 ps.want_blank = true;
-ps.in_stmt = ps.p_l_follow > 0;	/* we are no longer in the middle of a
-	 * stmt */
+ps.in_stmt = ps.p_l_follow > 0;
 
 if (!*spaced_expr) {	/* if not if for (;;) */
 	parse(psym_semicolon);	/* let parser know about end of stmt */
@@ -1002,7 +1001,7 @@ process_rbrace(bool *spaced_expr, int *d
 	parse(psym_semicolon);
 }
 
-if (ps.p_l_follow != 0) {	/* check for unclosed if, for, else. */
+if (ps.p_l_follow > 0) {	/* check for unclosed if, for, else. */
 	diag(1, "Unbalanced parentheses");
 	ps.p_l_follow = 0;
 	*spaced_expr = false;

Index: src/usr.bin/indent/indent.h
diff -u src/usr.bin/indent/indent.h:1.56 src/usr.bin/indent/indent.h:1.57
--- src/usr.bin/indent/indent.h:1.56	Fri Oct 29 16:54:51 2021
+++ src/usr.bin/indent/indent.h	Fri Oct 29 16:59:35 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: indent.h,v 1.56 2021/10/29 16:54:51 rillig Exp $	*/
+/*	$NetBSD: indent.h,v 1.57 2021/10/29 16:59:35 rillig Exp $	*/
 
 /*-
  * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
@@ -319,7 +319,7 @@ extern struct parser_state {
 bool next_unary;		/* whether the following operator should be
  * unary */
 int p_l_follow;		/* used to remember how to indent the
- * following statement */
+ * remaining lines of the statement */
 int paren_level;		/* parenthesization level. used to indent
  * within statements */
 short paren_indents[20];	/* indentation of the operand/argument of each

Index: src/usr.bin/indent/lexi.c
diff -u src/usr.bin/indent/lexi.c:1.108 src/usr.bin/indent/lexi.c:1.109
--- src/usr.bin/indent/lexi.c:1.108	Fri Oct 29 16:54:51 2021
+++ src/usr.bin/indent/lexi.c	Fri Oct 29 16:59:35 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: lexi.c,v 1.108 2021/10/29 16:54:51 rillig Exp $	*/
+/*	$NetBSD: lexi.c,v 1.109 2021/10/29 16:59:35 rillig Exp $	*/
 
 /*-
  * SPDX-License-Identifier: BSD-4-Clause
@@ -43,7 +43,7 @@ static char sccsid[] = "@(#)lexi.c	8.1 (
 
 #include 
 #if defined(__NetBSD__)
-__RCSID("$NetBSD: lexi.c,v 1.108 2021/10/29 16:54:51 rillig Exp $");
+__RCSID("$NetBSD: lexi.c,v 1.109 2021/10/29 16:59:35 rillig Exp $");
 #elif defined(__FreeBSD__)
 __FBSDID("$FreeBSD: head/usr.bin/indent/lexi.c 337862 2018-08-15 18:19:45Z pstef $");
 #endif
@@ -389,7 +389,7 @@ lex_char_or_string(void)
 static bool
 probably_typename(void)
 {
-if (ps.p_l_follow != 0)
+if (ps.p_l_follow > 0)
 	return false;
 if (ps.block_init || ps.in_stmt)
 	return false;
@@ -487,7 +487,7 @@ lexi_alnum(void)
 	case kw_struct_or_union_or_enum:
 	case kw_type:
 found_typename:
-	if (ps.p_l_follow != 0) {
+	if (ps.p_l_follow > 0) {
 		/* inside parentheses: cast, param list, offsetof or sizeof */
 		ps.cast_mask |= (1 << ps.p_l_follow) & ~ps.not_cast_mask;
 	}
@@ -496,7 +496,7 @@ lexi_alnum(void)
 		break;
 	if (kw != NULL && kw->kind == kw_struct_or_union_or_enum)
 		return lsym_tag;
-	if (ps.p_l_follow != 0)
+	if (ps.p_l_follow > 0)
 		break;
 	return lsym_type;
 



CVS commit: src/usr.bin/indent

2021-10-29 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Fri Oct 29 17:41:56 UTC 2021

Modified Files:
src/usr.bin/indent: indent.h

Log Message:
indent: group members of parser_state by topic

No functional change.


To generate a diff of this commit:
cvs rdiff -u -r1.58 -r1.59 src/usr.bin/indent/indent.h

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/indent/indent.h
diff -u src/usr.bin/indent/indent.h:1.58 src/usr.bin/indent/indent.h:1.59
--- src/usr.bin/indent/indent.h:1.58	Fri Oct 29 17:32:22 2021
+++ src/usr.bin/indent/indent.h	Fri Oct 29 17:41:56 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: indent.h,v 1.58 2021/10/29 17:32:22 rillig Exp $	*/
+/*	$NetBSD: indent.h,v 1.59 2021/10/29 17:41:56 rillig Exp $	*/
 
 /*-
  * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
@@ -271,14 +271,39 @@ extern bool inhibit_formatting;	/* true 
 
 #define	STACKSIZE 256
 
-/* TODO: group the members by purpose, don't sort them alphabetically */
 extern struct parser_state {
+/* TODO: rename to prev_token */
 lexer_symbol last_token;
+/* TODO: rename to prev_newline */
+bool last_nl;		/* whether the last thing scanned was a
+ * newline */
+/* TODO: rename to prev_col_1 */
+bool col_1;			/* whether the last token started in column 1 */
+enum keyword_kind prev_keyword;
+enum keyword_kind curr_keyword;
+bool next_unary;		/* whether the following operator should be
+ * unary */
 
-int tos;			/* pointer to top of stack */
-parser_symbol s_sym[STACKSIZE];
-int s_ind_level[STACKSIZE];
-float s_case_ind_level[STACKSIZE];
+char procname[100];		/* The name of the current procedure */
+
+
+bool want_blank;		/* whether the following token should be
+ * prefixed by a blank. (Said prefixing is
+ * ignored in some cases.) */
+
+int paren_level;		/* parenthesization level. used to indent
+ * within statements */
+/* TODO: rename to next_line_paren_level */
+int p_l_follow;		/* how to indent the remaining lines of the
+ * statement */
+short paren_indents[20];	/* indentation of the operand/argument of each
+ * level of parentheses or brackets, relative
+ * to the enclosing statement */
+int cast_mask;		/* indicates which close parentheses
+ * potentially close off casts */
+int not_cast_mask;		/* indicates which close parentheses
+ * definitely close off something else than
+ * casts */
 
 int comment_delta;		/* used to set up indentation for all lines of
  * a boxed comment after the first one */
@@ -286,60 +311,47 @@ extern struct parser_state {
  * before the start of a box comment so that
  * forthcoming lines of the comment are
  * indented properly */
-int cast_mask;		/* indicates which close parentheses
- * potentially close off casts */
-int not_cast_mask;		/* indicates which close parentheses
- * definitely close off something else than
- * casts */
+int com_ind;		/* indentation of the current comment */
+
 bool block_init;		/* whether inside a block initialization */
 int block_init_level;	/* The level of brace nesting in an
  * initialization */
-bool last_nl;		/* whether the last thing scanned was a
- * newline */
 bool init_or_struct;	/* whether there has been a declarator (e.g.
  * int or char) and no left parenthesis since
  * the last semicolon. When true, a '{' is
  * starting a structure definition or an
  * initialization list */
-bool col_1;			/* whether the last token started in column 1 */
-int com_ind;		/* indentation of the current comment */
+
+int ind_level;		/* the current indentation level */
+int ind_level_follow;	/* the level to which ind_level should be set
+ * after the current line is printed */
+
 int decl_nest;		/* current nesting level for structure or init */
 bool decl_on_line;		/* whether this line of code has part of a
  * declaration on it */
-int ind_level_follow;	/* the level to which ind_level should be set
- * after the current line is printed */
 bool in_decl;		/* whether we are in a declaration stmt. The
  * processing of braces is then slightly
  * different */
+int just_saw_decl;
+bool in_parameter_declaration;
+bool decl_indent_done;	/* whether the indentation for a declaration
+ * has been added to the code buffer. */
+
 bool in_stmt;
-int ind_level;		/* the current indentation level */
 bool ind_stmt;		/* whether the next line should have an extra
  * indentation level because we are in the
- * middle of a stmt */
-bool next_unary;		/* whether the following operator should be
- * unary */
-int p_l_follow;		/* used to remember how to indent the
- * remaining lines of the statement */
-int paren_level;		/* parenthesization level. used to indent
- * within statements */
-

CVS commit: src/usr.bin/indent

2021-10-29 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Fri Oct 29 17:41:56 UTC 2021

Modified Files:
src/usr.bin/indent: indent.h

Log Message:
indent: group members of parser_state by topic

No functional change.


To generate a diff of this commit:
cvs rdiff -u -r1.58 -r1.59 src/usr.bin/indent/indent.h

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



CVS commit: src/sys/arch/m68k/include

2021-10-29 Thread Jason R Thorpe
Module Name:src
Committed By:   thorpej
Date:   Fri Oct 29 17:29:45 UTC 2021

Modified Files:
src/sys/arch/m68k/include: signal.h

Log Message:
Define __HAVE_STRUCT_SIGCONTEXT regardless of its current visibility.


To generate a diff of this commit:
cvs rdiff -u -r1.27 -r1.28 src/sys/arch/m68k/include/signal.h

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



CVS commit: src/sys/arch/m68k/include

2021-10-29 Thread Jason R Thorpe
Module Name:src
Committed By:   thorpej
Date:   Fri Oct 29 17:29:45 UTC 2021

Modified Files:
src/sys/arch/m68k/include: signal.h

Log Message:
Define __HAVE_STRUCT_SIGCONTEXT regardless of its current visibility.


To generate a diff of this commit:
cvs rdiff -u -r1.27 -r1.28 src/sys/arch/m68k/include/signal.h

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

Modified files:

Index: src/sys/arch/m68k/include/signal.h
diff -u src/sys/arch/m68k/include/signal.h:1.27 src/sys/arch/m68k/include/signal.h:1.28
--- src/sys/arch/m68k/include/signal.h:1.27	Wed Oct 27 01:10:06 2021
+++ src/sys/arch/m68k/include/signal.h	Fri Oct 29 17:29:45 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: signal.h,v 1.27 2021/10/27 01:10:06 thorpej Exp $	*/
+/*	$NetBSD: signal.h,v 1.28 2021/10/29 17:29:45 thorpej Exp $	*/
 
 /*
  * Copyright (c) 1982, 1986, 1989, 1991 Regents of the University of California.
@@ -36,6 +36,8 @@
 
 #include 
 
+#define	__HAVE_STRUCT_SIGCONTEXT
+
 typedef int sig_atomic_t;
 
 #if defined(_NETBSD_SOURCE)
@@ -65,7 +67,6 @@ struct sigcontext13 {
 #endif /* _KERNEL */
 
 #if defined(_LIBC) || defined(_KERNEL)
-#define	__HAVE_STRUCT_SIGCONTEXT
 struct sigcontext {
 	int	sc_onstack;		/* sigstack state to restore */
 	int	__sc_mask13;		/* signal mask to restore (old style) */
@@ -96,7 +97,7 @@ struct sigstate {
 
 u_int fpsr2siginfocode(u_int fpsr);
 
-#endif
+#endif /* _KERNEL */
 
 #if defined(__M68K_SIGNAL_PRIVATE)
 



CVS commit: src

2021-10-29 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Fri Oct 29 17:50:38 UTC 2021

Modified Files:
src/tests/usr.bin/indent: token_comment.c token_lparen.c
src/usr.bin/indent: indent.c indent.h lexi.c pr_comment.c

Log Message:
indent: use prev/curr/next to refer to the current token

The word 'last' just didn't match with 'next'.

No functional change.


To generate a diff of this commit:
cvs rdiff -u -r1.8 -r1.9 src/tests/usr.bin/indent/token_comment.c \
src/tests/usr.bin/indent/token_lparen.c
cvs rdiff -u -r1.170 -r1.171 src/usr.bin/indent/indent.c
cvs rdiff -u -r1.59 -r1.60 src/usr.bin/indent/indent.h
cvs rdiff -u -r1.109 -r1.110 src/usr.bin/indent/lexi.c
cvs rdiff -u -r1.87 -r1.88 src/usr.bin/indent/pr_comment.c

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



CVS commit: src

2021-10-29 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Fri Oct 29 17:50:38 UTC 2021

Modified Files:
src/tests/usr.bin/indent: token_comment.c token_lparen.c
src/usr.bin/indent: indent.c indent.h lexi.c pr_comment.c

Log Message:
indent: use prev/curr/next to refer to the current token

The word 'last' just didn't match with 'next'.

No functional change.


To generate a diff of this commit:
cvs rdiff -u -r1.8 -r1.9 src/tests/usr.bin/indent/token_comment.c \
src/tests/usr.bin/indent/token_lparen.c
cvs rdiff -u -r1.170 -r1.171 src/usr.bin/indent/indent.c
cvs rdiff -u -r1.59 -r1.60 src/usr.bin/indent/indent.h
cvs rdiff -u -r1.109 -r1.110 src/usr.bin/indent/lexi.c
cvs rdiff -u -r1.87 -r1.88 src/usr.bin/indent/pr_comment.c

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

Modified files:

Index: src/tests/usr.bin/indent/token_comment.c
diff -u src/tests/usr.bin/indent/token_comment.c:1.8 src/tests/usr.bin/indent/token_comment.c:1.9
--- src/tests/usr.bin/indent/token_comment.c:1.8	Tue Oct 26 21:37:27 2021
+++ src/tests/usr.bin/indent/token_comment.c	Fri Oct 29 17:50:37 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: token_comment.c,v 1.8 2021/10/26 21:37:27 rillig Exp $ */
+/* $NetBSD: token_comment.c,v 1.9 2021/10/29 17:50:37 rillig Exp $ */
 /* $FreeBSD$ */
 
 /*
@@ -41,7 +41,7 @@
  * - with varying opt.comment_column (-c0, -c1, -c33, -c80)
  * - with varying opt.decl_comment_column (-cd0, -cd1, -cd20, -cd33, -cd80)
  * - with/without ps.decl_on_line
- * - with/without ps.last_nl
+ * - with/without ps.prev_newline
  *
  * - very long comments that overflow the buffer 'com'
  * - comments that come from save_com
Index: src/tests/usr.bin/indent/token_lparen.c
diff -u src/tests/usr.bin/indent/token_lparen.c:1.8 src/tests/usr.bin/indent/token_lparen.c:1.9
--- src/tests/usr.bin/indent/token_lparen.c:1.8	Fri Oct 29 16:54:51 2021
+++ src/tests/usr.bin/indent/token_lparen.c	Fri Oct 29 17:50:37 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: token_lparen.c,v 1.8 2021/10/29 16:54:51 rillig Exp $ */
+/* $NetBSD: token_lparen.c,v 1.9 2021/10/29 17:50:37 rillig Exp $ */
 /* $FreeBSD$ */
 
 /*
@@ -100,7 +100,7 @@ int array[] = {
 #indent input
 void cover_want_blank_before_lparen(void)
 {
-	/* ps.last_token can never be 'newline'. */
+	/* ps.prev_token can never be 'newline'. */
 	int newline =
 	(3);
 
@@ -146,7 +146,7 @@ void cover_want_blank_before_lparen(void
 void
 cover_want_blank_before_lparen(void)
 {
-	/* ps.last_token can never be 'newline'. */
+	/* ps.prev_token can never be 'newline'. */
 	int newline =
 	(3);
 

Index: src/usr.bin/indent/indent.c
diff -u src/usr.bin/indent/indent.c:1.170 src/usr.bin/indent/indent.c:1.171
--- src/usr.bin/indent/indent.c:1.170	Fri Oct 29 17:32:22 2021
+++ src/usr.bin/indent/indent.c	Fri Oct 29 17:50:37 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: indent.c,v 1.170 2021/10/29 17:32:22 rillig Exp $	*/
+/*	$NetBSD: indent.c,v 1.171 2021/10/29 17:50:37 rillig Exp $	*/
 
 /*-
  * SPDX-License-Identifier: BSD-4-Clause
@@ -43,7 +43,7 @@ static char sccsid[] = "@(#)indent.c	5.1
 
 #include 
 #if defined(__NetBSD__)
-__RCSID("$NetBSD: indent.c,v 1.170 2021/10/29 17:32:22 rillig Exp $");
+__RCSID("$NetBSD: indent.c,v 1.171 2021/10/29 17:50:37 rillig Exp $");
 #elif defined(__FreeBSD__)
 __FBSDID("$FreeBSD: head/usr.bin/indent/indent.c 340138 2018-11-04 19:24:49Z oshogbo $");
 #endif
@@ -450,8 +450,8 @@ main_init_globals(void)
 found_err = false;
 
 ps.s_sym[0] = psym_stmt;
-ps.last_nl = true;
-ps.last_token = lsym_semicolon;
+ps.prev_newline = true;
+ps.prev_token = lsym_semicolon;
 buf_init();
 buf_init();
 buf_init();
@@ -690,7 +690,7 @@ process_form_feed(void)
 static void
 process_newline(void)
 {
-if (ps.last_token == lsym_comma && ps.p_l_follow == 0 && !ps.block_init &&
+if (ps.prev_token == lsym_comma && ps.p_l_follow == 0 && !ps.block_init &&
 	!opt.break_after_comma && break_comma &&
 	com.s == com.e)
 	goto stay_in_line;
@@ -707,9 +707,9 @@ want_blank_before_lparen(void)
 {
 if (!ps.want_blank)
 	return false;
-if (ps.last_token == lsym_rparen_or_rbracket)
+if (ps.prev_token == lsym_rparen_or_rbracket)
 	return false;
-if (ps.last_token != lsym_ident && ps.last_token != lsym_funcname)
+if (ps.prev_token != lsym_ident && ps.prev_token != lsym_funcname)
 	return true;
 if (opt.proc_calls_space)
 	return true;
@@ -881,7 +881,7 @@ process_semicolon(bool *seen_case, int *
 	ps.init_or_struct = false;
 *seen_case = false;		/* these will only need resetting in an error */
 *quest_level = 0;
-if (ps.last_token == lsym_rparen_or_rbracket)
+if (ps.prev_token == lsym_rparen_or_rbracket)
 	ps.in_parameter_declaration = false;
 ps.cast_mask = 0;
 ps.not_cast_mask = 0;
@@ -1079,7 +1079,7 @@ process_type(int *decl_ind, bool *tabs_t
 {
 parse(psym_decl);		/* let the parser worry about indentation */
 
-if (ps.last_token == lsym_rparen_or_rbracket && 

CVS commit: src/usr.bin/indent

2021-10-29 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Fri Oct 29 19:12:49 UTC 2021

Modified Files:
src/usr.bin/indent: indent.c io.c pr_comment.c

Log Message:
indent: fix undefined behavior in buffer handling

Adding an arbitrary integer to a pointer may result in an out of bounds
pointer, so replace the addition with a pointer subtraction.

In the buffer handling functions, handle 'buf' and 'l' before 's' and
'e', since they are pairs.

In inbuf_read_line, use 's' instead of 'buf' to make the code easier to
understand for human readers.

No functional change.


To generate a diff of this commit:
cvs rdiff -u -r1.172 -r1.173 src/usr.bin/indent/indent.c
cvs rdiff -u -r1.105 -r1.106 src/usr.bin/indent/io.c
cvs rdiff -u -r1.88 -r1.89 src/usr.bin/indent/pr_comment.c

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



CVS commit: src/usr.bin/indent

2021-10-29 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Fri Oct 29 19:12:49 UTC 2021

Modified Files:
src/usr.bin/indent: indent.c io.c pr_comment.c

Log Message:
indent: fix undefined behavior in buffer handling

Adding an arbitrary integer to a pointer may result in an out of bounds
pointer, so replace the addition with a pointer subtraction.

In the buffer handling functions, handle 'buf' and 'l' before 's' and
'e', since they are pairs.

In inbuf_read_line, use 's' instead of 'buf' to make the code easier to
understand for human readers.

No functional change.


To generate a diff of this commit:
cvs rdiff -u -r1.172 -r1.173 src/usr.bin/indent/indent.c
cvs rdiff -u -r1.105 -r1.106 src/usr.bin/indent/io.c
cvs rdiff -u -r1.88 -r1.89 src/usr.bin/indent/pr_comment.c

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/indent/indent.c
diff -u src/usr.bin/indent/indent.c:1.172 src/usr.bin/indent/indent.c:1.173
--- src/usr.bin/indent/indent.c:1.172	Fri Oct 29 18:50:52 2021
+++ src/usr.bin/indent/indent.c	Fri Oct 29 19:12:48 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: indent.c,v 1.172 2021/10/29 18:50:52 rillig Exp $	*/
+/*	$NetBSD: indent.c,v 1.173 2021/10/29 19:12:48 rillig Exp $	*/
 
 /*-
  * SPDX-License-Identifier: BSD-4-Clause
@@ -43,7 +43,7 @@ static char sccsid[] = "@(#)indent.c	5.1
 
 #include 
 #if defined(__NetBSD__)
-__RCSID("$NetBSD: indent.c,v 1.172 2021/10/29 18:50:52 rillig Exp $");
+__RCSID("$NetBSD: indent.c,v 1.173 2021/10/29 19:12:48 rillig Exp $");
 #elif defined(__FreeBSD__)
 __FBSDID("$FreeBSD: head/usr.bin/indent/indent.c 340138 2018-11-04 19:24:49Z oshogbo $");
 #endif
@@ -390,11 +390,11 @@ buf_init(struct buffer *buf)
 {
 size_t size = 200;
 buf->buf = xmalloc(size);
-buf->buf[0] = ' ';		/* allow accessing buf->e[-1] */
-buf->buf[1] = '\0';
-buf->s = buf->buf + 1;
+buf->l = buf->buf + size - 5 /* safety margin */;
+buf->s = buf->buf + 1;	/* allow accessing buf->e[-1] */
 buf->e = buf->s;
-buf->l = buf->buf + size - 5;	/* safety margin */
+buf->buf[0] = ' ';
+buf->buf[1] = '\0';
 }
 
 static size_t
@@ -404,20 +404,21 @@ buf_len(const struct buffer *buf)
 }
 
 void
-buf_expand(struct buffer *buf, size_t desired_size)
+buf_expand(struct buffer *buf, size_t add_size)
 {
-size_t nsize = (size_t)(buf->l - buf->s) + 400 + desired_size;
+size_t new_size = (size_t)(buf->l - buf->s) + 400 + add_size;
 size_t len = buf_len(buf);
-buf->buf = xrealloc(buf->buf, nsize);
-buf->e = buf->buf + len + 1;
-buf->l = buf->buf + nsize - 5;
+buf->buf = xrealloc(buf->buf, new_size);
+buf->l = buf->buf + new_size - 5;
 buf->s = buf->buf + 1;
+buf->e = buf->s + len;
+/* At this point, the buffer may not be null-terminated anymore. */
 }
 
 static void
 buf_reserve(struct buffer *buf, size_t n)
 {
-if (buf->e + n >= buf->l)
+if (n >= (size_t)(buf->l - buf->e))
 	buf_expand(buf, n);
 }
 
@@ -467,7 +468,9 @@ main_init_globals(void)
 
 inp.buf = xmalloc(10);
 inp.l = inp.buf + 8;
-inp.s = inp.e = inp.buf;
+inp.s = inp.buf;
+inp.e = inp.buf;
+
 line_no = 1;
 had_eof = ps.in_decl = ps.decl_on_line = break_comma = false;
 

Index: src/usr.bin/indent/io.c
diff -u src/usr.bin/indent/io.c:1.105 src/usr.bin/indent/io.c:1.106
--- src/usr.bin/indent/io.c:1.105	Fri Oct 29 18:18:03 2021
+++ src/usr.bin/indent/io.c	Fri Oct 29 19:12:48 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: io.c,v 1.105 2021/10/29 18:18:03 rillig Exp $	*/
+/*	$NetBSD: io.c,v 1.106 2021/10/29 19:12:48 rillig Exp $	*/
 
 /*-
  * SPDX-License-Identifier: BSD-4-Clause
@@ -43,7 +43,7 @@ static char sccsid[] = "@(#)io.c	8.1 (Be
 
 #include 
 #if defined(__NetBSD__)
-__RCSID("$NetBSD: io.c,v 1.105 2021/10/29 18:18:03 rillig Exp $");
+__RCSID("$NetBSD: io.c,v 1.106 2021/10/29 19:12:48 rillig Exp $");
 #elif defined(__FreeBSD__)
 __FBSDID("$FreeBSD: head/usr.bin/indent/io.c 334927 2018-06-10 16:44:18Z pstef $");
 #endif
@@ -448,8 +448,8 @@ inbuf_read_line(void)
 inp.s = inp.buf;
 inp.e = p;
 
-if (p - inp.buf >= 3 && p[-3] == '*' && p[-2] == '/') {
-	if (strncmp(inp.buf, "/**INDENT**", 11) == 0)
+if (p - inp.s >= 3 && p[-3] == '*' && p[-2] == '/') {
+	if (strncmp(inp.s, "/**INDENT**", 11) == 0)
 	inbuf_read_line();	/* flush indent error message */
 	else
 	parse_indent_comment();

Index: src/usr.bin/indent/pr_comment.c
diff -u src/usr.bin/indent/pr_comment.c:1.88 src/usr.bin/indent/pr_comment.c:1.89
--- src/usr.bin/indent/pr_comment.c:1.88	Fri Oct 29 17:50:37 2021
+++ src/usr.bin/indent/pr_comment.c	Fri Oct 29 19:12:48 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: pr_comment.c,v 1.88 2021/10/29 17:50:37 rillig Exp $	*/
+/*	$NetBSD: pr_comment.c,v 1.89 2021/10/29 19:12:48 rillig Exp $	*/
 
 /*-
  * SPDX-License-Identifier: BSD-4-Clause
@@ -43,7 +43,7 @@ static char sccsid[] = "@(#)pr_comment.c
 
 #include 
 #if defined(__NetBSD__)

CVS commit: src/distrib/sets/lists/comp

2021-10-29 Thread Michael Lorenz
Module Name:src
Committed By:   macallan
Date:   Fri Oct 29 19:12:30 UTC 2021

Modified Files:
src/distrib/sets/lists/comp: mi

Log Message:
add mgxreg.h


To generate a diff of this commit:
cvs rdiff -u -r1.2396 -r1.2397 src/distrib/sets/lists/comp/mi

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



CVS commit: src/distrib/sets/lists/comp

2021-10-29 Thread Michael Lorenz
Module Name:src
Committed By:   macallan
Date:   Fri Oct 29 19:12:30 UTC 2021

Modified Files:
src/distrib/sets/lists/comp: mi

Log Message:
add mgxreg.h


To generate a diff of this commit:
cvs rdiff -u -r1.2396 -r1.2397 src/distrib/sets/lists/comp/mi

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

Modified files:

Index: src/distrib/sets/lists/comp/mi
diff -u src/distrib/sets/lists/comp/mi:1.2396 src/distrib/sets/lists/comp/mi:1.2397
--- src/distrib/sets/lists/comp/mi:1.2396	Sun Oct 10 13:03:09 2021
+++ src/distrib/sets/lists/comp/mi	Fri Oct 29 19:12:29 2021
@@ -1,4 +1,4 @@
-#	$NetBSD: mi,v 1.2396 2021/10/10 13:03:09 jmcneill Exp $
+#	$NetBSD: mi,v 1.2397 2021/10/29 19:12:29 macallan Exp $
 #
 # Note: don't delete entries from here - mark them as "obsolete" instead.
 ./etc/mtree/set.compcomp-sys-root
@@ -802,6 +802,7 @@
 ./usr/include/dev/rcons/rcons.h			comp-obsolete		obsolete
 ./usr/include/dev/rcons/rcons_subr.h		comp-obsolete		obsolete
 ./usr/include/dev/sbus/mbppio.h			comp-c-include
+./usr/include/dev/sbus/mgxreg.h comp-c-include
 ./usr/include/dev/scsipi/atapi_all.h		comp-obsolete		obsolete
 ./usr/include/dev/scsipi/atapi_cd.h		comp-obsolete		obsolete
 ./usr/include/dev/scsipi/atapi_disk.h		comp-obsolete		obsolete



CVS commit: src/lib/libc

2021-10-29 Thread Robert Elz
Module Name:src
Committed By:   kre
Date:   Fri Oct 29 19:27:07 UTC 2021

Modified Files:
src/lib/libc/gen: popen.c
src/lib/libc/stdlib: system.c

Log Message:
Add "--" 'options end' parameter to the sh -c call that runs the
command, so that the command cannot appear to be more options
(which always then fails, as there would be no arg for "-c" to
treat as the command string in that case).

For the full (LONG) explanation, see:
   http://mail-index.netbsd.org/current-users/2021/10/29/msg041629.html


To generate a diff of this commit:
cvs rdiff -u -r1.36 -r1.37 src/lib/libc/gen/popen.c
cvs rdiff -u -r1.25 -r1.26 src/lib/libc/stdlib/system.c

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



CVS commit: src/lib/libc

2021-10-29 Thread Robert Elz
Module Name:src
Committed By:   kre
Date:   Fri Oct 29 19:27:07 UTC 2021

Modified Files:
src/lib/libc/gen: popen.c
src/lib/libc/stdlib: system.c

Log Message:
Add "--" 'options end' parameter to the sh -c call that runs the
command, so that the command cannot appear to be more options
(which always then fails, as there would be no arg for "-c" to
treat as the command string in that case).

For the full (LONG) explanation, see:
   http://mail-index.netbsd.org/current-users/2021/10/29/msg041629.html


To generate a diff of this commit:
cvs rdiff -u -r1.36 -r1.37 src/lib/libc/gen/popen.c
cvs rdiff -u -r1.25 -r1.26 src/lib/libc/stdlib/system.c

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

Modified files:

Index: src/lib/libc/gen/popen.c
diff -u src/lib/libc/gen/popen.c:1.36 src/lib/libc/gen/popen.c:1.37
--- src/lib/libc/gen/popen.c:1.36	Thu Jan 24 18:01:38 2019
+++ src/lib/libc/gen/popen.c	Fri Oct 29 19:27:06 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: popen.c,v 1.36 2019/01/24 18:01:38 christos Exp $	*/
+/*	$NetBSD: popen.c,v 1.37 2021/10/29 19:27:06 kre Exp $	*/
 
 /*
  * Copyright (c) 1988, 1993
@@ -37,7 +37,7 @@
 #if 0
 static char sccsid[] = "@(#)popen.c	8.3 (Berkeley) 5/3/95";
 #else
-__RCSID("$NetBSD: popen.c,v 1.36 2019/01/24 18:01:38 christos Exp $");
+__RCSID("$NetBSD: popen.c,v 1.37 2021/10/29 19:27:06 kre Exp $");
 #endif
 #endif /* LIBC_SCCS and not lint */
 
@@ -209,7 +209,7 @@ popen(const char *cmd, const char *type)
 		/* NOTREACHED */
 	case 0:/* Child. */
 		pdes_child(pdes, type);
-		execl(_PATH_BSHELL, "sh", "-c", cmd, NULL);
+		execl(_PATH_BSHELL, "sh", "-c", "--", cmd, NULL);
 		_exit(127);
 		/* NOTREACHED */
 	}

Index: src/lib/libc/stdlib/system.c
diff -u src/lib/libc/stdlib/system.c:1.25 src/lib/libc/stdlib/system.c:1.26
--- src/lib/libc/stdlib/system.c:1.25	Tue Jan 20 18:31:25 2015
+++ src/lib/libc/stdlib/system.c	Fri Oct 29 19:27:06 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: system.c,v 1.25 2015/01/20 18:31:25 christos Exp $	*/
+/*	$NetBSD: system.c,v 1.26 2021/10/29 19:27:06 kre Exp $	*/
 
 /*
  * Copyright (c) 1988, 1993
@@ -34,7 +34,7 @@
 #if 0
 static char sccsid[] = "@(#)system.c	8.1 (Berkeley) 6/4/93";
 #else
-__RCSID("$NetBSD: system.c,v 1.25 2015/01/20 18:31:25 christos Exp $");
+__RCSID("$NetBSD: system.c,v 1.26 2021/10/29 19:27:06 kre Exp $");
 #endif
 #endif /* LIBC_SCCS and not lint */
 
@@ -56,8 +56,8 @@ system(const char *command)
 	struct sigaction intsa, quitsa, sa;
 	sigset_t nmask, omask;
 	int pstat;
-	const char *argp[] = {"sh", "-c", NULL, NULL};
-	argp[2] = command;
+	const char *argp[] = {"sh", "-c", "--", NULL, NULL};
+	argp[3] = command;
 
 	/*
 	 * ISO/IEC 9899:1999 in 7.20.4.6 describes this special case.



CVS commit: src

2021-10-29 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Fri Oct 29 19:22:55 UTC 2021

Modified Files:
src/tests/usr.bin/indent: t_misc.sh
src/usr.bin/indent: indent.c

Log Message:
indent: clean up main_init_globals

No functional change.


To generate a diff of this commit:
cvs rdiff -u -r1.10 -r1.11 src/tests/usr.bin/indent/t_misc.sh
cvs rdiff -u -r1.173 -r1.174 src/usr.bin/indent/indent.c

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

Modified files:

Index: src/tests/usr.bin/indent/t_misc.sh
diff -u src/tests/usr.bin/indent/t_misc.sh:1.10 src/tests/usr.bin/indent/t_misc.sh:1.11
--- src/tests/usr.bin/indent/t_misc.sh:1.10	Fri Oct 29 16:54:51 2021
+++ src/tests/usr.bin/indent/t_misc.sh	Fri Oct 29 19:22:55 2021
@@ -1,5 +1,5 @@
 #! /bin/sh
-# $NetBSD: t_misc.sh,v 1.10 2021/10/29 16:54:51 rillig Exp $
+# $NetBSD: t_misc.sh,v 1.11 2021/10/29 19:22:55 rillig Exp $
 #
 # Copyright (c) 2021 The NetBSD Foundation, Inc.
 # All rights reserved.
@@ -323,6 +323,18 @@ line_no_counting_body()
 	"$indent" code.c -st
 }
 
+atf_test_case 'default_backup_extension'
+default_backup_extension_body()
+{
+	echo 'int var;' > code.c
+	echo 'int var;' > code.c.orig
+
+	atf_check \
+	"$indent" code.c
+	atf_check -o 'file:code.c.orig' \
+	cat code.c.BAK
+}
+
 atf_init_test_cases()
 {
 	atf_add_test_case 'in_place'
@@ -333,4 +345,5 @@ atf_init_test_cases()
 	atf_add_test_case 'opt_npro'
 	atf_add_test_case 'opt_U'
 	atf_add_test_case 'line_no_counting'
+	atf_add_test_case 'default_backup_extension'
 }

Index: src/usr.bin/indent/indent.c
diff -u src/usr.bin/indent/indent.c:1.173 src/usr.bin/indent/indent.c:1.174
--- src/usr.bin/indent/indent.c:1.173	Fri Oct 29 19:12:48 2021
+++ src/usr.bin/indent/indent.c	Fri Oct 29 19:22:55 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: indent.c,v 1.173 2021/10/29 19:12:48 rillig Exp $	*/
+/*	$NetBSD: indent.c,v 1.174 2021/10/29 19:22:55 rillig Exp $	*/
 
 /*-
  * SPDX-License-Identifier: BSD-4-Clause
@@ -43,7 +43,7 @@ static char sccsid[] = "@(#)indent.c	5.1
 
 #include 
 #if defined(__NetBSD__)
-__RCSID("$NetBSD: indent.c,v 1.173 2021/10/29 19:12:48 rillig Exp $");
+__RCSID("$NetBSD: indent.c,v 1.174 2021/10/29 19:22:55 rillig Exp $");
 #elif defined(__FreeBSD__)
 __FBSDID("$FreeBSD: head/usr.bin/indent/indent.c 340138 2018-11-04 19:24:49Z oshogbo $");
 #endif
@@ -85,7 +85,11 @@ struct options opt = {
 .use_tabs = true,
 };
 
-struct parser_state ps;
+struct parser_state ps = {
+.s_sym[0] = psym_stmt,
+.prev_token = lsym_semicolon,
+.prev_newline = true,
+};
 
 struct buffer lab;
 struct buffer code;
@@ -108,7 +112,7 @@ bool blank_line_after;
 bool break_comma;
 float case_ind;
 bool had_eof;
-int line_no;
+int line_no = 1;
 bool inhibit_formatting;
 
 static int ifdef_level;
@@ -454,35 +458,16 @@ buf_reset(struct buffer *buf)
 static void
 main_init_globals(void)
 {
-found_err = false;
-
-ps.s_sym[0] = psym_stmt;
-ps.prev_newline = true;
-ps.prev_token = lsym_semicolon;
-buf_init();
-buf_init();
-buf_init();
-buf_init();
-
-opt.else_if = true;		/* XXX: redundant? */
-
 inp.buf = xmalloc(10);
 inp.l = inp.buf + 8;
 inp.s = inp.buf;
 inp.e = inp.buf;
 
-line_no = 1;
-had_eof = ps.in_decl = ps.decl_on_line = break_comma = false;
-
-ps.init_or_struct = false;
-ps.want_blank = ps.in_stmt = ps.ind_stmt = false;
-ps.is_case_label = false;
-
-sc_end = NULL;
-saved_inp_s = NULL;
-saved_inp_e = NULL;
+buf_init();
 
-output = NULL;
+buf_init();
+buf_init();
+buf_init();
 
 const char *suffix = getenv("SIMPLE_BACKUP_SUFFIX");
 if (suffix != NULL)



CVS commit: src

2021-10-29 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Fri Oct 29 19:22:55 UTC 2021

Modified Files:
src/tests/usr.bin/indent: t_misc.sh
src/usr.bin/indent: indent.c

Log Message:
indent: clean up main_init_globals

No functional change.


To generate a diff of this commit:
cvs rdiff -u -r1.10 -r1.11 src/tests/usr.bin/indent/t_misc.sh
cvs rdiff -u -r1.173 -r1.174 src/usr.bin/indent/indent.c

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



CVS commit: src/tests/usr.bin/indent

2021-10-29 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Fri Oct 29 19:39:32 UTC 2021

Modified Files:
src/tests/usr.bin/indent: t_errors.sh

Log Message:
tests/indent: demonstrate segmentation fault in search_stmt_comment


To generate a diff of this commit:
cvs rdiff -u -r1.11 -r1.12 src/tests/usr.bin/indent/t_errors.sh

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



CVS commit: src/tests/usr.bin/indent

2021-10-29 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Fri Oct 29 19:39:32 UTC 2021

Modified Files:
src/tests/usr.bin/indent: t_errors.sh

Log Message:
tests/indent: demonstrate segmentation fault in search_stmt_comment


To generate a diff of this commit:
cvs rdiff -u -r1.11 -r1.12 src/tests/usr.bin/indent/t_errors.sh

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

Modified files:

Index: src/tests/usr.bin/indent/t_errors.sh
diff -u src/tests/usr.bin/indent/t_errors.sh:1.11 src/tests/usr.bin/indent/t_errors.sh:1.12
--- src/tests/usr.bin/indent/t_errors.sh:1.11	Fri Oct 29 16:54:51 2021
+++ src/tests/usr.bin/indent/t_errors.sh	Fri Oct 29 19:39:32 2021
@@ -1,5 +1,5 @@
 #! /bin/sh
-# $NetBSD: t_errors.sh,v 1.11 2021/10/29 16:54:51 rillig Exp $
+# $NetBSD: t_errors.sh,v 1.12 2021/10/29 19:39:32 rillig Exp $
 #
 # Copyright (c) 2021 The NetBSD Foundation, Inc.
 # All rights reserved.
@@ -408,6 +408,14 @@ unbalanced_parentheses_3_body()
 	"$indent" code.c
 }
 
+atf_test_case 'search_stmt_comment_segv'
+search_stmt_comment_segv_body()
+{
+	printf '{if(expr\n)/*c*/;}\n' > code.c
+
+	atf_check -s 'signal' \
+	"$indent" code.c -st
+}
 
 atf_init_test_cases()
 {
@@ -440,4 +448,5 @@ atf_init_test_cases()
 	atf_add_test_case 'unbalanced_parentheses_1'
 	atf_add_test_case 'unbalanced_parentheses_2'
 	atf_add_test_case 'unbalanced_parentheses_3'
+	atf_add_test_case 'search_stmt_comment_segv'
 }



Re: CVS commit: src

2021-10-29 Thread Robert Elz
Date:Fri, 29 Oct 2021 17:50:38 +
From:"Roland Illig" 
Message-ID:  <20211029175038.33b08f...@cvs.netbsd.org>

  | Log Message:
  | indent: use prev/curr/next to refer to the current token
  |
  | The word 'last' just didn't match with 'next'.

That depends upon how it is used, last is one of those "flexible"
words which means different things, depending upon the context.

Eg: "last night" does not mean the night before doomsday, it means
the night that just passed (the previous night if you like, though
no-one would say that with that meaning).

With that usage, last and next fit together just fine, today is
Saturday Oct 30, where I am (my timezone), last Thursday was Oct 28,
next Thursday is Nov 4.   Perfectly clear, and normal usages.

On the other hand the "last apple" usually means there are none
left after this one, but this one can be ambiguous, and more
context is needed.   "I want the last apple" has that meaning.
"The last apple tasted sweeter than the others" probably
has the "previous" meaning (though might now), though again,
I doubt anyone would use "previous" in that kind of sentence,
"last" is normal, whether it means "the one I just ate" (however
many are left), or "the one after which there were no more".
That difference is usually immaterial, as if there are no more
the last one eaten would be the last one...

Note: I am not objecting to the change, just that perhaps sometimes
all that is not clear to you might be just fine for others.

kre



CVS commit: src/usr.bin/indent

2021-10-29 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Fri Oct 29 18:18:03 UTC 2021

Modified Files:
src/usr.bin/indent: indent.h io.c

Log Message:
indent: reorder global variables to be more intuitive

The buffer 'inp' comes first. From there, a single token is read into
the buffer 'token'. From there, it usually ends up in 'code'. The buffer
'token' does not belong to the group of the other 3 buffers, which
together make up a line of formatted output.

No functional change.


To generate a diff of this commit:
cvs rdiff -u -r1.60 -r1.61 src/usr.bin/indent/indent.h
cvs rdiff -u -r1.104 -r1.105 src/usr.bin/indent/io.c

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



CVS commit: src/usr.bin/indent

2021-10-29 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Fri Oct 29 18:18:03 UTC 2021

Modified Files:
src/usr.bin/indent: indent.h io.c

Log Message:
indent: reorder global variables to be more intuitive

The buffer 'inp' comes first. From there, a single token is read into
the buffer 'token'. From there, it usually ends up in 'code'. The buffer
'token' does not belong to the group of the other 3 buffers, which
together make up a line of formatted output.

No functional change.


To generate a diff of this commit:
cvs rdiff -u -r1.60 -r1.61 src/usr.bin/indent/indent.h
cvs rdiff -u -r1.104 -r1.105 src/usr.bin/indent/io.c

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/indent/indent.h
diff -u src/usr.bin/indent/indent.h:1.60 src/usr.bin/indent/indent.h:1.61
--- src/usr.bin/indent/indent.h:1.60	Fri Oct 29 17:50:37 2021
+++ src/usr.bin/indent/indent.h	Fri Oct 29 18:18:03 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: indent.h,v 1.60 2021/10/29 17:50:37 rillig Exp $	*/
+/*	$NetBSD: indent.h,v 1.61 2021/10/29 18:18:03 rillig Exp $	*/
 
 /*-
  * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
@@ -135,22 +135,28 @@ typedef enum stmt_head {
  * of code */
 
 
+/* A range of characters, in some cases null-terminated. */
 struct buffer {
-char *buf;			/* buffer */
-char *s;			/* start */
-char *e;			/* end */
-char *l;			/* limit */
+char *s;			/* start of the usable text */
+char *e;			/* end of the usable text */
+char *buf;			/* start of the allocated memory */
+char *l;			/* end of the allocated memory */
 };
 
 extern FILE *input;
 extern FILE *output;
 
-extern struct buffer lab;	/* label or preprocessor directive */
-extern struct buffer code;	/* code */
-extern struct buffer com;	/* comment */
-extern struct buffer token;	/* the last token scanned */
+extern struct buffer inp;	/* one line of input, ready to be split into
+ * tokens */
 
-extern struct buffer inp;
+extern struct buffer token;	/* the current token to be processed, is
+ * typically copied to the buffer 'code',
+ * or in some cases to 'lab'. */
+
+extern struct buffer lab;	/* the label or preprocessor directive */
+extern struct buffer code;	/* the main part of the current line of code */
+extern struct buffer com;	/* the trailing comment of the line, or the
+ * start or end of a multi-line comment */
 
 extern char sc_buf[sc_size];	/* input text is saved here when looking for
  * the brace after an if, while, etc */

Index: src/usr.bin/indent/io.c
diff -u src/usr.bin/indent/io.c:1.104 src/usr.bin/indent/io.c:1.105
--- src/usr.bin/indent/io.c:1.104	Fri Oct 29 17:32:22 2021
+++ src/usr.bin/indent/io.c	Fri Oct 29 18:18:03 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: io.c,v 1.104 2021/10/29 17:32:22 rillig Exp $	*/
+/*	$NetBSD: io.c,v 1.105 2021/10/29 18:18:03 rillig Exp $	*/
 
 /*-
  * SPDX-License-Identifier: BSD-4-Clause
@@ -43,7 +43,7 @@ static char sccsid[] = "@(#)io.c	8.1 (Be
 
 #include 
 #if defined(__NetBSD__)
-__RCSID("$NetBSD: io.c,v 1.104 2021/10/29 17:32:22 rillig Exp $");
+__RCSID("$NetBSD: io.c,v 1.105 2021/10/29 18:18:03 rillig Exp $");
 #elif defined(__FreeBSD__)
 __FBSDID("$FreeBSD: head/usr.bin/indent/io.c 334927 2018-06-10 16:44:18Z pstef $");
 #endif
@@ -153,7 +153,7 @@ dump_line_code(int ind)
 	/* XXX: the '+ 1' smells like an off-by-one error. */
 	ps.paren_indents[i] = (short)-(paren_ind + target_ind + 1);
 	debug_println(
-		"setting pi[%d] from %d to %d for column %d",
+		"setting paren_indents[%d] from %d to %d for column %d",
 		i, paren_ind, ps.paren_indents[i], target_ind + 1);
 	}
 }
@@ -186,7 +186,7 @@ dump_line_comment(int ind)
 	}
 }
 
-/* if comment can't fit on this line, put it on next line */
+/* if comment can't fit on this line, put it on the next line */
 if (ind > target_ind) {
 	output_char('\n');
 	ind = 0;
@@ -204,8 +204,8 @@ dump_line_comment(int ind)
 }
 
 /*
- * Write a line of formatted source to the output file. The line consists of a
- * label, the code and the comment.
+ * Write a line of formatted source to the output file. The line consists of
+ * the label, the code and the comment.
  */
 static void
 output_line(char line_terminator)



CVS commit: src/usr.bin/indent

2021-10-29 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Fri Oct 29 18:50:52 UTC 2021

Modified Files:
src/usr.bin/indent: indent.c

Log Message:
indent: mark obviously broken code


To generate a diff of this commit:
cvs rdiff -u -r1.171 -r1.172 src/usr.bin/indent/indent.c

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/indent/indent.c
diff -u src/usr.bin/indent/indent.c:1.171 src/usr.bin/indent/indent.c:1.172
--- src/usr.bin/indent/indent.c:1.171	Fri Oct 29 17:50:37 2021
+++ src/usr.bin/indent/indent.c	Fri Oct 29 18:50:52 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: indent.c,v 1.171 2021/10/29 17:50:37 rillig Exp $	*/
+/*	$NetBSD: indent.c,v 1.172 2021/10/29 18:50:52 rillig Exp $	*/
 
 /*-
  * SPDX-License-Identifier: BSD-4-Clause
@@ -43,7 +43,7 @@ static char sccsid[] = "@(#)indent.c	5.1
 
 #include 
 #if defined(__NetBSD__)
-__RCSID("$NetBSD: indent.c,v 1.171 2021/10/29 17:50:37 rillig Exp $");
+__RCSID("$NetBSD: indent.c,v 1.172 2021/10/29 18:50:52 rillig Exp $");
 #elif defined(__FreeBSD__)
 __FBSDID("$FreeBSD: head/usr.bin/indent/indent.c 340138 2018-11-04 19:24:49Z oshogbo $");
 #endif
@@ -188,6 +188,12 @@ search_stmt_comment(bool *comment_buffer
 	 * process_comment() will use that to calculate original indentation
 	 * of a boxed comment.
 	 */
+	/*
+	 * FIXME: This '4' needs an explanation. For example, in the snippet
+	 * 'if(expr)/''*comment', the 'r)' of the code is not copied. If there
+	 * is an additional line break before the ')', memcpy tries to copy
+	 * (size_t)-1 bytes.
+	 */
 	memcpy(sc_buf, inp.buf, (size_t)(inp.s - inp.buf) - 4);
 	save_com = sc_buf + (inp.s - inp.buf - 4);
 	save_com[0] = save_com[1] = ' ';



CVS commit: src/usr.bin/indent

2021-10-29 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Fri Oct 29 18:50:52 UTC 2021

Modified Files:
src/usr.bin/indent: indent.c

Log Message:
indent: mark obviously broken code


To generate a diff of this commit:
cvs rdiff -u -r1.171 -r1.172 src/usr.bin/indent/indent.c

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



CVS commit: src/sys/dev/sbus

2021-10-29 Thread Michael Lorenz
Module Name:src
Committed By:   macallan
Date:   Fri Oct 29 19:10:14 UTC 2021

Modified Files:
src/sys/dev/sbus: Makefile

Log Message:
install mgxreg.h so we can use it from Xorg


To generate a diff of this commit:
cvs rdiff -u -r1.4 -r1.5 src/sys/dev/sbus/Makefile

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



CVS commit: src/sys/dev/sbus

2021-10-29 Thread Michael Lorenz
Module Name:src
Committed By:   macallan
Date:   Fri Oct 29 19:10:14 UTC 2021

Modified Files:
src/sys/dev/sbus: Makefile

Log Message:
install mgxreg.h so we can use it from Xorg


To generate a diff of this commit:
cvs rdiff -u -r1.4 -r1.5 src/sys/dev/sbus/Makefile

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

Modified files:

Index: src/sys/dev/sbus/Makefile
diff -u src/sys/dev/sbus/Makefile:1.4 src/sys/dev/sbus/Makefile:1.5
--- src/sys/dev/sbus/Makefile:1.4	Wed Apr 11 19:07:37 2001
+++ src/sys/dev/sbus/Makefile	Fri Oct 29 19:10:14 2021
@@ -1,8 +1,8 @@
-#	$NetBSD: Makefile,v 1.4 2001/04/11 19:07:37 jdolecek Exp $
+#	$NetBSD: Makefile,v 1.5 2021/10/29 19:10:14 macallan Exp $
 
 INCSDIR= /usr/include/dev/sbus
 
 # Only install includes which are used by userland
-INCS=	mbppio.h
+INCS=	mbppio.h mgxreg.h
 
 .include 



CVS commit: src/usr.bin/indent

2021-10-29 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Fri Oct 29 19:31:24 UTC 2021

Modified Files:
src/usr.bin/indent: indent.c

Log Message:
indent: initialize 'ps' via code

This saves 3 kB of binary size since the parser state is rather large
and only very few members are initialized to non-zero values.

No functional change.


To generate a diff of this commit:
cvs rdiff -u -r1.174 -r1.175 src/usr.bin/indent/indent.c

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



CVS commit: src/usr.bin/indent

2021-10-29 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Fri Oct 29 19:31:24 UTC 2021

Modified Files:
src/usr.bin/indent: indent.c

Log Message:
indent: initialize 'ps' via code

This saves 3 kB of binary size since the parser state is rather large
and only very few members are initialized to non-zero values.

No functional change.


To generate a diff of this commit:
cvs rdiff -u -r1.174 -r1.175 src/usr.bin/indent/indent.c

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/indent/indent.c
diff -u src/usr.bin/indent/indent.c:1.174 src/usr.bin/indent/indent.c:1.175
--- src/usr.bin/indent/indent.c:1.174	Fri Oct 29 19:22:55 2021
+++ src/usr.bin/indent/indent.c	Fri Oct 29 19:31:24 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: indent.c,v 1.174 2021/10/29 19:22:55 rillig Exp $	*/
+/*	$NetBSD: indent.c,v 1.175 2021/10/29 19:31:24 rillig Exp $	*/
 
 /*-
  * SPDX-License-Identifier: BSD-4-Clause
@@ -43,7 +43,7 @@ static char sccsid[] = "@(#)indent.c	5.1
 
 #include 
 #if defined(__NetBSD__)
-__RCSID("$NetBSD: indent.c,v 1.174 2021/10/29 19:22:55 rillig Exp $");
+__RCSID("$NetBSD: indent.c,v 1.175 2021/10/29 19:31:24 rillig Exp $");
 #elif defined(__FreeBSD__)
 __FBSDID("$FreeBSD: head/usr.bin/indent/indent.c 340138 2018-11-04 19:24:49Z oshogbo $");
 #endif
@@ -85,11 +85,7 @@ struct options opt = {
 .use_tabs = true,
 };
 
-struct parser_state ps = {
-.s_sym[0] = psym_stmt,
-.prev_token = lsym_semicolon,
-.prev_newline = true,
-};
+struct parser_state ps;
 
 struct buffer lab;
 struct buffer code;
@@ -469,6 +465,10 @@ main_init_globals(void)
 buf_init();
 buf_init();
 
+ps.s_sym[0] = psym_stmt;
+ps.prev_token = lsym_semicolon;
+ps.prev_newline = true;
+
 const char *suffix = getenv("SIMPLE_BACKUP_SUFFIX");
 if (suffix != NULL)
 	backup_suffix = suffix;



CVS commit: src/usr.bin/indent

2021-10-29 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Fri Oct 29 19:52:59 UTC 2021

Modified Files:
src/usr.bin/indent: args.c

Log Message:
indent: parse options in a platform-independent way

Previously, on an ILP32 platform, the option '-ts3'
resulted in the error message 'must be an integer', on LP64 platforms it
resulted in the error message 'must be between 1 and 80'. Remove this
unnecessary difference.


To generate a diff of this commit:
cvs rdiff -u -r1.66 -r1.67 src/usr.bin/indent/args.c

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



CVS commit: src/usr.bin/indent

2021-10-29 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Fri Oct 29 19:52:59 UTC 2021

Modified Files:
src/usr.bin/indent: args.c

Log Message:
indent: parse options in a platform-independent way

Previously, on an ILP32 platform, the option '-ts3'
resulted in the error message 'must be an integer', on LP64 platforms it
resulted in the error message 'must be between 1 and 80'. Remove this
unnecessary difference.


To generate a diff of this commit:
cvs rdiff -u -r1.66 -r1.67 src/usr.bin/indent/args.c

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/indent/args.c
diff -u src/usr.bin/indent/args.c:1.66 src/usr.bin/indent/args.c:1.67
--- src/usr.bin/indent/args.c:1.66	Thu Oct 28 22:20:08 2021
+++ src/usr.bin/indent/args.c	Fri Oct 29 19:52:59 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: args.c,v 1.66 2021/10/28 22:20:08 rillig Exp $	*/
+/*	$NetBSD: args.c,v 1.67 2021/10/29 19:52:59 rillig Exp $	*/
 
 /*-
  * SPDX-License-Identifier: BSD-4-Clause
@@ -43,7 +43,7 @@ static char sccsid[] = "@(#)args.c	8.1 (
 
 #include 
 #if defined(__NetBSD__)
-__RCSID("$NetBSD: args.c,v 1.66 2021/10/28 22:20:08 rillig Exp $");
+__RCSID("$NetBSD: args.c,v 1.67 2021/10/29 19:52:59 rillig Exp $");
 #elif defined(__FreeBSD__)
 __FBSDID("$FreeBSD: head/usr.bin/indent/args.c 336318 2018-07-15 21:04:21Z pstef $");
 #endif
@@ -52,7 +52,6 @@ __FBSDID("$FreeBSD: head/usr.bin/indent/
 
 #include 
 #include 
-#include 
 #include 
 #include 
 #include 
@@ -241,10 +240,9 @@ found:
 	return;
 }
 
-errno = 0;
 char *end;
 long num = strtol(arg_arg, , 10);
-if (!(errno == 0 && *end == '\0'))
+if (*end != '\0')
 	errx(1, "%s: argument \"%s\" to option \"-%s\" must be an integer",
 	option_source, arg_arg, p->p_name);
 



CVS commit: src

2021-10-29 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Fri Oct 29 20:05:58 UTC 2021

Modified Files:
src/tests/usr.bin/indent: t_errors.sh
src/usr.bin/indent: indent.c

Log Message:
indent: replace segmentation fault with assertion


To generate a diff of this commit:
cvs rdiff -u -r1.12 -r1.13 src/tests/usr.bin/indent/t_errors.sh
cvs rdiff -u -r1.175 -r1.176 src/usr.bin/indent/indent.c

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



CVS commit: src

2021-10-29 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Fri Oct 29 20:05:58 UTC 2021

Modified Files:
src/tests/usr.bin/indent: t_errors.sh
src/usr.bin/indent: indent.c

Log Message:
indent: replace segmentation fault with assertion


To generate a diff of this commit:
cvs rdiff -u -r1.12 -r1.13 src/tests/usr.bin/indent/t_errors.sh
cvs rdiff -u -r1.175 -r1.176 src/usr.bin/indent/indent.c

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

Modified files:

Index: src/tests/usr.bin/indent/t_errors.sh
diff -u src/tests/usr.bin/indent/t_errors.sh:1.12 src/tests/usr.bin/indent/t_errors.sh:1.13
--- src/tests/usr.bin/indent/t_errors.sh:1.12	Fri Oct 29 19:39:32 2021
+++ src/tests/usr.bin/indent/t_errors.sh	Fri Oct 29 20:05:58 2021
@@ -1,5 +1,5 @@
 #! /bin/sh
-# $NetBSD: t_errors.sh,v 1.12 2021/10/29 19:39:32 rillig Exp $
+# $NetBSD: t_errors.sh,v 1.13 2021/10/29 20:05:58 rillig Exp $
 #
 # Copyright (c) 2021 The NetBSD Foundation, Inc.
 # All rights reserved.
@@ -413,7 +413,7 @@ search_stmt_comment_segv_body()
 {
 	printf '{if(expr\n)/*c*/;}\n' > code.c
 
-	atf_check -s 'signal' \
+	atf_check -s 'signal' -o 'ignore' -e 'match:assert' \
 	"$indent" code.c -st
 }
 

Index: src/usr.bin/indent/indent.c
diff -u src/usr.bin/indent/indent.c:1.175 src/usr.bin/indent/indent.c:1.176
--- src/usr.bin/indent/indent.c:1.175	Fri Oct 29 19:31:24 2021
+++ src/usr.bin/indent/indent.c	Fri Oct 29 20:05:58 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: indent.c,v 1.175 2021/10/29 19:31:24 rillig Exp $	*/
+/*	$NetBSD: indent.c,v 1.176 2021/10/29 20:05:58 rillig Exp $	*/
 
 /*-
  * SPDX-License-Identifier: BSD-4-Clause
@@ -43,7 +43,7 @@ static char sccsid[] = "@(#)indent.c	5.1
 
 #include 
 #if defined(__NetBSD__)
-__RCSID("$NetBSD: indent.c,v 1.175 2021/10/29 19:31:24 rillig Exp $");
+__RCSID("$NetBSD: indent.c,v 1.176 2021/10/29 20:05:58 rillig Exp $");
 #elif defined(__FreeBSD__)
 __FBSDID("$FreeBSD: head/usr.bin/indent/indent.c 340138 2018-11-04 19:24:49Z oshogbo $");
 #endif
@@ -53,6 +53,7 @@ __FBSDID("$FreeBSD: head/usr.bin/indent/
 #include 
 #include 
 #endif
+#include 
 #include 
 #include 
 #include 
@@ -194,6 +195,7 @@ search_stmt_comment(bool *comment_buffer
 	 * is an additional line break before the ')', memcpy tries to copy
 	 * (size_t)-1 bytes.
 	 */
+	assert((size_t)(inp.s - inp.buf) >= 4);
 	memcpy(sc_buf, inp.buf, (size_t)(inp.s - inp.buf) - 4);
 	save_com = sc_buf + (inp.s - inp.buf - 4);
 	save_com[0] = save_com[1] = ' ';



CVS commit: src/usr.bin/indent

2021-10-29 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Fri Oct 29 20:27:42 UTC 2021

Modified Files:
src/usr.bin/indent: indent.c indent.h io.c lexi.c pr_comment.c

Log Message:
indent: merge isblank and is_hspace into ch_isblank

No functional change.


To generate a diff of this commit:
cvs rdiff -u -r1.176 -r1.177 src/usr.bin/indent/indent.c
cvs rdiff -u -r1.61 -r1.62 src/usr.bin/indent/indent.h
cvs rdiff -u -r1.106 -r1.107 src/usr.bin/indent/io.c
cvs rdiff -u -r1.110 -r1.111 src/usr.bin/indent/lexi.c
cvs rdiff -u -r1.89 -r1.90 src/usr.bin/indent/pr_comment.c

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



CVS commit: src/usr.bin/indent

2021-10-29 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Fri Oct 29 20:27:42 UTC 2021

Modified Files:
src/usr.bin/indent: indent.c indent.h io.c lexi.c pr_comment.c

Log Message:
indent: merge isblank and is_hspace into ch_isblank

No functional change.


To generate a diff of this commit:
cvs rdiff -u -r1.176 -r1.177 src/usr.bin/indent/indent.c
cvs rdiff -u -r1.61 -r1.62 src/usr.bin/indent/indent.h
cvs rdiff -u -r1.106 -r1.107 src/usr.bin/indent/io.c
cvs rdiff -u -r1.110 -r1.111 src/usr.bin/indent/lexi.c
cvs rdiff -u -r1.89 -r1.90 src/usr.bin/indent/pr_comment.c

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/indent/indent.c
diff -u src/usr.bin/indent/indent.c:1.176 src/usr.bin/indent/indent.c:1.177
--- src/usr.bin/indent/indent.c:1.176	Fri Oct 29 20:05:58 2021
+++ src/usr.bin/indent/indent.c	Fri Oct 29 20:27:42 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: indent.c,v 1.176 2021/10/29 20:05:58 rillig Exp $	*/
+/*	$NetBSD: indent.c,v 1.177 2021/10/29 20:27:42 rillig Exp $	*/
 
 /*-
  * SPDX-License-Identifier: BSD-4-Clause
@@ -43,7 +43,7 @@ static char sccsid[] = "@(#)indent.c	5.1
 
 #include 
 #if defined(__NetBSD__)
-__RCSID("$NetBSD: indent.c,v 1.176 2021/10/29 20:05:58 rillig Exp $");
+__RCSID("$NetBSD: indent.c,v 1.177 2021/10/29 20:27:42 rillig Exp $");
 #elif defined(__FreeBSD__)
 __FBSDID("$FreeBSD: head/usr.bin/indent/indent.c 340138 2018-11-04 19:24:49Z oshogbo $");
 #endif
@@ -266,7 +266,7 @@ search_stmt_other(lexer_symbol lsym, boo
 	return false;
 }
 
-while (sc_end > save_com && isblank((unsigned char)sc_end[-1]))
+while (sc_end > save_com && ch_isblank(sc_end[-1]))
 	sc_end--;
 
 if (opt.swallow_optional_blanklines ||
@@ -332,7 +332,7 @@ search_stmt_lookahead(lexer_symbol *lsym
  * into the buffer so that the later lexi() call will read them.
  */
 if (sc_end != NULL) {
-	while (is_hspace(*inp.s)) {
+	while (ch_isblank(*inp.s)) {
 	*sc_end++ = *inp.s++;
 	if (sc_end >= _com[sc_size])
 		errx(1, "input too long");
@@ -1196,7 +1196,7 @@ read_preprocessing_line(void)
 state = PLAIN;
 int com_start = 0, com_end = 0;
 
-while (is_hspace(*inp.s))
+while (ch_isblank(*inp.s))
 	inbuf_skip();
 
 while (*inp.s != '\n' || (state == COMM && !had_eof)) {
@@ -1236,7 +1236,7 @@ read_preprocessing_line(void)
 	}
 }
 
-while (lab.e > lab.s && is_hspace(lab.e[-1]))
+while (lab.e > lab.s && ch_isblank(lab.e[-1]))
 	lab.e--;
 if (lab.e - lab.s == com_end && saved_inp_s == NULL) {
 	/* comment on preprocessor line */
@@ -1254,7 +1254,7 @@ read_preprocessing_line(void)
 	memmove(sc_end, lab.s + com_start, (size_t)(com_end - com_start));
 	sc_end += com_end - com_start;
 	lab.e = lab.s + com_start;
-	while (lab.e > lab.s && is_hspace(lab.e[-1]))
+	while (lab.e > lab.s && ch_isblank(lab.e[-1]))
 	lab.e--;
 	saved_inp_s = inp.s;	/* save current input buffer */
 	saved_inp_e = inp.e;

Index: src/usr.bin/indent/indent.h
diff -u src/usr.bin/indent/indent.h:1.61 src/usr.bin/indent/indent.h:1.62
--- src/usr.bin/indent/indent.h:1.61	Fri Oct 29 18:18:03 2021
+++ src/usr.bin/indent/indent.h	Fri Oct 29 20:27:42 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: indent.h,v 1.61 2021/10/29 18:18:03 rillig Exp $	*/
+/*	$NetBSD: indent.h,v 1.62 2021/10/29 20:27:42 rillig Exp $	*/
 
 /*-
  * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
@@ -407,7 +407,7 @@ char *xstrdup(const char *);
 void buf_expand(struct buffer *, size_t);
 
 static inline bool
-is_hspace(char ch)
+ch_isblank(char ch)
 {
 return ch == ' ' || ch == '\t';
 }

Index: src/usr.bin/indent/io.c
diff -u src/usr.bin/indent/io.c:1.106 src/usr.bin/indent/io.c:1.107
--- src/usr.bin/indent/io.c:1.106	Fri Oct 29 19:12:48 2021
+++ src/usr.bin/indent/io.c	Fri Oct 29 20:27:42 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: io.c,v 1.106 2021/10/29 19:12:48 rillig Exp $	*/
+/*	$NetBSD: io.c,v 1.107 2021/10/29 20:27:42 rillig Exp $	*/
 
 /*-
  * SPDX-License-Identifier: BSD-4-Clause
@@ -43,7 +43,7 @@ static char sccsid[] = "@(#)io.c	8.1 (Be
 
 #include 
 #if defined(__NetBSD__)
-__RCSID("$NetBSD: io.c,v 1.106 2021/10/29 19:12:48 rillig Exp $");
+__RCSID("$NetBSD: io.c,v 1.107 2021/10/29 20:27:42 rillig Exp $");
 #elif defined(__FreeBSD__)
 __FBSDID("$FreeBSD: head/usr.bin/indent/io.c 334927 2018-06-10 16:44:18Z pstef $");
 #endif
@@ -106,7 +106,7 @@ dump_line_label(void)
 {
 int ind;
 
-while (lab.e > lab.s && is_hspace(lab.e[-1]))
+while (lab.e > lab.s && ch_isblank(lab.e[-1]))
 	lab.e--;
 *lab.e = '\0';
 
@@ -121,7 +121,7 @@ dump_line_label(void)
 	output_char(*s++);
 	} while (s < lab.e && 'a' <= *s && *s <= 'z');
 
-	while (s < lab.e && is_hspace(*s))
+	while (s < lab.e && ch_isblank(*s))
 	s++;
 
 	if (s < lab.e) {
@@ -344,9 +344,9 @@ compute_label_indent(void)
 }
 
 static void
-skip_hspace(const char **pp)
+skip_blank(const char **pp)
 {
-while (is_hspace(**pp))
+while (ch_isblank(**pp))
 	

CVS commit: src/tests/usr.bin/indent

2021-10-29 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Fri Oct 29 22:37:25 UTC 2021

Modified Files:
src/tests/usr.bin/indent: token_binary_op.c

Log Message:
tests/indent: test binary operators for tokens in column 1


To generate a diff of this commit:
cvs rdiff -u -r1.4 -r1.5 src/tests/usr.bin/indent/token_binary_op.c

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



CVS commit: src/tests/usr.bin/indent

2021-10-29 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Fri Oct 29 22:37:25 UTC 2021

Modified Files:
src/tests/usr.bin/indent: token_binary_op.c

Log Message:
tests/indent: test binary operators for tokens in column 1


To generate a diff of this commit:
cvs rdiff -u -r1.4 -r1.5 src/tests/usr.bin/indent/token_binary_op.c

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

Modified files:

Index: src/tests/usr.bin/indent/token_binary_op.c
diff -u src/tests/usr.bin/indent/token_binary_op.c:1.4 src/tests/usr.bin/indent/token_binary_op.c:1.5
--- src/tests/usr.bin/indent/token_binary_op.c:1.4	Fri Oct 29 21:56:36 2021
+++ src/tests/usr.bin/indent/token_binary_op.c	Fri Oct 29 22:37:25 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: token_binary_op.c,v 1.4 2021/10/29 21:56:36 rillig Exp $ */
+/* $NetBSD: token_binary_op.c,v 1.5 2021/10/29 22:37:25 rillig Exp $ */
 /* $FreeBSD$ */
 
 /*
@@ -239,3 +239,30 @@ char *(*fn)(int, int) = NULL;
 /* XXX: The parameter '(int)' is wrongly interpreted as a type cast. */
 /* XXX: The parameter '(int, int)' is wrongly interpreted as a type cast. */
 #indent run-equals-input -di0
+
+
+/*
+ * Ensure that the result of the indentation does not depend on whether a
+ * token from the input starts in column 1 or 9.
+ *
+ * See process_binary_op, ps.prev_col_1.
+ */
+#indent input
+int col_1 //
+= //
+1;
+
+int col_9 //
+	= //
+	9;
+#indent end
+
+#indent run
+int		col_1		//
+=//
+1;
+
+int		col_9		//
+=//
+9;
+#indent end



CVS commit: src/usr.bin/indent

2021-10-29 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Fri Oct 29 22:52:50 UTC 2021

Modified Files:
src/usr.bin/indent: parse.c

Log Message:
indent: reduce indentation in parse, extract decl_level

No functional change.


To generate a diff of this commit:
cvs rdiff -u -r1.44 -r1.45 src/usr.bin/indent/parse.c

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



CVS commit: src/usr.bin/indent

2021-10-29 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Fri Oct 29 22:52:50 UTC 2021

Modified Files:
src/usr.bin/indent: parse.c

Log Message:
indent: reduce indentation in parse, extract decl_level

No functional change.


To generate a diff of this commit:
cvs rdiff -u -r1.44 -r1.45 src/usr.bin/indent/parse.c

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/indent/parse.c
diff -u src/usr.bin/indent/parse.c:1.44 src/usr.bin/indent/parse.c:1.45
--- src/usr.bin/indent/parse.c:1.44	Thu Oct 28 22:20:08 2021
+++ src/usr.bin/indent/parse.c	Fri Oct 29 22:52:50 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: parse.c,v 1.44 2021/10/28 22:20:08 rillig Exp $	*/
+/*	$NetBSD: parse.c,v 1.45 2021/10/29 22:52:50 rillig Exp $	*/
 
 /*-
  * SPDX-License-Identifier: BSD-4-Clause
@@ -84,6 +84,16 @@ psym_name(parser_symbol psym)
 }
 #endif
 
+static int
+decl_level(void)
+{
+int level = 0;
+for (int i = ps.tos - 1; i > 0; i--)
+	if (ps.s_sym[i] == psym_decl)
+	level++;
+return level;
+}
+
 /*
  * Shift the token onto the parser stack, or reduce it by combining it with
  * previous tokens.
@@ -106,22 +116,16 @@ parse(parser_symbol psym)
 	ps.search_stmt = opt.brace_same_line;
 	/* indicate that following brace should be on same line */
 
-	if (ps.s_sym[ps.tos] != psym_decl) {	/* only put one declaration
-		 * onto stack */
-	break_comma = true;	/* while in declaration, newline should be
- * forced after comma */
-	ps.s_sym[++ps.tos] = psym_decl;
-	ps.s_ind_level[ps.tos] = ps.ind_level_follow;
+	if (ps.s_sym[ps.tos] == psym_decl)
+	break;		/* only put one declaration onto stack */
 
-	if (opt.ljust_decl) {
-		ps.ind_level = 0;
-		for (int i = ps.tos - 1; i > 0; --i)
-		if (ps.s_sym[i] == psym_decl)
-			++ps.ind_level;	/* indentation is number of
-	 * declaration levels deep we are */
-		ps.ind_level_follow = ps.ind_level;
-	}
-	}
+	break_comma = true;	/* while in a declaration, force a newline
+ * after comma */
+	ps.s_sym[++ps.tos] = psym_decl;
+	ps.s_ind_level[ps.tos] = ps.ind_level_follow;
+
+	if (opt.ljust_decl)
+	ps.ind_level_follow = ps.ind_level = decl_level();
 	break;
 
 case psym_if_expr:		/* 'if' '('  ')' */



CVS commit: src/usr.bin/indent

2021-10-29 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Fri Oct 29 23:03:53 UTC 2021

Modified Files:
src/usr.bin/indent: parse.c

Log Message:
indent: remove redundant comments

The comments only repeated what the constants for the parser symbols
already express in their names. In the past, the names of these
constants were inconsistent and misleading; back then, it made sense to
make the comments express the actual meaning of the constants.


To generate a diff of this commit:
cvs rdiff -u -r1.45 -r1.46 src/usr.bin/indent/parse.c

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



CVS commit: src/usr.bin/indent

2021-10-29 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Fri Oct 29 23:03:53 UTC 2021

Modified Files:
src/usr.bin/indent: parse.c

Log Message:
indent: remove redundant comments

The comments only repeated what the constants for the parser symbols
already express in their names. In the past, the names of these
constants were inconsistent and misleading; back then, it made sense to
make the comments express the actual meaning of the constants.


To generate a diff of this commit:
cvs rdiff -u -r1.45 -r1.46 src/usr.bin/indent/parse.c

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/indent/parse.c
diff -u src/usr.bin/indent/parse.c:1.45 src/usr.bin/indent/parse.c:1.46
--- src/usr.bin/indent/parse.c:1.45	Fri Oct 29 22:52:50 2021
+++ src/usr.bin/indent/parse.c	Fri Oct 29 23:03:53 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: parse.c,v 1.45 2021/10/29 22:52:50 rillig Exp $	*/
+/*	$NetBSD: parse.c,v 1.46 2021/10/29 23:03:53 rillig Exp $	*/
 
 /*-
  * SPDX-License-Identifier: BSD-4-Clause
@@ -128,7 +128,7 @@ parse(parser_symbol psym)
 	ps.ind_level_follow = ps.ind_level = decl_level();
 	break;
 
-case psym_if_expr:		/* 'if' '('  ')' */
+case psym_if_expr:
 	if (ps.s_sym[ps.tos] == psym_if_expr_stmt_else && opt.else_if) {
 	/*
 	 * Reduce "else if" to "if". This saves a lot of stack space in
@@ -138,7 +138,7 @@ parse(parser_symbol psym)
 	}
 	/* FALLTHROUGH */
 case psym_do:
-case psym_for_exprs:	/* 'for' (...) */
+case psym_for_exprs:
 	ps.s_sym[++ps.tos] = psym;
 	ps.s_ind_level[ps.tos] = ps.ind_level = ps.ind_level_follow;
 	++ps.ind_level_follow;	/* subsequent statements should be indented 1 */
@@ -172,7 +172,7 @@ parse(parser_symbol psym)
 	ps.s_ind_level[ps.tos] = ps.ind_level_follow;
 	break;
 
-case psym_while_expr:	/* 'while' '('  ')' */
+case psym_while_expr:
 	if (ps.s_sym[ps.tos] == psym_do_stmt) {
 	/* it is matched with do stmt */
 	ps.ind_level = ps.ind_level_follow = ps.s_ind_level[ps.tos];
@@ -210,7 +210,7 @@ parse(parser_symbol psym)
 	diag(1, "Statement nesting error");
 	break;
 
-case psym_switch_expr:	/* had switch (...) */
+case psym_switch_expr:
 	ps.s_sym[++ps.tos] = psym_switch_expr;
 	ps.s_case_ind_level[ps.tos] = case_ind;
 	/* save current case indent level */
@@ -222,9 +222,8 @@ parse(parser_symbol psym)
 	ps.search_stmt = opt.brace_same_line;
 	break;
 
-case psym_semicolon:	/* this indicates a simple stmt */
-	break_comma = false;	/* turn off flag to break after commas in a
- * declaration */
+case psym_semicolon:	/* a simple statement */
+	break_comma = false;	/* don't break after comma in a declaration */
 	ps.s_sym[++ps.tos] = psym_stmt;
 	ps.s_ind_level[ps.tos] = ps.ind_level;
 	break;



CVS commit: src

2021-10-29 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Fri Oct 29 21:56:37 UTC 2021

Modified Files:
src/tests/usr.bin/indent: token_binary_op.c
src/usr.bin/indent: indent.c indent.h

Log Message:
indent: fix missing blank before binary operator


To generate a diff of this commit:
cvs rdiff -u -r1.3 -r1.4 src/tests/usr.bin/indent/token_binary_op.c
cvs rdiff -u -r1.177 -r1.178 src/usr.bin/indent/indent.c
cvs rdiff -u -r1.62 -r1.63 src/usr.bin/indent/indent.h

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



CVS commit: src

2021-10-29 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Fri Oct 29 21:56:37 UTC 2021

Modified Files:
src/tests/usr.bin/indent: token_binary_op.c
src/usr.bin/indent: indent.c indent.h

Log Message:
indent: fix missing blank before binary operator


To generate a diff of this commit:
cvs rdiff -u -r1.3 -r1.4 src/tests/usr.bin/indent/token_binary_op.c
cvs rdiff -u -r1.177 -r1.178 src/usr.bin/indent/indent.c
cvs rdiff -u -r1.62 -r1.63 src/usr.bin/indent/indent.h

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

Modified files:

Index: src/tests/usr.bin/indent/token_binary_op.c
diff -u src/tests/usr.bin/indent/token_binary_op.c:1.3 src/tests/usr.bin/indent/token_binary_op.c:1.4
--- src/tests/usr.bin/indent/token_binary_op.c:1.3	Tue Oct 26 22:00:38 2021
+++ src/tests/usr.bin/indent/token_binary_op.c	Fri Oct 29 21:56:36 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: token_binary_op.c,v 1.3 2021/10/26 22:00:38 rillig Exp $ */
+/* $NetBSD: token_binary_op.c,v 1.4 2021/10/29 21:56:36 rillig Exp $ */
 /* $FreeBSD$ */
 
 /*
@@ -220,18 +220,22 @@ peculiarities(void)
 #indent end
 
 
+/*
+ * Before NetBSD indent.c 1.178 from 2021-10-29, indent removed the blank
+ * before the '=', in the second and third of these function pointer
+ * declarations. This was because indent interpreted the prototype parameters
+ * 'int' and 'int, int' as type casts, which doesn't make sense at all. Fixing
+ * this properly requires large style changes since indent is based on simple
+ * heuristics all over. This didn't change in indent.c 1.178; instead, the
+ * rule for inserting a blank before a binary operator was changed to always
+ * insert a blank, except at the beginning of a line.
+ */
 #indent input
 char *(*fn)() = NULL;
 char *(*fn)(int) = NULL;
 char *(*fn)(int, int) = NULL;
 #indent end
 
-/* FIXME: The parameter '(int)' is wrongly interpreted as a type cast. */
-/* FIXME: The parameter '(int, int)' is wrongly interpreted as a type cast. */
-#indent run -di0
-char *(*fn)() = NULL;
-/* $ FIXME: Missing space before '='. */
-char *(*fn)(int)= NULL;
-/* $ FIXME: Missing space before '='. */
-char *(*fn)(int, int)= NULL;
-#indent end
+/* XXX: The parameter '(int)' is wrongly interpreted as a type cast. */
+/* XXX: The parameter '(int, int)' is wrongly interpreted as a type cast. */
+#indent run-equals-input -di0

Index: src/usr.bin/indent/indent.c
diff -u src/usr.bin/indent/indent.c:1.177 src/usr.bin/indent/indent.c:1.178
--- src/usr.bin/indent/indent.c:1.177	Fri Oct 29 20:27:42 2021
+++ src/usr.bin/indent/indent.c	Fri Oct 29 21:56:36 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: indent.c,v 1.177 2021/10/29 20:27:42 rillig Exp $	*/
+/*	$NetBSD: indent.c,v 1.178 2021/10/29 21:56:36 rillig Exp $	*/
 
 /*-
  * SPDX-License-Identifier: BSD-4-Clause
@@ -43,7 +43,7 @@ static char sccsid[] = "@(#)indent.c	5.1
 
 #include 
 #if defined(__NetBSD__)
-__RCSID("$NetBSD: indent.c,v 1.177 2021/10/29 20:27:42 rillig Exp $");
+__RCSID("$NetBSD: indent.c,v 1.178 2021/10/29 21:56:36 rillig Exp $");
 #elif defined(__FreeBSD__)
 __FBSDID("$FreeBSD: head/usr.bin/indent/indent.c 340138 2018-11-04 19:24:49Z oshogbo $");
 #endif
@@ -815,7 +815,7 @@ process_unary_op(int decl_ind, bool tabs
 static void
 process_binary_op(void)
 {
-if (ps.want_blank)
+if (!ps.prev_newline && buf_len() > 0)
 	buf_add_char(, ' ');
 buf_add_buf(, );
 ps.want_blank = true;

Index: src/usr.bin/indent/indent.h
diff -u src/usr.bin/indent/indent.h:1.62 src/usr.bin/indent/indent.h:1.63
--- src/usr.bin/indent/indent.h:1.62	Fri Oct 29 20:27:42 2021
+++ src/usr.bin/indent/indent.h	Fri Oct 29 21:56:36 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: indent.h,v 1.62 2021/10/29 20:27:42 rillig Exp $	*/
+/*	$NetBSD: indent.h,v 1.63 2021/10/29 21:56:36 rillig Exp $	*/
 
 /*-
  * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
@@ -285,7 +285,8 @@ extern struct parser_state {
 lexer_symbol prev_token;
 bool prev_newline;		/* whether the last thing scanned was a
  * newline */
-bool prev_col_1;		/* whether the last token started in column 1 */
+bool prev_col_1;		/* whether the last token started in column 1
+ * of the unformatted input */
 enum keyword_kind prev_keyword;
 enum keyword_kind curr_keyword;
 bool next_unary;		/* whether the following operator should be



Re: CVS commit: src

2021-10-29 Thread Roland Illig

Am 29.10.2021 um 22:40 schrieb Robert Elz:

 Date:Fri, 29 Oct 2021 17:50:38 +
 From:"Roland Illig" 
 Message-ID:  <20211029175038.33b08f...@cvs.netbsd.org>

   | Log Message:
   | indent: use prev/curr/next to refer to the current token
   |
   | The word 'last' just didn't match with 'next'.

That depends upon how it is used, last is one of those "flexible"
words which means different things, depending upon the context.


It's exactly this flexibility that I wanted to eliminate from the code.

For example, the function process_command has the variable last_blank
that remembers the index of the last (rightmost) seen blank in a line.
In that case, "previous" and "last seen" and "rightmost" are equivalent,
which is OK in that context.

To avoid confusion in the parser_state, I wanted to use a different word
to specify the directly adjacent item, and prev/curr/next just seemed to
be a good fit in a situation of iterating over tokens, to avoid the
ambiguity of first/last and last/next. The code is still complicated
enough that I welcome every little bit of disambiguation that I can get.

Roland


CVS commit: src/sys/dev/i2c

2021-10-29 Thread Brad Spencer
Module Name:src
Committed By:   brad
Date:   Fri Oct 29 23:23:33 UTC 2021

Modified Files:
src/sys/dev/i2c: sht4x.c

Log Message:
Correct an off by one degree error in the temperature conversion.


To generate a diff of this commit:
cvs rdiff -u -r1.1 -r1.2 src/sys/dev/i2c/sht4x.c

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



CVS commit: src/sys/dev/i2c

2021-10-29 Thread Brad Spencer
Module Name:src
Committed By:   brad
Date:   Fri Oct 29 23:23:33 UTC 2021

Modified Files:
src/sys/dev/i2c: sht4x.c

Log Message:
Correct an off by one degree error in the temperature conversion.


To generate a diff of this commit:
cvs rdiff -u -r1.1 -r1.2 src/sys/dev/i2c/sht4x.c

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

Modified files:

Index: src/sys/dev/i2c/sht4x.c
diff -u src/sys/dev/i2c/sht4x.c:1.1 src/sys/dev/i2c/sht4x.c:1.2
--- src/sys/dev/i2c/sht4x.c:1.1	Sun Oct  3 17:27:02 2021
+++ src/sys/dev/i2c/sht4x.c	Fri Oct 29 23:23:33 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: sht4x.c,v 1.1 2021/10/03 17:27:02 brad Exp $	*/
+/*	$NetBSD: sht4x.c,v 1.2 2021/10/29 23:23:33 brad Exp $	*/
 
 /*
  * Copyright (c) 2021 Brad Spencer 
@@ -17,7 +17,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: sht4x.c,v 1.1 2021/10/03 17:27:02 brad Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sht4x.c,v 1.2 2021/10/29 23:23:33 brad Exp $");
 
 /*
   Driver for the Sensirion SHT40/SHT41/SHT45
@@ -723,7 +723,7 @@ sht4x_refresh(struct sysmon_envsys * sme
 
 	  It follows then:
 
-	  T in Kelvin = (229.15 + 175 * rawvalue / 65535)
+	  T in Kelvin = (228.15 + 175 * rawvalue / 65535)
 
 	  given the relationship between Celsius and Kelvin.
 
@@ -771,7 +771,7 @@ sht4x_refresh(struct sysmon_envsys * sme
 		switch (edata->sensor) {
 		case SHT4X_TEMP_SENSOR:
 			svalptr = [0];
-			v1 = 22915; /* this is scaled up already from 229.15 */
+			v1 = 22815; /* this is scaled up already from 228.15 */
 			v2 = 175;
 			mul1 = 100;
 			mul2 = 1;



CVS commit: src/usr.bin/indent

2021-10-29 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Fri Oct 29 23:48:50 UTC 2021

Modified Files:
src/usr.bin/indent: indent.c lexi.c parse.c

Log Message:
indent: remove redundant comments, remove punctuation from debug log

The comment about 'null stmt' between braces probably meant 'no
statements between braces'.

The comments at psym_switch_expr only repeated what the code says or had
been outdated 29 years ago already since opt.case_indent does not have
to be 'one level down'.

In the debug log, the quotes around the symbol names are not necessary
after a ':'. The parse stack also does not need this much punctuation.

Reducing a do-while loop to nothing instead of a statement saves a few
CPU cycles. It works because after each lbrace, a stmt is pushed to the
parser stack. This stmt can only ever be reduced to a stmt_list but
never be removed.


To generate a diff of this commit:
cvs rdiff -u -r1.178 -r1.179 src/usr.bin/indent/indent.c
cvs rdiff -u -r1.113 -r1.114 src/usr.bin/indent/lexi.c
cvs rdiff -u -r1.46 -r1.47 src/usr.bin/indent/parse.c

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/indent/indent.c
diff -u src/usr.bin/indent/indent.c:1.178 src/usr.bin/indent/indent.c:1.179
--- src/usr.bin/indent/indent.c:1.178	Fri Oct 29 21:56:36 2021
+++ src/usr.bin/indent/indent.c	Fri Oct 29 23:48:50 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: indent.c,v 1.178 2021/10/29 21:56:36 rillig Exp $	*/
+/*	$NetBSD: indent.c,v 1.179 2021/10/29 23:48:50 rillig Exp $	*/
 
 /*-
  * SPDX-License-Identifier: BSD-4-Clause
@@ -43,7 +43,7 @@ static char sccsid[] = "@(#)indent.c	5.1
 
 #include 
 #if defined(__NetBSD__)
-__RCSID("$NetBSD: indent.c,v 1.178 2021/10/29 21:56:36 rillig Exp $");
+__RCSID("$NetBSD: indent.c,v 1.179 2021/10/29 23:48:50 rillig Exp $");
 #elif defined(__FreeBSD__)
 __FBSDID("$FreeBSD: head/usr.bin/indent/indent.c 340138 2018-11-04 19:24:49Z oshogbo $");
 #endif
@@ -342,6 +342,7 @@ search_stmt_lookahead(lexer_symbol *lsym
 }
 
 struct parser_state backup_ps = ps;
+debug_println("made backup of parser state");
 *lsym = lexi();
 if (*lsym == lsym_newline || *lsym == lsym_form_feed ||
 	*lsym == lsym_comment || ps.search_stmt) {

Index: src/usr.bin/indent/lexi.c
diff -u src/usr.bin/indent/lexi.c:1.113 src/usr.bin/indent/lexi.c:1.114
--- src/usr.bin/indent/lexi.c:1.113	Fri Oct 29 21:31:29 2021
+++ src/usr.bin/indent/lexi.c	Fri Oct 29 23:48:50 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: lexi.c,v 1.113 2021/10/29 21:31:29 rillig Exp $	*/
+/*	$NetBSD: lexi.c,v 1.114 2021/10/29 23:48:50 rillig Exp $	*/
 
 /*-
  * SPDX-License-Identifier: BSD-4-Clause
@@ -43,7 +43,7 @@ static char sccsid[] = "@(#)lexi.c	8.1 (
 
 #include 
 #if defined(__NetBSD__)
-__RCSID("$NetBSD: lexi.c,v 1.113 2021/10/29 21:31:29 rillig Exp $");
+__RCSID("$NetBSD: lexi.c,v 1.114 2021/10/29 23:48:50 rillig Exp $");
 #elif defined(__FreeBSD__)
 __FBSDID("$FreeBSD: head/usr.bin/indent/lexi.c 337862 2018-08-15 18:19:45Z pstef $");
 #endif
@@ -318,7 +318,7 @@ debug_lexi(lexer_symbol lsym)
 debug_print_buf("label", );
 debug_print_buf("code", );
 debug_print_buf("comment", );
-debug_printf("lexi returns '%s'", lsym_name(lsym));
+debug_printf("lexi: %s", lsym_name(lsym));
 debug_vis_range(" \"", token.s, token.e, "\"\n");
 
 // prev_token

Index: src/usr.bin/indent/parse.c
diff -u src/usr.bin/indent/parse.c:1.46 src/usr.bin/indent/parse.c:1.47
--- src/usr.bin/indent/parse.c:1.46	Fri Oct 29 23:03:53 2021
+++ src/usr.bin/indent/parse.c	Fri Oct 29 23:48:50 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: parse.c,v 1.46 2021/10/29 23:03:53 rillig Exp $	*/
+/*	$NetBSD: parse.c,v 1.47 2021/10/29 23:48:50 rillig Exp $	*/
 
 /*-
  * SPDX-License-Identifier: BSD-4-Clause
@@ -101,7 +101,7 @@ decl_level(void)
 void
 parse(parser_symbol psym)
 {
-debug_println("parse token: '%s'", psym_name(psym));
+debug_println("parse token: %s", psym_name(psym));
 
 if (psym != psym_else) {
 	while (ps.s_sym[ps.tos] == psym_if_expr_stmt) {
@@ -168,7 +168,6 @@ parse(parser_symbol psym)
 	ps.s_sym[++ps.tos] = psym_lbrace;
 	ps.s_ind_level[ps.tos] = ps.ind_level;
 	ps.s_sym[++ps.tos] = psym_stmt;
-	/* allow null stmt between braces */
 	ps.s_ind_level[ps.tos] = ps.ind_level_follow;
 	break;
 
@@ -213,11 +212,8 @@ parse(parser_symbol psym)
 case psym_switch_expr:
 	ps.s_sym[++ps.tos] = psym_switch_expr;
 	ps.s_case_ind_level[ps.tos] = case_ind;
-	/* save current case indent level */
 	ps.s_ind_level[ps.tos] = ps.ind_level_follow;
-	/* cases should be one level deeper than the switch */
 	case_ind = (float)ps.ind_level_follow + opt.case_indent;
-	/* statements should be two levels deeper */
 	ps.ind_level_follow += (int)opt.case_indent + 1;
 	ps.search_stmt = opt.brace_same_line;
 	break;
@@ -241,7 +237,7 @@ parse(parser_symbol psym)
 #ifdef debug
 printf("parse stack:");
 for (int i = 1; i <= ps.tos; ++i)
-	printf(" ('%s' at 

CVS commit: src/usr.bin/indent

2021-10-29 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Fri Oct 29 23:48:50 UTC 2021

Modified Files:
src/usr.bin/indent: indent.c lexi.c parse.c

Log Message:
indent: remove redundant comments, remove punctuation from debug log

The comment about 'null stmt' between braces probably meant 'no
statements between braces'.

The comments at psym_switch_expr only repeated what the code says or had
been outdated 29 years ago already since opt.case_indent does not have
to be 'one level down'.

In the debug log, the quotes around the symbol names are not necessary
after a ':'. The parse stack also does not need this much punctuation.

Reducing a do-while loop to nothing instead of a statement saves a few
CPU cycles. It works because after each lbrace, a stmt is pushed to the
parser stack. This stmt can only ever be reduced to a stmt_list but
never be removed.


To generate a diff of this commit:
cvs rdiff -u -r1.178 -r1.179 src/usr.bin/indent/indent.c
cvs rdiff -u -r1.113 -r1.114 src/usr.bin/indent/lexi.c
cvs rdiff -u -r1.46 -r1.47 src/usr.bin/indent/parse.c

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



CVS commit: src/usr.bin/indent

2021-10-29 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Fri Oct 29 21:22:06 UTC 2021

Modified Files:
src/usr.bin/indent: lexi.c

Log Message:
indent: add detailed debug logging for the parser state


To generate a diff of this commit:
cvs rdiff -u -r1.111 -r1.112 src/usr.bin/indent/lexi.c

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



CVS commit: src/usr.bin/indent

2021-10-29 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Fri Oct 29 21:22:06 UTC 2021

Modified Files:
src/usr.bin/indent: lexi.c

Log Message:
indent: add detailed debug logging for the parser state


To generate a diff of this commit:
cvs rdiff -u -r1.111 -r1.112 src/usr.bin/indent/lexi.c

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/indent/lexi.c
diff -u src/usr.bin/indent/lexi.c:1.111 src/usr.bin/indent/lexi.c:1.112
--- src/usr.bin/indent/lexi.c:1.111	Fri Oct 29 20:27:42 2021
+++ src/usr.bin/indent/lexi.c	Fri Oct 29 21:22:05 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: lexi.c,v 1.111 2021/10/29 20:27:42 rillig Exp $	*/
+/*	$NetBSD: lexi.c,v 1.112 2021/10/29 21:22:05 rillig Exp $	*/
 
 /*-
  * SPDX-License-Identifier: BSD-4-Clause
@@ -43,7 +43,7 @@ static char sccsid[] = "@(#)lexi.c	8.1 (
 
 #include 
 #if defined(__NetBSD__)
-__RCSID("$NetBSD: lexi.c,v 1.111 2021/10/29 20:27:42 rillig Exp $");
+__RCSID("$NetBSD: lexi.c,v 1.112 2021/10/29 21:22:05 rillig Exp $");
 #elif defined(__FreeBSD__)
 __FBSDID("$FreeBSD: head/usr.bin/indent/lexi.c 337862 2018-08-15 18:19:45Z pstef $");
 #endif
@@ -294,6 +294,15 @@ debug_print_buf(const char *name, const 
 }
 }
 
+#define debug_ps_bool(name) \
+	debug_println("[%c] " #name, ps.name ? 'x' : ' ')
+#define debug_ps_int(name) \
+	if (ps.name != 0) \
+	debug_println("%3d " #name, ps.name)
+#define debug_ps_keyword(name) \
+	if (ps.name != kw_0) \
+	debug_println("" #name " = %s", kw_name(ps.name))
+
 static void
 debug_lexi(lexer_symbol lsym)
 {
@@ -303,12 +312,45 @@ debug_lexi(lexer_symbol lsym)
 debug_print_buf("code", );
 debug_print_buf("comment", );
 debug_printf("lexi returns '%s'", lsym_name(lsym));
-if (ps.curr_keyword != kw_0)
-	debug_printf(" keyword '%s'", kw_name(ps.curr_keyword));
-if (ps.prev_keyword != kw_0)
-	debug_printf(" previous keyword '%s'", kw_name(ps.prev_keyword));
-debug_println("");
-debug_print_buf("token", );
+debug_vis_range(" \"", token.s, token.e, "\"\n");
+
+// prev_token
+debug_ps_bool(prev_newline);
+debug_ps_bool(prev_col_1);
+debug_ps_keyword(prev_keyword);
+debug_ps_keyword(curr_keyword);
+debug_ps_bool(next_unary);
+// procname
+debug_ps_bool(want_blank);
+debug_ps_int(paren_level);
+debug_ps_int(p_l_follow);
+// paren_indents
+debug_ps_int(cast_mask);
+debug_ps_int(not_cast_mask);
+
+debug_ps_int(comment_delta);
+debug_ps_int(n_comment_delta);
+debug_ps_int(com_ind);
+
+debug_ps_bool(block_init);
+debug_ps_int(block_init_level);
+debug_ps_bool(init_or_struct);
+
+debug_ps_int(ind_level);
+debug_ps_int(ind_level_follow);
+
+debug_ps_int(decl_nest);
+debug_ps_bool(decl_on_line);
+debug_ps_bool(in_decl);
+debug_ps_int(just_saw_decl);
+debug_ps_bool(in_parameter_declaration);
+debug_ps_bool(decl_indent_done);
+
+debug_ps_bool(in_stmt);
+debug_ps_bool(ind_stmt);
+debug_ps_bool(is_case_label);
+
+debug_ps_bool(search_stmt);
 }
 #endif
 



CVS commit: src/usr.bin/indent

2021-10-29 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Fri Oct 29 21:31:29 UTC 2021

Modified Files:
src/usr.bin/indent: lexi.c

Log Message:
indent: in debug mode, log only differences for most ps members


To generate a diff of this commit:
cvs rdiff -u -r1.112 -r1.113 src/usr.bin/indent/lexi.c

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/indent/lexi.c
diff -u src/usr.bin/indent/lexi.c:1.112 src/usr.bin/indent/lexi.c:1.113
--- src/usr.bin/indent/lexi.c:1.112	Fri Oct 29 21:22:05 2021
+++ src/usr.bin/indent/lexi.c	Fri Oct 29 21:31:29 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: lexi.c,v 1.112 2021/10/29 21:22:05 rillig Exp $	*/
+/*	$NetBSD: lexi.c,v 1.113 2021/10/29 21:31:29 rillig Exp $	*/
 
 /*-
  * SPDX-License-Identifier: BSD-4-Clause
@@ -43,7 +43,7 @@ static char sccsid[] = "@(#)lexi.c	8.1 (
 
 #include 
 #if defined(__NetBSD__)
-__RCSID("$NetBSD: lexi.c,v 1.112 2021/10/29 21:22:05 rillig Exp $");
+__RCSID("$NetBSD: lexi.c,v 1.113 2021/10/29 21:31:29 rillig Exp $");
 #elif defined(__FreeBSD__)
 __FBSDID("$FreeBSD: head/usr.bin/indent/lexi.c 337862 2018-08-15 18:19:45Z pstef $");
 #endif
@@ -295,17 +295,24 @@ debug_print_buf(const char *name, const 
 }
 
 #define debug_ps_bool(name) \
-	debug_println("[%c] " #name, ps.name ? 'x' : ' ')
+if (ps.name != prev_ps.name) \
+	debug_println("[%c] ps." #name, ps.name ? 'x' : ' ')
 #define debug_ps_int(name) \
-	if (ps.name != 0) \
-	debug_println("%3d " #name, ps.name)
+	if (ps.name != prev_ps.name) \
+	debug_println("%3d ps." #name, ps.name)
 #define debug_ps_keyword(name) \
 	if (ps.name != kw_0) \
-	debug_println("" #name " = %s", kw_name(ps.name))
+	debug_println("ps." #name " = %s", kw_name(ps.name))
 
 static void
 debug_lexi(lexer_symbol lsym)
 {
+/*
+ * Watch out for 'rolled back parser state' in the debug output; the
+ * differences around these are unreliable.
+ */
+static struct parser_state prev_ps;
+
 debug_println("");
 debug_printf("line %d\n", line_no);
 debug_print_buf("label", );
@@ -351,6 +358,8 @@ debug_lexi(lexer_symbol lsym)
 debug_ps_bool(is_case_label);
 
 debug_ps_bool(search_stmt);
+
+prev_ps = ps;
 }
 #endif
 



CVS commit: src/usr.bin/indent

2021-10-29 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Fri Oct 29 21:31:29 UTC 2021

Modified Files:
src/usr.bin/indent: lexi.c

Log Message:
indent: in debug mode, log only differences for most ps members


To generate a diff of this commit:
cvs rdiff -u -r1.112 -r1.113 src/usr.bin/indent/lexi.c

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



CVS commit: src/sys/arch/powerpc/include

2021-10-29 Thread Jason R Thorpe
Module Name:src
Committed By:   thorpej
Date:   Fri Oct 29 21:42:02 UTC 2021

Modified Files:
src/sys/arch/powerpc/include: signal.h

Log Message:
Define __HAVE_STRUCT_SIGCONTEXT regardless of its current visibility.


To generate a diff of this commit:
cvs rdiff -u -r1.25 -r1.26 src/sys/arch/powerpc/include/signal.h

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

Modified files:

Index: src/sys/arch/powerpc/include/signal.h
diff -u src/sys/arch/powerpc/include/signal.h:1.25 src/sys/arch/powerpc/include/signal.h:1.26
--- src/sys/arch/powerpc/include/signal.h:1.25	Wed Oct 27 18:20:08 2021
+++ src/sys/arch/powerpc/include/signal.h	Fri Oct 29 21:42:02 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: signal.h,v 1.25 2021/10/27 18:20:08 christos Exp $	*/
+/*	$NetBSD: signal.h,v 1.26 2021/10/29 21:42:02 thorpej Exp $	*/
 
 /*
  * Copyright (C) 1995, 1996 Wolfgang Solfrank.
@@ -37,6 +37,14 @@
 #ifndef _LOCORE
 #include 
 
+/*
+ * This is needed natively for 32-bit, and for 32-bit compatibility only
+ * in the 64-bit environment.
+ */
+#if !defined(__LP64__) || defined(_KERNEL)
+#define	__HAVE_STRUCT_SIGCONTEXT
+#endif
+
 typedef int sig_atomic_t;
 
 #ifndef __LP64__
@@ -56,7 +64,6 @@ struct sigcontext13 {
 /*
  * struct sigcontext introduced in NetBSD 1.4
  */
-#define	__HAVE_STRUCT_SIGCONTEXT
 struct sigcontext {
 	int sc_onstack;			/* saved onstack flag */
 	int __sc_mask13;		/* saved signal mask (old style) */



CVS commit: src/sys/arch/powerpc/include

2021-10-29 Thread Jason R Thorpe
Module Name:src
Committed By:   thorpej
Date:   Fri Oct 29 21:42:02 UTC 2021

Modified Files:
src/sys/arch/powerpc/include: signal.h

Log Message:
Define __HAVE_STRUCT_SIGCONTEXT regardless of its current visibility.


To generate a diff of this commit:
cvs rdiff -u -r1.25 -r1.26 src/sys/arch/powerpc/include/signal.h

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



CVS commit: src/sys/dev/sbus

2021-10-29 Thread Michael Lorenz
Module Name:src
Committed By:   macallan
Date:   Sat Oct 30 05:37:39 UTC 2021

Modified Files:
src/sys/dev/sbus: mgx.c mgxreg.h

Log Message:
actually mmap() the blitter registers when asked to, while there do some
magic number reduction


To generate a diff of this commit:
cvs rdiff -u -r1.17 -r1.18 src/sys/dev/sbus/mgx.c
cvs rdiff -u -r1.5 -r1.6 src/sys/dev/sbus/mgxreg.h

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

Modified files:

Index: src/sys/dev/sbus/mgx.c
diff -u src/sys/dev/sbus/mgx.c:1.17 src/sys/dev/sbus/mgx.c:1.18
--- src/sys/dev/sbus/mgx.c:1.17	Fri Oct 22 19:21:12 2021
+++ src/sys/dev/sbus/mgx.c	Sat Oct 30 05:37:39 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: mgx.c,v 1.17 2021/10/22 19:21:12 macallan Exp $ */
+/*	$NetBSD: mgx.c,v 1.18 2021/10/30 05:37:39 macallan Exp $ */
 
 /*-
  * Copyright (c) 2014 Michael Lorenz
@@ -29,7 +29,7 @@
 /* a console driver for the SSB 4096V-MGX graphics card */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: mgx.c,v 1.17 2021/10/22 19:21:12 macallan Exp $");
+__KERNEL_RCSID(0, "$NetBSD: mgx.c,v 1.18 2021/10/30 05:37:39 macallan Exp $");
 
 #include 
 #include 
@@ -684,6 +684,8 @@ mgx_putchar_aa(void *cookie, int row, in
 	uint32_t fg, bg;
 	int x, y, wi, he, rv;
 
+if (sc->sc_mode != WSDISPLAYIO_MODE_EMUL) return;
+
 	wi = font->fontwidth;
 	he = font->fontheight;
 
@@ -731,6 +733,8 @@ mgx_putchar_mono(void *cookie, int row, 
 	uint32_t fg, bg, scratch = ((sc->sc_stride * sc->sc_height) + 7) & ~7;
 	int x, y, wi, he, len, i;
 
+if (sc->sc_mode != WSDISPLAYIO_MODE_EMUL) return;
+
 	wi = font->fontwidth;
 	he = font->fontheight;
 
@@ -1120,7 +1124,7 @@ mgx_mmap(void *v, void *vs, off_t offset
 	}
 
 	/*
-	 * Blitter registers at 0x8000, only in mapped mode.
+	 * Blitter registers at 0x0080, only in mapped mode.
 	 * Restrict to root, even though I'm fairly sure the DMA engine lives
 	 * elsewhere ( and isn't documented anyway )
 	 */
@@ -1132,9 +1136,9 @@ mgx_mmap(void *v, void *vs, off_t offset
 		return -1;
 	}
 	if ((sc->sc_mode == WSDISPLAYIO_MODE_MAPPED) &&
-	(offset >= 0x8000) && (offset < 0x80001000)) {
+	(offset >= MGX_BLTOFFSET) && (offset < MGX_BLTOFFSET + 0x1000)) {
 		return bus_space_mmap(sc->sc_tag, sc->sc_rpaddr,
-		offset, prot, BUS_SPACE_MAP_LINEAR);
+		offset - MGX_BLTOFFSET, prot, BUS_SPACE_MAP_LINEAR);
 	}
 	return -1;
 }
@@ -1270,7 +1274,7 @@ mgxmmap(dev_t dev, off_t offset, int pro
 	}
 
 	/*
-	 * Blitter registers at 0x8000, only in mapped mode.
+	 * Blitter registers at 0x0080, only in mapped mode.
 	 * Restrict to root, even though I'm fairly sure the DMA engine lives
 	 * elsewhere ( and isn't documented anyway )
 	 */
@@ -1282,9 +1286,9 @@ mgxmmap(dev_t dev, off_t offset, int pro
 		return -1;
 	}
 	if ((sc->sc_mode == WSDISPLAYIO_MODE_MAPPED) &&
-	(offset >= 0x8000) && (offset < 0x80001000)) {
+	(offset >= MGX_BLTOFFSET) && (offset < MGX_BLTOFFSET + 0x1000)) {
 		return bus_space_mmap(sc->sc_tag, sc->sc_rpaddr,
-		offset, prot, BUS_SPACE_MAP_LINEAR);
+		offset - MGX_BLTOFFSET, prot, BUS_SPACE_MAP_LINEAR);
 	}
 	return -1;
 }

Index: src/sys/dev/sbus/mgxreg.h
diff -u src/sys/dev/sbus/mgxreg.h:1.5 src/sys/dev/sbus/mgxreg.h:1.6
--- src/sys/dev/sbus/mgxreg.h:1.5	Sat Jul 29 03:29:49 2017
+++ src/sys/dev/sbus/mgxreg.h	Sat Oct 30 05:37:39 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: mgxreg.h,v 1.5 2017/07/29 03:29:49 macallan Exp $ */
+/*	$NetBSD: mgxreg.h,v 1.6 2021/10/30 05:37:39 macallan Exp $ */
 
 /* register definitions based on OpenBSD's atxxreg.h: */
 
@@ -30,6 +30,9 @@
 #ifndef MGX_REG_H
 #define MGX_REG_H
 
+#define MGX_FBOFFSET  0x
+#define MGX_BLTOFFSET 0x0080
+
 #define VGA_BASE 0x3c0
 #define CRTC_INDEX	0x3d4
 #define CRTC_DATA	0x3d5



CVS commit: src/sys/dev/sbus

2021-10-29 Thread Michael Lorenz
Module Name:src
Committed By:   macallan
Date:   Sat Oct 30 05:37:39 UTC 2021

Modified Files:
src/sys/dev/sbus: mgx.c mgxreg.h

Log Message:
actually mmap() the blitter registers when asked to, while there do some
magic number reduction


To generate a diff of this commit:
cvs rdiff -u -r1.17 -r1.18 src/sys/dev/sbus/mgx.c
cvs rdiff -u -r1.5 -r1.6 src/sys/dev/sbus/mgxreg.h

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



CVS commit: src/sys/arch/aarch64/aarch64

2021-10-29 Thread Nick Hudson
Module Name:src
Committed By:   skrll
Date:   Fri Oct 29 07:55:04 UTC 2021

Modified Files:
src/sys/arch/aarch64/aarch64: aarch64_tlb.c

Log Message:
Fix length of memset in tlb_record_asids


To generate a diff of this commit:
cvs rdiff -u -r1.1 -r1.2 src/sys/arch/aarch64/aarch64/aarch64_tlb.c

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



CVS commit: src/sys/arch/aarch64/aarch64

2021-10-29 Thread Nick Hudson
Module Name:src
Committed By:   skrll
Date:   Fri Oct 29 07:55:04 UTC 2021

Modified Files:
src/sys/arch/aarch64/aarch64: aarch64_tlb.c

Log Message:
Fix length of memset in tlb_record_asids


To generate a diff of this commit:
cvs rdiff -u -r1.1 -r1.2 src/sys/arch/aarch64/aarch64/aarch64_tlb.c

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

Modified files:

Index: src/sys/arch/aarch64/aarch64/aarch64_tlb.c
diff -u src/sys/arch/aarch64/aarch64/aarch64_tlb.c:1.1 src/sys/arch/aarch64/aarch64/aarch64_tlb.c:1.2
--- src/sys/arch/aarch64/aarch64/aarch64_tlb.c:1.1	Sun Oct 10 07:15:25 2021
+++ src/sys/arch/aarch64/aarch64/aarch64_tlb.c	Fri Oct 29 07:55:04 2021
@@ -31,7 +31,7 @@
 #include "opt_multiprocessor.h"
 
 #include 
-__KERNEL_RCSID(1, "$NetBSD: aarch64_tlb.c,v 1.1 2021/10/10 07:15:25 skrll Exp $");
+__KERNEL_RCSID(1, "$NetBSD: aarch64_tlb.c,v 1.2 2021/10/29 07:55:04 skrll Exp $");
 
 #include 
 #include 
@@ -104,7 +104,7 @@ tlb_record_asids(u_long *mapp, tlb_asid_
 	KASSERT(asid_max == pmap_md_tlb_asid_max());
 
 #if DIAGNOSTIC
-	memset(mapp, 0xff, (asid_max + 1) / (NBBY * sizeof(u_long)));
+	memset(mapp, 0xff, (asid_max + 1) / NBBY);
 	mapp[0] ^= __BITS(0, KERNEL_PID);
 #endif
 	return asid_max;



CVS commit: src/lib/libc/string

2021-10-29 Thread Nia Alarie
Module Name:src
Committed By:   nia
Date:   Fri Oct 29 10:11:57 UTC 2021

Modified Files:
src/lib/libc/string: wcsdup.c

Log Message:
wcsdup(3): use reallocarr to catch integer overflow


To generate a diff of this commit:
cvs rdiff -u -r1.3 -r1.4 src/lib/libc/string/wcsdup.c

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



CVS commit: src/lib/libc/string

2021-10-29 Thread Nia Alarie
Module Name:src
Committed By:   nia
Date:   Fri Oct 29 10:11:57 UTC 2021

Modified Files:
src/lib/libc/string: wcsdup.c

Log Message:
wcsdup(3): use reallocarr to catch integer overflow


To generate a diff of this commit:
cvs rdiff -u -r1.3 -r1.4 src/lib/libc/string/wcsdup.c

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

Modified files:

Index: src/lib/libc/string/wcsdup.c
diff -u src/lib/libc/string/wcsdup.c:1.3 src/lib/libc/string/wcsdup.c:1.4
--- src/lib/libc/string/wcsdup.c:1.3	Mon May 26 13:17:48 2008
+++ src/lib/libc/string/wcsdup.c	Fri Oct 29 10:11:57 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: wcsdup.c,v 1.3 2008/05/26 13:17:48 haad Exp $	*/
+/*	$NetBSD: wcsdup.c,v 1.4 2021/10/29 10:11:57 nia Exp $	*/
 
 /*
  * Copyright (C) 2006 Aleksey Cheusov
@@ -14,7 +14,7 @@
 #include 
 
 #if defined(LIBC_SCCS) && !defined(lint) 
-__RCSID("$NetBSD: wcsdup.c,v 1.3 2008/05/26 13:17:48 haad Exp $"); 
+__RCSID("$NetBSD: wcsdup.c,v 1.4 2021/10/29 10:11:57 nia Exp $"); 
 #endif /* LIBC_SCCS and not lint */ 
 
 #include "namespace.h"
@@ -33,9 +33,9 @@ wcsdup(const wchar_t *str)
 	_DIAGASSERT(str != NULL);
 
 	len = wcslen(str) + 1;
-	copy = malloc(len * sizeof (wchar_t));
 
-	if (!copy)
+	copy = NULL;
+	if (reallocarr(, len, sizeof(wchar_t)) != 0)
 		return NULL;
 
 	return wmemcpy(copy, str, len);



CVS commit: src/share/man/man4

2021-10-29 Thread Nia Alarie
Module Name:src
Committed By:   nia
Date:   Fri Oct 29 10:21:28 UTC 2021

Modified Files:
src/share/man/man4: pci.4 usb.4

Log Message:
Add some missing device drivers to the lists.

>From bobs at thelibertytree.org, thanks!


To generate a diff of this commit:
cvs rdiff -u -r1.120 -r1.121 src/share/man/man4/pci.4
cvs rdiff -u -r1.118 -r1.119 src/share/man/man4/usb.4

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



CVS commit: src/share/man/man4

2021-10-29 Thread Nia Alarie
Module Name:src
Committed By:   nia
Date:   Fri Oct 29 10:21:28 UTC 2021

Modified Files:
src/share/man/man4: pci.4 usb.4

Log Message:
Add some missing device drivers to the lists.

>From bobs at thelibertytree.org, thanks!


To generate a diff of this commit:
cvs rdiff -u -r1.120 -r1.121 src/share/man/man4/pci.4
cvs rdiff -u -r1.118 -r1.119 src/share/man/man4/usb.4

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

Modified files:

Index: src/share/man/man4/pci.4
diff -u src/share/man/man4/pci.4:1.120 src/share/man/man4/pci.4:1.121
--- src/share/man/man4/pci.4:1.120	Sun Aug  1 21:56:27 2021
+++ src/share/man/man4/pci.4	Fri Oct 29 10:21:28 2021
@@ -1,4 +1,4 @@
-.\"	$NetBSD: pci.4,v 1.120 2021/08/01 21:56:27 andvar Exp $
+.\"	$NetBSD: pci.4,v 1.121 2021/10/29 10:21:28 nia Exp $
 .\"
 .\" Copyright (c) 1997 Jason R. Thorpe.  All rights reserved.
 .\" Copyright (c) 1997 Jonathan Stone
@@ -29,7 +29,7 @@
 .\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
 .\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 .\"
-.Dd March 17, 2021
+.Dd October 29, 2021
 .Dt PCI 4
 .Os
 .Sh NAME
@@ -175,6 +175,8 @@ Mylex DAC960 and DEC SWXCR RAID controll
 National Semiconductor PC87415 PCI-IDE controllers.
 .It Xr nvme 4
 Non-Volatile Memory (NVM Express) host controllers.
+.It Xr pdcsata 4
+Promise Serial-ATA disk controllers.
 .It Xr pciide 4
 IDE disk controllers.
 .It Xr rtsx 4

Index: src/share/man/man4/usb.4
diff -u src/share/man/man4/usb.4:1.118 src/share/man/man4/usb.4:1.119
--- src/share/man/man4/usb.4:1.118	Tue Jun 29 10:22:37 2021
+++ src/share/man/man4/usb.4	Fri Oct 29 10:21:28 2021
@@ -1,4 +1,4 @@
-.\" $NetBSD: usb.4,v 1.118 2021/06/29 10:22:37 nia Exp $
+.\" $NetBSD: usb.4,v 1.119 2021/10/29 10:21:28 nia Exp $
 .\"
 .\" Copyright (c) 1999-2014 The NetBSD Foundation, Inc.
 .\" All rights reserved.
@@ -27,7 +27,7 @@
 .\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 .\" POSSIBILITY OF SUCH DAMAGE.
 .\"
-.Dd June 27, 2021
+.Dd October 29, 2021
 .Dt USB 4
 .Os
 .Sh NAME
@@ -109,6 +109,8 @@ MosChip MCS7730/7830/7832 10/100 USB Eth
 Microchip LAN75xx/LAN78xx 10/100/Gigabit USB Ethernet device
 .It Xr udav 4
 Davicom DM9601 10/100 USB Ethernet device
+.It Xr ure 4
+Realtek RTL8152/RTL8153 10/100/Gigabit USB Ethernet device
 .It Xr url 4
 Realtek RTL8150L 10/100 USB Ethernet device
 .It Xr urndis 4