CVS commit: src

2024-03-10 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sun Mar 10 10:15:52 UTC 2024

Modified Files:
src/tests/usr.bin/xlint/lint1: msg_141.c
src/usr.bin/xlint/lint1: tree.c

Log Message:
lint: fix integer overflow in integer overflow check


To generate a diff of this commit:
cvs rdiff -u -r1.11 -r1.12 src/tests/usr.bin/xlint/lint1/msg_141.c
cvs rdiff -u -r1.615 -r1.616 src/usr.bin/xlint/lint1/tree.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/xlint/lint1/msg_141.c
diff -u src/tests/usr.bin/xlint/lint1/msg_141.c:1.11 src/tests/usr.bin/xlint/lint1/msg_141.c:1.12
--- src/tests/usr.bin/xlint/lint1/msg_141.c:1.11	Sun Mar 10 09:58:30 2024
+++ src/tests/usr.bin/xlint/lint1/msg_141.c	Sun Mar 10 10:15:52 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: msg_141.c,v 1.11 2024/03/10 09:58:30 rillig Exp $	*/
+/*	$NetBSD: msg_141.c,v 1.12 2024/03/10 10:15:52 rillig Exp $	*/
 # 3 "msg_141.c"
 
 // Test for message: operator '%s' produces integer overflow [141]
@@ -162,26 +162,26 @@ mult_u32(void)
 void
 mult_s64(void)
 {
-	/* TODO: expect+1: warning: operator '*' produces integer overflow [141] */
-	//s64 = -0x1LL * 0x1LL;	// -0x01
-	/* TODO: expect+1: warning: operator '*' produces integer overflow [141] */
-	//s64 = -3LL * 0x2aabLL;	// -0x8001
-	/* TODO: expect+1: warning: operator '*' produces integer overflow [141] */
-	//s64 = 0x2aabLL * -3LL;	// -0x8001
+	/* expect+1: warning: operator '*' produces integer overflow [141] */
+	s64 = -0x1LL * 0x1LL;	// -0x01
+	/* expect+1: warning: operator '*' produces integer overflow [141] */
+	s64 = -3LL * 0x2aabLL;	// -0x8001
+	/* expect+1: warning: operator '*' produces integer overflow [141] */
+	s64 = 0x2aabLL * -3LL;	// -0x8001
 	s64 = -8LL * +0x1000LL;	// -0x8000
 	s64 = +0x1000LL * -8LL;	// -0x8000
 	s64 = +2LL * +0x3fffLL;	// +0x7ffe
 	s64 = +0x3fffLL * +2LL;	// +0x7ffe
 	s64 = +0x7fffLL * +1LL;	// +0x7fff
 	s64 = +1LL * +0x7fffLL;	// +0x7fff
-	/* TODO: expect+1: warning: operator '*' produces integer overflow [141] */
-	//s64 = +2LL * +0x4000LL;	// +0x8000
-	/* TODO: expect+1: warning: operator '*' produces integer overflow [141] */
-	//s64 = +0x4000LL * +2LL;	// +0x8000
-	/* TODO: expect+1: warning: operator '*' produces integer overflow [141] */
-	//s64 = +0xLL * +0x10001LL;	// +0x
-	/* TODO: expect+1: warning: operator '*' produces integer overflow [141] */
-	//s64 = +0x1LL * +0x1LL;	// +0x01
+	/* expect+1: warning: operator '*' produces integer overflow [141] */
+	s64 = +2LL * +0x4000LL;	// +0x8000
+	/* expect+1: warning: operator '*' produces integer overflow [141] */
+	s64 = +0x4000LL * +2LL;	// +0x8000
+	/* expect+1: warning: operator '*' produces integer overflow [141] */
+	s64 = +0xLL * +0x10001LL;	// +0x
+	/* expect+1: warning: operator '*' produces integer overflow [141] */
+	s64 = +0x1LL * +0x1LL;	// +0x01
 }
 
 void
@@ -249,6 +249,7 @@ mod_s32(void)
 {
 	s32 = -1 % (-0x7fff - 1);
 	s32 = -1 % 0x7fff;
+	/* expect+1: warning: operator '%' produces integer overflow [141] */
 	s32 = (-0x7fff - 1) % -1;
 	s32 = 0x7fff % -1;
 }
@@ -269,9 +270,8 @@ mod_s64(void)
 {
 	s64 = -1LL % (-0x7fffLL - 1LL);
 	s64 = -1LL % 0x7fffLL;
-	// FIXME: endless loop on x86_64 in idivq instruction,
-	//  probably due to SIGFPE handling.
-	//s64 = (-0x7fffLL - 1LL) % -1LL;
+	/* expect+1: warning: operator '%' produces integer overflow [141] */
+	s64 = (-0x7fffLL - 1LL) % -1LL;
 	s64 = 0x7fffLL % -1LL;
 }
 
@@ -334,12 +334,12 @@ plus_u32(void)
 void
 plus_s64(void)
 {
-	/* TODO: expect+1: warning: operator '+' produces integer overflow [141] */
-	// FIXME: s64 = -0x7fffLL + -2LL;
+	/* expect+1: warning: operator '+' produces integer overflow [141] */
+	s64 = -0x7fffLL + -2LL;
 	s64 = -0x7fffLL + -1LL;
 	s64 = 0x7ffeLL + 1LL;
-	/* TODO: expect+1: warning: operator '+' produces integer overflow [141] */
-	// FIXME: s64 = 0x7fffLL + 1LL;
+	/* expect+1: warning: operator '+' produces integer overflow [141] */
+	s64 = 0x7fffLL + 1LL;
 }
 
 void
@@ -390,19 +390,19 @@ minus_u32(void)
 void
 minus_s64(void)
 {
-	/* TODO: expect+1: warning: operator '-' produces integer overflow [141] */
-	// FIXME: s64 = -0x7fffLL - 0x7fffLL;
-	/* TODO: expect+1: warning: operator '-' produces integer overflow [141] 

CVS commit: src

2024-03-10 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sun Mar 10 10:15:52 UTC 2024

Modified Files:
src/tests/usr.bin/xlint/lint1: msg_141.c
src/usr.bin/xlint/lint1: tree.c

Log Message:
lint: fix integer overflow in integer overflow check


To generate a diff of this commit:
cvs rdiff -u -r1.11 -r1.12 src/tests/usr.bin/xlint/lint1/msg_141.c
cvs rdiff -u -r1.615 -r1.616 src/usr.bin/xlint/lint1/tree.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/xlint/lint1

2024-03-10 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sun Mar 10 09:58:30 UTC 2024

Modified Files:
src/tests/usr.bin/xlint/lint1: msg_141.c

Log Message:
tests/lint: test integer overflow when folding constants

The test is still incomplete, yet it has discovered several bugs that
are worth fixing.


To generate a diff of this commit:
cvs rdiff -u -r1.10 -r1.11 src/tests/usr.bin/xlint/lint1/msg_141.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/xlint/lint1/msg_141.c
diff -u src/tests/usr.bin/xlint/lint1/msg_141.c:1.10 src/tests/usr.bin/xlint/lint1/msg_141.c:1.11
--- src/tests/usr.bin/xlint/lint1/msg_141.c:1.10	Thu Jan 11 20:25:04 2024
+++ src/tests/usr.bin/xlint/lint1/msg_141.c	Sun Mar 10 09:58:30 2024
@@ -1,213 +1,583 @@
-/*	$NetBSD: msg_141.c,v 1.10 2024/01/11 20:25:04 rillig Exp $	*/
+/*	$NetBSD: msg_141.c,v 1.11 2024/03/10 09:58:30 rillig Exp $	*/
 # 3 "msg_141.c"
 
 // Test for message: operator '%s' produces integer overflow [141]
 
 /* lint1-extra-flags: -h -X 351 */
 
-/*
- * Before tree.c 1.347 from 2021-08-23, lint wrongly warned about integer
- * overflow in '-'.
- */
-int signed_int_max = (1U << 31) - 1;
+// Integer overflow occurs when the arbitrary-precision result of an
+// arithmetic operation cannot be represented by the type of the expression.
 
-/*
- * Before tree.c 1.347 from 2021-08-23, lint wrongly warned about integer
- * overflow in '-'.
- */
-unsigned int unsigned_int_max = (1U << 31) - 1;
-
-/* expect+1: warning: operator '+' produces integer overflow [141] */
-int int_overflow = (1 << 30) + (1 << 30);
-
-/* expect+2: warning: operator '+' produces integer overflow [141] */
-/* expect+1: warning: initialization of unsigned with negative constant [221] */
-unsigned int intermediate_overflow = (1 << 30) + (1 << 30);
-
-unsigned int no_overflow = (1U << 30) + (1 << 30);
-
-/* expect+1: warning: operator '-' produces integer overflow [141] */
-unsigned int unsigned_int_min = 0U - (1U << 31);
-
-/* expect+1: warning: operator '-' produces integer overflow [141] */
-unsigned int unsigned_int_min_unary = -(1U << 31);
-
-enum {
-	INT_MAX = 2147483647,
-	INT_MIN = -INT_MAX - 1,
-};
-
-unsigned long long overflow_unsigned[] = {
-
-	// unary '+'
-
-	+0U,
-	+~0U,
-	+~0ULL,
-
-	// unary '-'
-
-	-0U,
-	-~0U,
+signed int s32;
+unsigned int u32;
+signed long long s64;
+unsigned long long u64;
+
+void
+compl_s32(void)
+{
+	s32 = ~(-0x7fff - 1);
+	s32 = ~-1;
+	s32 = ~0;
+	s32 = ~1;
+	s32 = ~0x7fff;
+}
+
+void
+compl_u32(void)
+{
+	u32 = ~0xU;
+	u32 = ~0x7fffU;
+	u32 = ~0x8000U;
+	u32 = ~0xU;
+}
+
+void
+compl_s64(void)
+{
+	s64 = ~(-0x7fffLL - 1LL);
+	s64 = ~-1LL;
+	s64 = ~0LL;
+	s64 = ~0x7fffLL;
+}
+
+void
+compl_u64(void)
+{
+	u64 = ~0ULL;
+	u64 = ~0x7fffULL;
+	u64 = ~0x8000ULL;
+	u64 = ~0xULL;
+}
+
+void
+uplus_s32(void)
+{
+	s32 = +(-0x7fff - 1);
+	s32 = +-1;
+	s32 = +0;
+	s32 = +0x7fff;
+}
+
+void
+uplus_u32(void)
+{
+	u32 = +0xU;
+	u32 = +0x7fffU;
+	u32 = +0x8000U;
+	u32 = +0xU;
+}
+
+void
+uplus_s64(void)
+{
+	s64 = +(-0x7fffLL - 1LL);
+	s64 = +-1LL;
+	s64 = +0LL;
+	s64 = +0x7fffLL;
+}
+
+void
+uplus_u64(void)
+{
+	u64 = +0xULL;
+	u64 = +0x7fffULL;
+	u64 = +0x8000ULL;
+	u64 = +0xULL;
+}
+
+void
+uminus_s32(void)
+{
 	/* expect+1: warning: operator '-' produces integer overflow [141] */
-	-(1ULL << 63),
+	s32 = -(-0x7fff - 1);
+	s32 = - -1;
+	s32 = -0;
+	s32 = -0x7fff;
+}
+
+void
+uminus_u32(void)
+{
+	u32 = -0xU;
+	u32 = -0x7fffU;
 	/* expect+1: warning: operator '-' produces integer overflow [141] */
-	-(1U << 31),
-
-	// '~'
+	u32 = -0x8000U;
+	u32 = -0xU;
+}
+
+void
+uminus_s64(void)
+{
+	/* expect+1: warning: operator '-' produces integer overflow [141] */
+	s64 = -(-0x7fffLL - 1LL);
+	s64 = - -1LL;
+	s64 = -0LL;
+	s64 = -0x7fffLL;
+}
+
+void
+uminus_u64(void)
+{
+	u64 = -0xULL;
+	u64 = -0x7fffULL;
+	/* expect+1: warning: operator '-' produces integer overflow [141] */
+	u64 = -0x8000ULL;
+	u64 = -0xULL;
+}
+
+void
+mult_s32(void)
+{
+	/* expect+1: warning: operator '*' produces integer overflow [141] */
+	s32 = -0x0001 * +0x0001;	// -0x01
+	/* expect+1: warning: operator '*' produces integer overflow [141] */
+	s32 = -0x0003 * +0x2aab;	// -0x8001
+	/* expect+1: warning: operator '*' produces integer overflow [141] */
+	s32 = +0x2aab * -0x0003;	// -0x8001
+	s32 = -0x0008 * +0x1000;	// -0x8000
+	s32 = +0x1000 * -0x0008;	// -0x8000
+	s32 = +0x0002 * +0x3fff;	// +0x7ffe
+	s32 = +0x3fff * +0x0002;	// +0x7ffe
+	s32 = +0x7fff * +0x0001;	// +0x7fff
+	s32 = 

CVS commit: src/tests/usr.bin/xlint/lint1

2024-03-10 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sun Mar 10 09:58:30 UTC 2024

Modified Files:
src/tests/usr.bin/xlint/lint1: msg_141.c

Log Message:
tests/lint: test integer overflow when folding constants

The test is still incomplete, yet it has discovered several bugs that
are worth fixing.


To generate a diff of this commit:
cvs rdiff -u -r1.10 -r1.11 src/tests/usr.bin/xlint/lint1/msg_141.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/xlint/lint1

2024-03-10 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sun Mar 10 09:24:54 UTC 2024

Modified Files:
src/usr.bin/xlint/lint1: tree.c

Log Message:
lint: in check for integer overflow, sort operators


To generate a diff of this commit:
cvs rdiff -u -r1.614 -r1.615 src/usr.bin/xlint/lint1/tree.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/xlint/lint1

2024-03-10 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sun Mar 10 09:24:54 UTC 2024

Modified Files:
src/usr.bin/xlint/lint1: tree.c

Log Message:
lint: in check for integer overflow, sort operators


To generate a diff of this commit:
cvs rdiff -u -r1.614 -r1.615 src/usr.bin/xlint/lint1/tree.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/xlint/lint1/tree.c
diff -u src/usr.bin/xlint/lint1/tree.c:1.614 src/usr.bin/xlint/lint1/tree.c:1.615
--- src/usr.bin/xlint/lint1/tree.c:1.614	Sat Mar  9 23:55:11 2024
+++ src/usr.bin/xlint/lint1/tree.c	Sun Mar 10 09:24:54 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: tree.c,v 1.614 2024/03/09 23:55:11 rillig Exp $	*/
+/*	$NetBSD: tree.c,v 1.615 2024/03/10 09:24:54 rillig Exp $	*/
 
 /*
  * Copyright (c) 1994, 1995 Jochen Pohl
@@ -37,7 +37,7 @@
 
 #include 
 #if defined(__RCSID)
-__RCSID("$NetBSD: tree.c,v 1.614 2024/03/09 23:55:11 rillig Exp $");
+__RCSID("$NetBSD: tree.c,v 1.615 2024/03/10 09:24:54 rillig Exp $");
 #endif
 
 #include 
@@ -815,6 +815,9 @@ fold_constant_integer(tnode_t *tn)
 
 	int64_t si;
 	switch (tn->tn_op) {
+	case COMPL:
+		si = ~sl;
+		break;
 	case UPLUS:
 		si = sl;
 		break;
@@ -823,9 +826,6 @@ fold_constant_integer(tnode_t *tn)
 		if (sl != 0 && msb(si, t) == msb(sl, t))
 			ovfl = true;
 		break;
-	case COMPL:
-		si = ~sl;
-		break;
 	case MULT:
 		if (utyp) {
 			si = (int64_t)(ul * ur);
@@ -892,12 +892,12 @@ fold_constant_integer(tnode_t *tn)
 	case LE:
 		si = (utyp ? ul <= ur : sl <= sr) ? 1 : 0;
 		break;
-	case GE:
-		si = (utyp ? ul >= ur : sl >= sr) ? 1 : 0;
-		break;
 	case GT:
 		si = (utyp ? ul > ur : sl > sr) ? 1 : 0;
 		break;
+	case GE:
+		si = (utyp ? ul >= ur : sl >= sr) ? 1 : 0;
+		break;
 	case EQ:
 		si = (utyp ? ul == ur : sl == sr) ? 1 : 0;
 		break;



CVS commit: src

2024-03-09 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sat Mar  9 23:55:11 UTC 2024

Modified Files:
src/tests/usr.bin/xlint/lint1: expr_fold.c
src/usr.bin/xlint/lint1: tree.c

Log Message:
lint: fix excessive overflow warning after division by zero


To generate a diff of this commit:
cvs rdiff -u -r1.11 -r1.12 src/tests/usr.bin/xlint/lint1/expr_fold.c
cvs rdiff -u -r1.613 -r1.614 src/usr.bin/xlint/lint1/tree.c

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



CVS commit: src

2024-03-09 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sat Mar  9 23:55:11 UTC 2024

Modified Files:
src/tests/usr.bin/xlint/lint1: expr_fold.c
src/usr.bin/xlint/lint1: tree.c

Log Message:
lint: fix excessive overflow warning after division by zero


To generate a diff of this commit:
cvs rdiff -u -r1.11 -r1.12 src/tests/usr.bin/xlint/lint1/expr_fold.c
cvs rdiff -u -r1.613 -r1.614 src/usr.bin/xlint/lint1/tree.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/xlint/lint1/expr_fold.c
diff -u src/tests/usr.bin/xlint/lint1/expr_fold.c:1.11 src/tests/usr.bin/xlint/lint1/expr_fold.c:1.12
--- src/tests/usr.bin/xlint/lint1/expr_fold.c:1.11	Sat Jan  6 15:05:24 2024
+++ src/tests/usr.bin/xlint/lint1/expr_fold.c	Sat Mar  9 23:55:11 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: expr_fold.c,v 1.11 2024/01/06 15:05:24 rillig Exp $	*/
+/*	$NetBSD: expr_fold.c,v 1.12 2024/03/09 23:55:11 rillig Exp $	*/
 # 3 "expr_fold.c"
 
 /*
@@ -114,9 +114,7 @@ fold_mult(void)
 void
 fold_div(void)
 {
-	/* expect+3: error: division by 0 [139] */
-	/* XXX: The following message is redundant. */
-	/* expect+1: warning: operator '/' produces integer overflow [141] */
+	/* expect+1: error: division by 0 [139] */
 	take_int(0 / 0);
 
 	/* expect+1: warning: conversion of 'long' to 'int' is out of range, arg #1 [295] */

Index: src/usr.bin/xlint/lint1/tree.c
diff -u src/usr.bin/xlint/lint1/tree.c:1.613 src/usr.bin/xlint/lint1/tree.c:1.614
--- src/usr.bin/xlint/lint1/tree.c:1.613	Sat Mar  9 14:54:14 2024
+++ src/usr.bin/xlint/lint1/tree.c	Sat Mar  9 23:55:11 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: tree.c,v 1.613 2024/03/09 14:54:14 rillig Exp $	*/
+/*	$NetBSD: tree.c,v 1.614 2024/03/09 23:55:11 rillig Exp $	*/
 
 /*
  * Copyright (c) 1994, 1995 Jochen Pohl
@@ -37,7 +37,7 @@
 
 #include 
 #if defined(__RCSID)
-__RCSID("$NetBSD: tree.c,v 1.613 2024/03/09 14:54:14 rillig Exp $");
+__RCSID("$NetBSD: tree.c,v 1.614 2024/03/09 23:55:11 rillig Exp $");
 #endif
 
 #include 
@@ -809,6 +809,8 @@ fold_constant_integer(tnode_t *tn)
 		ur = sr = tn->u.ops.right->u.value.u.integer;
 
 	uint64_t mask = value_bits(size_in_bits(t));
+	int64_t max_value = (int64_t)(mask >> 1);
+	int64_t min_value = -max_value - 1;
 	bool ovfl = false;
 
 	int64_t si;
@@ -841,11 +843,9 @@ fold_constant_integer(tnode_t *tn)
 		if (sr == 0) {
 			/* division by 0 */
 			error(139);
-			si = utyp ? -1 : INT64_MAX;
-		} else if (!utyp
-		&& (sl & mask) == (mask ^ (mask >> 1)) && sr == -1) {
-			/* operator '%s' produces integer overflow */
-			warning(141, op_name(DIV));
+			si = utyp ? -1 : max_value;
+		} else if (!utyp && sl == min_value && sr == -1) {
+			ovfl = true;
 			si = sl;
 		} else
 			si = utyp ? (int64_t)(ul / ur) : sl / sr;



CVS commit: src/tests/usr.bin/xlint/lint1

2024-03-09 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sat Mar  9 17:34:01 UTC 2024

Modified Files:
src/tests/usr.bin/xlint/lint1: platform_ilp32_int.c
platform_ilp32_long.c platform_lp64.c

Log Message:
tests/lint: demonstrate integer overflow on lp64 platforms


To generate a diff of this commit:
cvs rdiff -u -r1.3 -r1.4 src/tests/usr.bin/xlint/lint1/platform_ilp32_int.c
cvs rdiff -u -r1.5 -r1.6 src/tests/usr.bin/xlint/lint1/platform_ilp32_long.c
cvs rdiff -u -r1.8 -r1.9 src/tests/usr.bin/xlint/lint1/platform_lp64.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/xlint/lint1/platform_ilp32_int.c
diff -u src/tests/usr.bin/xlint/lint1/platform_ilp32_int.c:1.3 src/tests/usr.bin/xlint/lint1/platform_ilp32_int.c:1.4
--- src/tests/usr.bin/xlint/lint1/platform_ilp32_int.c:1.3	Sat Mar  9 16:47:09 2024
+++ src/tests/usr.bin/xlint/lint1/platform_ilp32_int.c	Sat Mar  9 17:34:01 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: platform_ilp32_int.c,v 1.3 2024/03/09 16:47:09 rillig Exp $	*/
+/*	$NetBSD: platform_ilp32_int.c,v 1.4 2024/03/09 17:34:01 rillig Exp $	*/
 # 3 "platform_ilp32_int.c"
 
 /*
@@ -28,24 +28,75 @@ convert_between_int_and_long(void)
 	ul32 = u32;
 }
 
-char ch;
+unsigned char u8;
+unsigned long long u64;
+unsigned char u8_buf[20];
+unsigned long long u64_buf[20];
 
 void
 array_index(void)
 {
-	static char buf[20];
 
+	/* expect+1: warning: array subscript cannot be > 19: 16777215 [168] */
+	u8 += u8_buf[0x00ff];
 	/* expect+1: warning: array subscript cannot be > 19: 2147483647 [168] */
-	ch += buf[2147483647];
+	u8 += u8_buf[0x7fff];
 	/* expect+2: warning: conversion of 'long long' to 'int' is out of range [119] */
 	/* expect+1: warning: array subscript cannot be negative: -2147483648 [167] */
-	ch += buf[2147483648];
+	u8 += u8_buf[2147483648];
 	/* expect+2: warning: conversion of 'unsigned int' to 'int' is out of range [119] */
 	/* expect+1: warning: array subscript cannot be negative: -2147483648 [167] */
-	ch += buf[0x8000];
+	u8 += u8_buf[0x8000];
 	/* expect+2: warning: conversion of 'unsigned int' to 'int' is out of range [119] */
 	/* expect+1: warning: array subscript cannot be negative: -1 [167] */
-	ch += buf[0x];
+	u8 += u8_buf[0x];
+	/* expect+2: warning: conversion of 'unsigned int' to 'int' is out of range [119] */
+	/* expect+1: warning: array subscript cannot be negative: -2147483648 [167] */
+	u8 += u8_buf[0x8000];
+	/* expect+2: warning: conversion of 'unsigned int' to 'int' is out of range [119] */
+	/* expect+1: warning: array subscript cannot be negative: -1 [167] */
+	u8 += u8_buf[0x];
+	/* expect+2: warning: conversion of 'long long' to 'int' is out of range [119] */
+	/* expect+1: warning: array subscript cannot be negative: -1 [167] */
+	u8 += u8_buf[0x00ff];
+	/* expect+1: warning: array subscript cannot be negative: -1 [167] */
+	u8 += u8_buf[0x];
+
+	/* expect+1: warning: array subscript cannot be > 19: 16777215 [168] */
+	u64 += u64_buf[0x00ff];
+	/* expect+2: warning: operator '*' produces integer overflow [141] */
+	/* expect+1: warning: array subscript cannot be negative: -1 [167] */
+	u64 += u64_buf[0x7fff];
+	/* expect+2: warning: conversion of 'long long' to 'int' is out of range [119] */
+	/* expect+1: warning: operator '*' produces integer overflow [141] */
+	u64 += u64_buf[2147483648];
+	/* expect+2: warning: conversion of 'unsigned int' to 'int' is out of range [119] */
+	/* expect+1: warning: operator '*' produces integer overflow [141] */
+	u64 += u64_buf[0x8000];
+	/* expect+2: warning: conversion of 'unsigned int' to 'int' is out of range [119] */
+	/* expect+1: warning: array subscript cannot be negative: -1 [167] */
+	u64 += u64_buf[0x];
+	/* expect+2: warning: conversion of 'unsigned int' to 'int' is out of range [119] */
+	/* expect+1: warning: operator '*' produces integer overflow [141] */
+	u64 += u64_buf[0x8000];
+	/* expect+2: warning: conversion of 'unsigned int' to 'int' is out of range [119] */
+	/* expect+1: warning: array subscript cannot be negative: -1 [167] */
+	u64 += u64_buf[0x];
+	/* expect+2: warning: conversion of 'long long' to 'int' is out of range [119] */
+	/* expect+1: warning: array subscript cannot be negative: -1 [167] */
+	u64 += u64_buf[0x00ff];
+	/* expect+2: warning: conversion of 'long long' to 'int' is out of range [119] */
+	/* expect+1: warning: array subscript cannot be negative: -1 [167] */
+	u64 += u64_buf[0x0fff];
+	/* expect+2: warning: conversion of 'long long' to 'int' is out of range [119] */
+	/* expect+1: warning: array subscript cannot be negative: -1 [167] */
+	u64 += u64_buf[0x1fff];
+	/* expect+2: warning: conversion of 'long long' to 'int' is out of range [119] */
+	/* expect+1: warning: array subscript cannot be negative: -1 [167] */
+	u64 += 

CVS commit: src/tests/usr.bin/xlint/lint1

2024-03-09 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sat Mar  9 17:34:01 UTC 2024

Modified Files:
src/tests/usr.bin/xlint/lint1: platform_ilp32_int.c
platform_ilp32_long.c platform_lp64.c

Log Message:
tests/lint: demonstrate integer overflow on lp64 platforms


To generate a diff of this commit:
cvs rdiff -u -r1.3 -r1.4 src/tests/usr.bin/xlint/lint1/platform_ilp32_int.c
cvs rdiff -u -r1.5 -r1.6 src/tests/usr.bin/xlint/lint1/platform_ilp32_long.c
cvs rdiff -u -r1.8 -r1.9 src/tests/usr.bin/xlint/lint1/platform_lp64.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/xlint/lint1

2024-03-09 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sat Mar  9 16:47:10 UTC 2024

Modified Files:
src/tests/usr.bin/xlint/lint1: platform_ilp32_int.c
platform_ilp32_long.c platform_lp64.c

Log Message:
tests/lint: test check for out-of-bounds array index


To generate a diff of this commit:
cvs rdiff -u -r1.2 -r1.3 src/tests/usr.bin/xlint/lint1/platform_ilp32_int.c
cvs rdiff -u -r1.4 -r1.5 src/tests/usr.bin/xlint/lint1/platform_ilp32_long.c
cvs rdiff -u -r1.7 -r1.8 src/tests/usr.bin/xlint/lint1/platform_lp64.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/xlint/lint1/platform_ilp32_int.c
diff -u src/tests/usr.bin/xlint/lint1/platform_ilp32_int.c:1.2 src/tests/usr.bin/xlint/lint1/platform_ilp32_int.c:1.3
--- src/tests/usr.bin/xlint/lint1/platform_ilp32_int.c:1.2	Tue Mar 28 14:44:35 2023
+++ src/tests/usr.bin/xlint/lint1/platform_ilp32_int.c	Sat Mar  9 16:47:09 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: platform_ilp32_int.c,v 1.2 2023/03/28 14:44:35 rillig Exp $	*/
+/*	$NetBSD: platform_ilp32_int.c,v 1.3 2024/03/09 16:47:09 rillig Exp $	*/
 # 3 "platform_ilp32_int.c"
 
 /*
@@ -27,3 +27,25 @@ convert_between_int_and_long(void)
 	u32 = ul32;
 	ul32 = u32;
 }
+
+char ch;
+
+void
+array_index(void)
+{
+	static char buf[20];
+
+	/* expect+1: warning: array subscript cannot be > 19: 2147483647 [168] */
+	ch += buf[2147483647];
+	/* expect+2: warning: conversion of 'long long' to 'int' is out of range [119] */
+	/* expect+1: warning: array subscript cannot be negative: -2147483648 [167] */
+	ch += buf[2147483648];
+	/* expect+2: warning: conversion of 'unsigned int' to 'int' is out of range [119] */
+	/* expect+1: warning: array subscript cannot be negative: -2147483648 [167] */
+	ch += buf[0x8000];
+	/* expect+2: warning: conversion of 'unsigned int' to 'int' is out of range [119] */
+	/* expect+1: warning: array subscript cannot be negative: -1 [167] */
+	ch += buf[0x];
+	/* expect+1: warning: array subscript cannot be negative: -1 [167] */
+	ch += buf[0x];
+}

Index: src/tests/usr.bin/xlint/lint1/platform_ilp32_long.c
diff -u src/tests/usr.bin/xlint/lint1/platform_ilp32_long.c:1.4 src/tests/usr.bin/xlint/lint1/platform_ilp32_long.c:1.5
--- src/tests/usr.bin/xlint/lint1/platform_ilp32_long.c:1.4	Sat Jul  8 15:26:25 2023
+++ src/tests/usr.bin/xlint/lint1/platform_ilp32_long.c	Sat Mar  9 16:47:09 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: platform_ilp32_long.c,v 1.4 2023/07/08 15:26:25 rillig Exp $	*/
+/*	$NetBSD: platform_ilp32_long.c,v 1.5 2024/03/09 16:47:09 rillig Exp $	*/
 # 3 "platform_ilp32_long.c"
 
 /*
@@ -36,3 +36,25 @@ convert_between_int_and_long(void)
 	u32 = ul32;
 	ul32 = u32;
 }
+
+char ch;
+
+void
+array_index(void)
+{
+	static char buf[20];
+
+	/* expect+1: warning: array subscript cannot be > 19: 2147483647 [168] */
+	ch += buf[2147483647];
+	/* expect+2: warning: conversion of 'long long' to 'long' is out of range [119] */
+	/* expect+1: warning: array subscript cannot be negative: -2147483648 [167] */
+	ch += buf[2147483648];
+	/* expect+2: warning: conversion of 'unsigned int' to 'long' is out of range [119] */
+	/* expect+1: warning: array subscript cannot be negative: -2147483648 [167] */
+	ch += buf[0x8000];
+	/* expect+2: warning: conversion of 'unsigned int' to 'long' is out of range [119] */
+	/* expect+1: warning: array subscript cannot be negative: -1 [167] */
+	ch += buf[0x];
+	/* expect+1: warning: array subscript cannot be negative: -1 [167] */
+	ch += buf[0x];
+}

Index: src/tests/usr.bin/xlint/lint1/platform_lp64.c
diff -u src/tests/usr.bin/xlint/lint1/platform_lp64.c:1.7 src/tests/usr.bin/xlint/lint1/platform_lp64.c:1.8
--- src/tests/usr.bin/xlint/lint1/platform_lp64.c:1.7	Sat Jul  8 12:45:43 2023
+++ src/tests/usr.bin/xlint/lint1/platform_lp64.c	Sat Mar  9 16:47:09 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: platform_lp64.c,v 1.7 2023/07/08 12:45:43 rillig Exp $	*/
+/*	$NetBSD: platform_lp64.c,v 1.8 2024/03/09 16:47:09 rillig Exp $	*/
 # 3 "platform_lp64.c"
 
 /*
@@ -44,3 +44,22 @@ convert_128(void)
 	/* expect+1: warning: conversion from '__uint128_t' to 'unsigned int' may lose accuracy [132] */
 	u32 = u128;
 }
+
+char ch;
+
+void
+array_index(void)
+{
+	static char buf[20];
+
+	/* expect+1: warning: array subscript cannot be > 19: 2147483647 [168] */
+	ch += buf[2147483647];
+	/* expect+1: warning: array subscript cannot be > 19: 2147483648 [168] */
+	ch += buf[2147483648];
+	/* expect+1: warning: array subscript cannot be > 19: 2147483648 [168] */
+	ch += buf[0x8000];
+	/* expect+1: warning: array subscript cannot be > 19: 4294967295 [168] */
+	ch += buf[0x];
+	/* expect+1: warning: array subscript cannot be negative: -1 [167] */
+	ch += buf[0x];
+}



CVS commit: src/tests/usr.bin/xlint/lint1

2024-03-09 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sat Mar  9 16:47:10 UTC 2024

Modified Files:
src/tests/usr.bin/xlint/lint1: platform_ilp32_int.c
platform_ilp32_long.c platform_lp64.c

Log Message:
tests/lint: test check for out-of-bounds array index


To generate a diff of this commit:
cvs rdiff -u -r1.2 -r1.3 src/tests/usr.bin/xlint/lint1/platform_ilp32_int.c
cvs rdiff -u -r1.4 -r1.5 src/tests/usr.bin/xlint/lint1/platform_ilp32_long.c
cvs rdiff -u -r1.7 -r1.8 src/tests/usr.bin/xlint/lint1/platform_lp64.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/xlint/lint1

2024-03-09 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sat Mar  9 14:54:14 UTC 2024

Modified Files:
src/usr.bin/xlint/lint1: tree.c

Log Message:
lint: merge duplicate code for checking array index


To generate a diff of this commit:
cvs rdiff -u -r1.612 -r1.613 src/usr.bin/xlint/lint1/tree.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/xlint/lint1/tree.c
diff -u src/usr.bin/xlint/lint1/tree.c:1.612 src/usr.bin/xlint/lint1/tree.c:1.613
--- src/usr.bin/xlint/lint1/tree.c:1.612	Sat Mar  9 13:54:47 2024
+++ src/usr.bin/xlint/lint1/tree.c	Sat Mar  9 14:54:14 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: tree.c,v 1.612 2024/03/09 13:54:47 rillig Exp $	*/
+/*	$NetBSD: tree.c,v 1.613 2024/03/09 14:54:14 rillig Exp $	*/
 
 /*
  * Copyright (c) 1994, 1995 Jochen Pohl
@@ -37,7 +37,7 @@
 
 #include 
 #if defined(__RCSID)
-__RCSID("$NetBSD: tree.c,v 1.612 2024/03/09 13:54:47 rillig Exp $");
+__RCSID("$NetBSD: tree.c,v 1.613 2024/03/09 14:54:14 rillig Exp $");
 #endif
 
 #include 
@@ -4327,52 +4327,37 @@ expr(tnode_t *tn, bool vctx, bool cond, 
 		expr_free_all();
 }
 
-/*
- * Checks the range of array indices, if possible.
- * amper is set if only the address of the element is used. This
- * means that the index is allowed to refer to the first element
- * after the array.
- */
+/* If the expression has the form '*(arr + idx)', check the array index. */
 static void
-check_array_index(tnode_t *tn, bool amper)
+check_array_index(const tnode_t *indir, bool taking_address)
 {
-	lint_assert(has_operands(tn));
-	const tnode_t *ln = tn->u.ops.left;
-	const tnode_t *rn = tn->u.ops.right;
-
-	/* We can only check constant indices. */
-	if (rn->tn_op != CON)
-		return;
-
-	/* Return if the left node does not stem from an array. */
-	if (ln->tn_op != ADDR)
-		return;
-	if (ln->u.ops.left->tn_op != STRING && ln->u.ops.left->tn_op != NAME)
-		return;
-	if (ln->u.ops.left->tn_type->t_tspec != ARRAY)
-		return;
+	const tnode_t *plus, *arr, *idx;
 
-	/*
-	 * For incomplete array types, we can print a warning only if the index
-	 * is negative.
-	 */
-	if (is_incomplete(ln->u.ops.left->tn_type)
-	&& rn->u.value.u.integer >= 0)
-		return;
+	if (indir->tn_op == INDIR
+	&& (plus = indir->u.ops.left, plus->tn_op == PLUS)
+	&& plus->u.ops.left->tn_op == ADDR
+	&& (arr = plus->u.ops.left->u.ops.left, true)
+	&& (arr->tn_op == STRING || arr->tn_op == NAME)
+	&& arr->tn_type->t_tspec == ARRAY
+	&& (idx = plus->u.ops.right, idx->tn_op == CON)
+	&& (!is_incomplete(arr->tn_type) || idx->u.value.u.integer < 0))
+		goto proceed;
+	return;
 
-	int elsz = length_in_bits(ln->tn_type->t_subt, NULL);
+proceed:;
+	int elsz = length_in_bits(arr->tn_type->t_subt, NULL);
 	if (elsz == 0)
 		return;
 	elsz /= CHAR_SIZE;
 
 	/* Change the unit of the index from bytes to element size. */
-	int64_t con = is_uinteger(rn->tn_type->t_tspec)
-	? (int64_t)((uint64_t)rn->u.value.u.integer / elsz)
-	: rn->u.value.u.integer / elsz;
+	int64_t con = is_uinteger(idx->tn_type->t_tspec)
+	? (int64_t)((uint64_t)idx->u.value.u.integer / elsz)
+	: idx->u.value.u.integer / elsz;
 
-	int dim = ln->u.ops.left->tn_type->u.dimension + (amper ? 1 : 0);
+	int dim = arr->tn_type->u.dimension + (taking_address ? 1 : 0);
 
-	if (!is_uinteger(rn->tn_type->t_tspec) && con < 0)
+	if (!is_uinteger(idx->tn_type->t_tspec) && con < 0)
 		/* array subscript cannot be negative: %ld */
 		warning(167, (long)con);
 	else if (dim > 0 && (uint64_t)con >= (uint64_t)dim)
@@ -4389,15 +4374,7 @@ check_expr_addr(const tnode_t *ln, bool 
 			mark_as_set(ln->u.sym);
 		mark_as_used(ln->u.sym, fcall, szof);
 	}
-	if (ln->tn_op == INDIR && ln->u.ops.left->tn_op == PLUS)
-		check_array_index(ln->u.ops.left, true);
-}
-
-static void
-check_expr_load(const tnode_t *ln)
-{
-	if (ln->tn_op == INDIR && ln->u.ops.left->tn_op == PLUS)
-		check_array_index(ln->u.ops.left, false);
+	check_array_index(ln, true);
 }
 
 /*
@@ -4439,9 +4416,7 @@ check_expr_assign(const tnode_t *ln, boo
 		if (ln->u.sym->s_scl == EXTERN)
 			outusg(ln->u.sym);
 	}
-	if (ln->tn_op == INDIR && ln->u.ops.left->tn_op == PLUS)
-		/* check the range of array indices */
-		check_array_index(ln->u.ops.left, false);
+	check_array_index(ln, false);
 }
 
 static void
@@ -4463,7 +4438,7 @@ check_expr_op(op_t op, const tnode_t *ln
 		check_expr_addr(ln, szof, fcall);
 		break;
 	case LOAD:
-		check_expr_load(ln);
+		check_array_index(ln, false);
 		/* FALLTHROUGH */
 	case INCBEF:
 	case DECBEF:



CVS commit: src/usr.bin/xlint/lint1

2024-03-09 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sat Mar  9 14:54:14 UTC 2024

Modified Files:
src/usr.bin/xlint/lint1: tree.c

Log Message:
lint: merge duplicate code for checking array index


To generate a diff of this commit:
cvs rdiff -u -r1.612 -r1.613 src/usr.bin/xlint/lint1/tree.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/xlint/lint1

2024-03-09 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sat Mar  9 13:54:47 UTC 2024

Modified Files:
src/usr.bin/xlint/lint1: README.md cgram.y ckbool.c ckctype.c
ckgetopt.c cksnprintb.c debug.c emit1.c func.c init.c lint1.h
tree.c

Log Message:
lint: inline accessor macros for tnode_t


To generate a diff of this commit:
cvs rdiff -u -r1.15 -r1.16 src/usr.bin/xlint/lint1/README.md
cvs rdiff -u -r1.490 -r1.491 src/usr.bin/xlint/lint1/cgram.y
cvs rdiff -u -r1.29 -r1.30 src/usr.bin/xlint/lint1/ckbool.c
cvs rdiff -u -r1.10 -r1.11 src/usr.bin/xlint/lint1/ckctype.c
cvs rdiff -u -r1.25 -r1.26 src/usr.bin/xlint/lint1/ckgetopt.c
cvs rdiff -u -r1.8 -r1.9 src/usr.bin/xlint/lint1/cksnprintb.c
cvs rdiff -u -r1.72 -r1.73 src/usr.bin/xlint/lint1/debug.c
cvs rdiff -u -r1.91 -r1.92 src/usr.bin/xlint/lint1/emit1.c
cvs rdiff -u -r1.183 -r1.184 src/usr.bin/xlint/lint1/func.c
cvs rdiff -u -r1.262 -r1.263 src/usr.bin/xlint/lint1/init.c
cvs rdiff -u -r1.220 -r1.221 src/usr.bin/xlint/lint1/lint1.h
cvs rdiff -u -r1.611 -r1.612 src/usr.bin/xlint/lint1/tree.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/xlint/lint1

2024-03-09 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sat Mar  9 13:54:47 UTC 2024

Modified Files:
src/usr.bin/xlint/lint1: README.md cgram.y ckbool.c ckctype.c
ckgetopt.c cksnprintb.c debug.c emit1.c func.c init.c lint1.h
tree.c

Log Message:
lint: inline accessor macros for tnode_t


To generate a diff of this commit:
cvs rdiff -u -r1.15 -r1.16 src/usr.bin/xlint/lint1/README.md
cvs rdiff -u -r1.490 -r1.491 src/usr.bin/xlint/lint1/cgram.y
cvs rdiff -u -r1.29 -r1.30 src/usr.bin/xlint/lint1/ckbool.c
cvs rdiff -u -r1.10 -r1.11 src/usr.bin/xlint/lint1/ckctype.c
cvs rdiff -u -r1.25 -r1.26 src/usr.bin/xlint/lint1/ckgetopt.c
cvs rdiff -u -r1.8 -r1.9 src/usr.bin/xlint/lint1/cksnprintb.c
cvs rdiff -u -r1.72 -r1.73 src/usr.bin/xlint/lint1/debug.c
cvs rdiff -u -r1.91 -r1.92 src/usr.bin/xlint/lint1/emit1.c
cvs rdiff -u -r1.183 -r1.184 src/usr.bin/xlint/lint1/func.c
cvs rdiff -u -r1.262 -r1.263 src/usr.bin/xlint/lint1/init.c
cvs rdiff -u -r1.220 -r1.221 src/usr.bin/xlint/lint1/lint1.h
cvs rdiff -u -r1.611 -r1.612 src/usr.bin/xlint/lint1/tree.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/xlint/lint1/README.md
diff -u src/usr.bin/xlint/lint1/README.md:1.15 src/usr.bin/xlint/lint1/README.md:1.16
--- src/usr.bin/xlint/lint1/README.md:1.15	Mon Feb  5 23:11:22 2024
+++ src/usr.bin/xlint/lint1/README.md	Sat Mar  9 13:54:47 2024
@@ -1,4 +1,4 @@
-[//]: # ($NetBSD: README.md,v 1.15 2024/02/05 23:11:22 rillig Exp $)
+[//]: # ($NetBSD: README.md,v 1.16 2024/03/09 13:54:47 rillig Exp $)
 
 # Introduction
 
@@ -108,15 +108,15 @@ Each node has an operator that defines w
 The operators and their properties are defined in `oper.c`.
 Some examples for operators:
 
-| Operator | Meaning|
-|--||
-| CON  | compile-time constant in `tn_val`  |
-| NAME | references the identifier in `tn_sym`  |
-| UPLUS| the unary operator `+tn_left`  |
-| PLUS | the binary operator `tn_left + tn_right`   |
-| CALL | a direct function call |
-| ICALL| an indirect function call  |
-| CVT  | an implicit conversion or an explicit cast |
+| Operator | Meaning|
+|--||
+| CON  | compile-time constant in `u.value` |
+| NAME | references the identifier in `u.sym`   |
+| UPLUS| the unary operator `+u.ops.left`   |
+| PLUS | the binary operator `u.ops.left + u.ops.right` |
+| CALL | a direct function call |
+| ICALL| an indirect function call  |
+| CVT  | an implicit conversion or an explicit cast |
 
 As an example, the expression `strcmp(names[i], "name")` has this internal
 structure:

Index: src/usr.bin/xlint/lint1/cgram.y
diff -u src/usr.bin/xlint/lint1/cgram.y:1.490 src/usr.bin/xlint/lint1/cgram.y:1.491
--- src/usr.bin/xlint/lint1/cgram.y:1.490	Sat Mar  9 10:41:11 2024
+++ src/usr.bin/xlint/lint1/cgram.y	Sat Mar  9 13:54:47 2024
@@ -1,5 +1,5 @@
 %{
-/* $NetBSD: cgram.y,v 1.490 2024/03/09 10:41:11 rillig Exp $ */
+/* $NetBSD: cgram.y,v 1.491 2024/03/09 13:54:47 rillig Exp $ */
 
 /*
  * Copyright (c) 1996 Christopher G. Demetriou.  All Rights Reserved.
@@ -35,7 +35,7 @@
 
 #include 
 #if defined(__RCSID)
-__RCSID("$NetBSD: cgram.y,v 1.490 2024/03/09 10:41:11 rillig Exp $");
+__RCSID("$NetBSD: cgram.y,v 1.491 2024/03/09 13:54:47 rillig Exp $");
 #endif
 
 #include 
@@ -625,7 +625,7 @@ gcc_statement_expr_item:
 		} else {
 			/* XXX: do that only on the last name */
 			if ($1->tn_op == NAME)
-$1->tn_sym->s_used = true;
+$1->u.sym->s_used = true;
 			expr($1, false, false, false, false);
 			suppress_fallthrough = false;
 			$$ = $1;

Index: src/usr.bin/xlint/lint1/ckbool.c
diff -u src/usr.bin/xlint/lint1/ckbool.c:1.29 src/usr.bin/xlint/lint1/ckbool.c:1.30
--- src/usr.bin/xlint/lint1/ckbool.c:1.29	Sat Feb  3 12:57:12 2024
+++ src/usr.bin/xlint/lint1/ckbool.c	Sat Mar  9 13:54:47 2024
@@ -1,4 +1,4 @@
-/* $NetBSD: ckbool.c,v 1.29 2024/02/03 12:57:12 rillig Exp $ */
+/* $NetBSD: ckbool.c,v 1.30 2024/03/09 13:54:47 rillig Exp $ */
 
 /*-
  * Copyright (c) 2021 The NetBSD Foundation, Inc.
@@ -36,7 +36,7 @@
 #include 
 
 #if defined(__RCSID)
-__RCSID("$NetBSD: ckbool.c,v 1.29 2024/02/03 12:57:12 rillig Exp $");
+__RCSID("$NetBSD: ckbool.c,v 1.30 2024/03/09 13:54:47 rillig Exp $");
 #endif
 
 #include 
@@ -73,7 +73,7 @@ is_symmetric_bool_or_other(op_t op)
 static bool
 is_int_constant_zero(const tnode_t *tn, tspec_t t)
 {
-	return t == INT && tn->tn_op == CON && tn->tn_val.u.integer == 0;
+	return t == INT && tn->tn_op == CON && tn->u.value.u.integer == 0;
 }
 
 static bool
@@ -201,7 +201,7 @@ bool
 is_typeok_bool_compares_with_zero(const tnode_t 

CVS commit: src/usr.bin/xlint

2024-03-09 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sat Mar  9 13:20:55 UTC 2024

Modified Files:
src/usr.bin/xlint/common: tyname.c
src/usr.bin/xlint/lint1: debug.c decl.c emit1.c func.c init.c lint1.h
tree.c

Log Message:
lint: inline accessor macros for type_t


To generate a diff of this commit:
cvs rdiff -u -r1.61 -r1.62 src/usr.bin/xlint/common/tyname.c
cvs rdiff -u -r1.71 -r1.72 src/usr.bin/xlint/lint1/debug.c
cvs rdiff -u -r1.395 -r1.396 src/usr.bin/xlint/lint1/decl.c
cvs rdiff -u -r1.90 -r1.91 src/usr.bin/xlint/lint1/emit1.c
cvs rdiff -u -r1.182 -r1.183 src/usr.bin/xlint/lint1/func.c
cvs rdiff -u -r1.261 -r1.262 src/usr.bin/xlint/lint1/init.c
cvs rdiff -u -r1.219 -r1.220 src/usr.bin/xlint/lint1/lint1.h
cvs rdiff -u -r1.610 -r1.611 src/usr.bin/xlint/lint1/tree.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/xlint/common/tyname.c
diff -u src/usr.bin/xlint/common/tyname.c:1.61 src/usr.bin/xlint/common/tyname.c:1.62
--- src/usr.bin/xlint/common/tyname.c:1.61	Fri Feb  2 16:25:58 2024
+++ src/usr.bin/xlint/common/tyname.c	Sat Mar  9 13:20:55 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: tyname.c,v 1.61 2024/02/02 16:25:58 rillig Exp $	*/
+/*	$NetBSD: tyname.c,v 1.62 2024/03/09 13:20:55 rillig Exp $	*/
 
 /*-
  * Copyright (c) 2005 The NetBSD Foundation, Inc.
@@ -35,7 +35,7 @@
 
 #include 
 #if defined(__RCSID)
-__RCSID("$NetBSD: tyname.c,v 1.61 2024/02/02 16:25:58 rillig Exp $");
+__RCSID("$NetBSD: tyname.c,v 1.62 2024/03/09 13:20:55 rillig Exp $");
 #endif
 
 #include 
@@ -165,7 +165,7 @@ type_name_of_function(buffer *buf, const
 	buf_add(buf, "(");
 	if (tp->t_proto) {
 #if IS_LINT1
-		const sym_t *param = tp->t_params;
+		const sym_t *param = tp->u.params;
 		if (param == NULL)
 			buf_add(buf, "void");
 		for (; param != NULL; param = param->s_next) {
@@ -197,12 +197,12 @@ type_name_of_struct_or_union(buffer *buf
 {
 	buf_add(buf, " ");
 #if IS_LINT1
-	if (tp->t_sou->sou_tag->s_name == unnamed &&
-	tp->t_sou->sou_first_typedef != NULL) {
+	if (tp->u.sou->sou_tag->s_name == unnamed &&
+	tp->u.sou->sou_first_typedef != NULL) {
 		buf_add(buf, "typedef ");
-		buf_add(buf, tp->t_sou->sou_first_typedef->s_name);
+		buf_add(buf, tp->u.sou->sou_first_typedef->s_name);
 	} else {
-		buf_add(buf, tp->t_sou->sou_tag->s_name);
+		buf_add(buf, tp->u.sou->sou_tag->s_name);
 	}
 #else
 	buf_add(buf, tp->t_isuniqpos ? "*anonymous*" : tp->t_tag->h_name);
@@ -214,12 +214,12 @@ type_name_of_enum(buffer *buf, const typ
 {
 	buf_add(buf, " ");
 #if IS_LINT1
-	if (tp->t_enum->en_tag->s_name == unnamed &&
-	tp->t_enum->en_first_typedef != NULL) {
+	if (tp->u.enumer->en_tag->s_name == unnamed &&
+	tp->u.enumer->en_first_typedef != NULL) {
 		buf_add(buf, "typedef ");
-		buf_add(buf, tp->t_enum->en_first_typedef->s_name);
+		buf_add(buf, tp->u.enumer->en_first_typedef->s_name);
 	} else {
-		buf_add(buf, tp->t_enum->en_tag->s_name);
+		buf_add(buf, tp->u.enumer->en_tag->s_name);
 	}
 #else
 	buf_add(buf, tp->t_isuniqpos ? "*anonymous*" : tp->t_tag->h_name);
@@ -234,7 +234,7 @@ type_name_of_array(buffer *buf, const ty
 	if (tp->t_incomplete_array)
 		buf_add(buf, "unknown_size");
 	else
-		buf_add_int(buf, tp->t_dim);
+		buf_add_int(buf, tp->u.dimension);
 #else
 	buf_add_int(buf, tp->t_dim);
 #endif
@@ -263,7 +263,7 @@ type_name(const type_t *tp)
 		buf_add(, "volatile ");
 
 #if IS_LINT1
-	if (is_struct_or_union(t) && tp->t_sou->sou_incomplete)
+	if (is_struct_or_union(t) && tp->u.sou->sou_incomplete)
 		buf_add(, "incomplete ");
 #endif
 	buf_add(, tspec_name(t));

Index: src/usr.bin/xlint/lint1/debug.c
diff -u src/usr.bin/xlint/lint1/debug.c:1.71 src/usr.bin/xlint/lint1/debug.c:1.72
--- src/usr.bin/xlint/lint1/debug.c:1.71	Mon Feb  5 23:11:22 2024
+++ src/usr.bin/xlint/lint1/debug.c	Sat Mar  9 13:20:55 2024
@@ -1,4 +1,4 @@
-/* $NetBSD: debug.c,v 1.71 2024/02/05 23:11:22 rillig Exp $ */
+/* $NetBSD: debug.c,v 1.72 2024/03/09 13:20:55 rillig Exp $ */
 
 /*-
  * Copyright (c) 2021 The NetBSD Foundation, Inc.
@@ -35,7 +35,7 @@
 
 #include 
 #if defined(__RCSID)
-__RCSID("$NetBSD: debug.c,v 1.71 2024/02/05 23:11:22 rillig Exp $");
+__RCSID("$NetBSD: debug.c,v 1.72 2024/03/09 13:20:55 rillig Exp $");
 #endif
 
 #include 
@@ -156,10 +156,10 @@ debug_type_details(const type_t *tp)
 	if (is_struct_or_union(tp->t_tspec)) {
 		debug_indent_inc();
 		debug_step("size %u bits, align %u bits, %s",
-		tp->t_sou->sou_size_in_bits, tp->t_sou->sou_align_in_bits,
-		tp->t_sou->sou_incomplete ? "incomplete" : "complete");
+		tp->u.sou->sou_size_in_bits, tp->u.sou->sou_align_in_bits,
+		tp->u.sou->sou_incomplete ? "incomplete" : "complete");
 
-		for (const sym_t *mem = tp->t_sou->sou_first_member;
+		for (const sym_t *mem = tp->u.sou->sou_first_member;
 		mem != NULL; mem = mem->s_next) {
 			debug_sym("", mem, "\n");
 			debug_type_details(mem->s_type);
@@ -168,7 +168,7 @@ 

CVS commit: src/usr.bin/xlint

2024-03-09 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sat Mar  9 13:20:55 UTC 2024

Modified Files:
src/usr.bin/xlint/common: tyname.c
src/usr.bin/xlint/lint1: debug.c decl.c emit1.c func.c init.c lint1.h
tree.c

Log Message:
lint: inline accessor macros for type_t


To generate a diff of this commit:
cvs rdiff -u -r1.61 -r1.62 src/usr.bin/xlint/common/tyname.c
cvs rdiff -u -r1.71 -r1.72 src/usr.bin/xlint/lint1/debug.c
cvs rdiff -u -r1.395 -r1.396 src/usr.bin/xlint/lint1/decl.c
cvs rdiff -u -r1.90 -r1.91 src/usr.bin/xlint/lint1/emit1.c
cvs rdiff -u -r1.182 -r1.183 src/usr.bin/xlint/lint1/func.c
cvs rdiff -u -r1.261 -r1.262 src/usr.bin/xlint/lint1/init.c
cvs rdiff -u -r1.219 -r1.220 src/usr.bin/xlint/lint1/lint1.h
cvs rdiff -u -r1.610 -r1.611 src/usr.bin/xlint/lint1/tree.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/xlint/lint1

2024-03-09 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sat Mar  9 11:05:05 UTC 2024

Modified Files:
src/usr.bin/xlint/lint1: lint1.h

Log Message:
lint: clean up comments, use typedefs


To generate a diff of this commit:
cvs rdiff -u -r1.218 -r1.219 src/usr.bin/xlint/lint1/lint1.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/xlint/lint1/lint1.h
diff -u src/usr.bin/xlint/lint1/lint1.h:1.218 src/usr.bin/xlint/lint1/lint1.h:1.219
--- src/usr.bin/xlint/lint1/lint1.h:1.218	Sat Mar  9 10:54:12 2024
+++ src/usr.bin/xlint/lint1/lint1.h	Sat Mar  9 11:05:05 2024
@@ -1,4 +1,4 @@
-/* $NetBSD: lint1.h,v 1.218 2024/03/09 10:54:12 rillig Exp $ */
+/* $NetBSD: lint1.h,v 1.219 2024/03/09 11:05:05 rillig Exp $ */
 
 /*
  * Copyright (c) 1996 Christopher G. Demetriou.  All Rights Reserved.
@@ -71,19 +71,6 @@ typedef struct {
 	int	p_uniq;			/* uniquifier */
 } pos_t;
 
-// TODO: Use bit-fields instead of plain bool, but keep an eye on arm and
-// powerpc, on which NetBSD's GCC 10.5.0 (but not the upstream GCC) generates
-// code that leads to extra 327 warnings, even in msg_327.c, which does not
-// contain any type qualifier at all.
-//
-// A possible starting point for continuing the investigation is that
-// type_qualifiers is a very small struct that contains only bool bit-fields,
-// and this struct is a member of the parser's union.
-//
-// Instead of using plain bool instead of bit-fields, an alternative workaround
-// is to compile cgram.c with -Os or -O1 instead of -O2.  The generated code
-// between -Os and -O2 differs too much though to give a hint at the root
-// cause.
 typedef struct {
 	bool tq_const;
 	bool tq_restrict;
@@ -128,9 +115,7 @@ typedef struct {
 	sym_t	*sou_first_typedef;
 } struct_or_union;
 
-/*
- * same as above for enums
- */
+/* The same as in struct_or_union, only for enums. */
 typedef struct {
 	bool	en_incomplete:1;
 	sym_t	*en_first_enumerator;
@@ -138,28 +123,21 @@ typedef struct {
 	sym_t	*en_first_typedef;
 } enumeration;
 
-/*
- * The type of an expression or object. Complex types are formed via t_subt
- * (for arrays, pointers and functions), as well as t_sou.
- */
+/* The type of an expression, object or function. */
 struct lint1_type {
 	tspec_t	t_tspec;	/* type specifier */
 	bool	t_incomplete_array:1;
-	bool	t_const:1;	/* const modifier */
-	bool	t_volatile:1;	/* volatile modifier */
+	bool	t_const:1;
+	bool	t_volatile:1;
 	bool	t_proto:1;	/* function prototype (t_params valid) */
 	bool	t_vararg:1;	/* prototype with '...' */
 	bool	t_typedef:1;	/* type defined with typedef */
 	bool	t_typeof:1;	/* type defined with GCC's __typeof__ */
 	bool	t_bitfield:1;
 	/*
-	 * Either the type is currently an enum (having t_tspec ENUM), or it is
-	 * an integer type (typically INT) that has been implicitly converted
-	 * from an enum type.  In both cases, t_enum is valid.
-	 *
-	 * The information about a former enum type is retained to allow type
-	 * checks in expressions such as ((var1 & 0x0001) == var2), to detect
-	 * when var1 and var2 are from incompatible enum types.
+	 * Either the type is currently an enum (having t_tspec ENUM), or it
+	 * is an integer type (typically INT) that has been implicitly
+	 * converted from an enum type.  In both cases, t_enum is valid.
 	 */
 	bool	t_is_enum:1;
 	bool	t_packed:1;
@@ -179,7 +157,7 @@ struct lint1_type {
 #define	t_dim	t_u._t_dim
 #define	t_sou	t_u._t_sou
 #define	t_enum	t_u._t_enum
-#define	t_params	t_u._t_params
+#define	t_params t_u._t_params
 
 
 typedef enum {
@@ -189,16 +167,14 @@ typedef enum {
 	SK_LABEL
 } symbol_kind;
 
-/*
- * storage classes and related things
- */
+/* storage classes and related things */
 typedef enum {
 	NO_SCL,
 	EXTERN,			/* external symbols (independent of decl_t) */
 	STATIC,			/* static symbols (local and global) */
 	AUTO,			/* automatic symbols (except register) */
 	REG,			/* register */
-	TYPEDEF,		/* typedef */
+	TYPEDEF,
 	THREAD_LOCAL,
 	STRUCT_TAG,
 	UNION_TAG,
@@ -217,9 +193,7 @@ typedef enum {
 	FS_NORETURN,		/* since C11 */
 } function_specifier;
 
-/*
- * symbol table entry
- */
+/* A type, variable, keyword; basically anything that has a name. */
 struct sym {
 	const char *s_name;
 	const char *s_rename;	/* renamed symbol's given name */
@@ -232,26 +206,26 @@ struct sym {
 	symbol_kind s_kind;
 	const struct keyword *s_keyword;
 	bool	s_bitfield:1;
-	bool	s_set:1;	/* variable set, label defined */
-	bool	s_used:1;	/* variable/label used */
-	bool	s_param:1;	/* symbol is function parameter */
-	bool	s_register:1;	/* symbol is register variable */
+	bool	s_set:1;
+	bool	s_used:1;
+	bool	s_param:1;
+	bool	s_register:1;
 	bool	s_defparam:1;	/* undefined symbol in old-style function
  * definition */
 	bool	s_return_type_implicit_int:1;
 	bool	s_osdef:1;	/* symbol stems from old-style function def. */
-	bool	s_inline:1;	/* true if this is an inline function */
-	struct 

CVS commit: src/usr.bin/xlint/lint1

2024-03-09 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sat Mar  9 11:05:05 UTC 2024

Modified Files:
src/usr.bin/xlint/lint1: lint1.h

Log Message:
lint: clean up comments, use typedefs


To generate a diff of this commit:
cvs rdiff -u -r1.218 -r1.219 src/usr.bin/xlint/lint1/lint1.h

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



CVS commit: src/usr.bin/xlint/lint1

2024-03-09 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sat Mar  9 10:54:12 UTC 2024

Modified Files:
src/usr.bin/xlint/lint1: func.c lint1.h

Log Message:
lint: internally store case label values in order of appearance


To generate a diff of this commit:
cvs rdiff -u -r1.181 -r1.182 src/usr.bin/xlint/lint1/func.c
cvs rdiff -u -r1.217 -r1.218 src/usr.bin/xlint/lint1/lint1.h

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



CVS commit: src/usr.bin/xlint/lint1

2024-03-09 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sat Mar  9 10:54:12 UTC 2024

Modified Files:
src/usr.bin/xlint/lint1: func.c lint1.h

Log Message:
lint: internally store case label values in order of appearance


To generate a diff of this commit:
cvs rdiff -u -r1.181 -r1.182 src/usr.bin/xlint/lint1/func.c
cvs rdiff -u -r1.217 -r1.218 src/usr.bin/xlint/lint1/lint1.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/xlint/lint1/func.c
diff -u src/usr.bin/xlint/lint1/func.c:1.181 src/usr.bin/xlint/lint1/func.c:1.182
--- src/usr.bin/xlint/lint1/func.c:1.181	Thu Feb  8 20:45:20 2024
+++ src/usr.bin/xlint/lint1/func.c	Sat Mar  9 10:54:12 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: func.c,v 1.181 2024/02/08 20:45:20 rillig Exp $	*/
+/*	$NetBSD: func.c,v 1.182 2024/03/09 10:54:12 rillig Exp $	*/
 
 /*
  * Copyright (c) 1994, 1995 Jochen Pohl
@@ -37,7 +37,7 @@
 
 #include 
 #if defined(__RCSID)
-__RCSID("$NetBSD: func.c,v 1.181 2024/02/08 20:45:20 rillig Exp $");
+__RCSID("$NetBSD: func.c,v 1.182 2024/03/09 10:54:12 rillig Exp $");
 #endif
 
 #include 
@@ -162,12 +162,7 @@ end_control_statement(control_statement_
 	control_statement *cs = cstmt;
 	cstmt = cs->c_surrounding;
 
-	case_label_t *cl, *next;
-	for (cl = cs->c_case_labels; cl != NULL; cl = next) {
-		next = cl->cl_next;
-		free(cl);
-	}
-
+	free(cs->c_case_labels.vals);
 	free(cs->c_switch_type);
 	free(cs);
 }
@@ -436,6 +431,34 @@ check_case_label_enum(const tnode_t *tn,
 #endif
 }
 
+static bool
+check_duplicate_case_label(control_statement *cs, const val_t *nv)
+{
+	case_labels *labels = >c_case_labels;
+	size_t i = 0, n = labels->len;
+
+	while (i < n && labels->vals[i].u.integer != nv->u.integer)
+		i++;
+
+	if (i < n) {
+		if (is_uinteger(nv->v_tspec))
+			/* duplicate case '%lu' in switch */
+			error(200, (unsigned long)nv->u.integer);
+		else
+			/* duplicate case '%ld' in switch */
+			error(199, (long)nv->u.integer);
+		return false;
+	}
+
+	if (labels->len >= labels->cap) {
+		labels->cap = 16 + 2 * labels->cap;
+		labels->vals = xrealloc(labels->vals,
+		sizeof(*labels->vals) * labels->cap);
+	}
+	labels->vals[labels->len++] = *nv;
+	return true;
+}
+
 static void
 check_case_label(tnode_t *tn)
 {
@@ -487,27 +510,8 @@ check_case_label(tnode_t *tn)
 	convert_constant(CASE, 0, cs->c_switch_type, , v);
 	free(v);
 
-	/* look if we had this value already */
-	case_label_t *cl;
-	for (cl = cs->c_case_labels; cl != NULL; cl = cl->cl_next) {
-		if (cl->cl_val.u.integer == nv.u.integer)
-			break;
-	}
-	if (cl != NULL && is_uinteger(nv.v_tspec))
-		/* duplicate case '%lu' in switch */
-		error(200, (unsigned long)nv.u.integer);
-	else if (cl != NULL)
-		/* duplicate case '%ld' in switch */
-		error(199, (long)nv.u.integer);
-	else {
+	if (check_duplicate_case_label(cs, ))
 		check_getopt_case_label(nv.u.integer);
-
-		/* Prepend the value to the list of case values. */
-		cl = xcalloc(1, sizeof(*cl));
-		cl->cl_val = nv;
-		cl->cl_next = cs->c_case_labels;
-		cs->c_case_labels = cl;
-	}
 }
 
 void
@@ -660,7 +664,6 @@ stmt_switch_expr_stmt(void)
 {
 	int nenum = 0, nclab = 0;
 	sym_t *esym;
-	case_label_t *cl;
 
 	lint_assert(cstmt->c_switch_type != NULL);
 
@@ -675,8 +678,7 @@ stmt_switch_expr_stmt(void)
 		esym != NULL; esym = esym->s_next) {
 			nenum++;
 		}
-		for (cl = cstmt->c_case_labels; cl != NULL; cl = cl->cl_next)
-			nclab++;
+		nclab = (int)cstmt->c_case_labels.len;
 		if (hflag && eflag && nclab < nenum && !cstmt->c_default)
 			/* enumeration value(s) not handled in switch */
 			warning(206);

Index: src/usr.bin/xlint/lint1/lint1.h
diff -u src/usr.bin/xlint/lint1/lint1.h:1.217 src/usr.bin/xlint/lint1/lint1.h:1.218
--- src/usr.bin/xlint/lint1/lint1.h:1.217	Sat Mar  9 10:47:16 2024
+++ src/usr.bin/xlint/lint1/lint1.h	Sat Mar  9 10:54:12 2024
@@ -1,4 +1,4 @@
-/* $NetBSD: lint1.h,v 1.217 2024/03/09 10:47:16 rillig Exp $ */
+/* $NetBSD: lint1.h,v 1.218 2024/03/09 10:54:12 rillig Exp $ */
 
 /*
  * Copyright (c) 1996 Christopher G. Demetriou.  All Rights Reserved.
@@ -425,14 +425,12 @@ typedef struct qual_ptr {
 	struct qual_ptr *p_next;
 } qual_ptr;
 
-/*
- * The values of the 'case' labels, linked via cl_next in reverse order of
- * appearance in the code, that is from bottom to top.
- */
-typedef struct case_label {
-	val_t	cl_val;
-	struct case_label *cl_next;
-} case_label_t;
+/* The values of the 'case' labels. */
+typedef struct {
+	val_t	*vals;
+	size_t	len;
+	size_t	cap;
+} case_labels;
 
 typedef enum {
 	CS_DO_WHILE,
@@ -466,7 +464,7 @@ typedef struct control_statement {
 
 	type_t	*c_switch_type;	/* type of switch expression */
 	tnode_t	*c_switch_expr;
-	case_label_t *c_case_labels;	/* list of case values */
+	case_labels c_case_labels;	/* list of case values */
 
 	memory_pool c_for_expr3_mem;	/* saved memory for end of loop
 	 * expression in for() */



CVS commit: src/usr.bin/xlint/lint1

2024-03-09 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sat Mar  9 10:47:16 UTC 2024

Modified Files:
src/usr.bin/xlint/lint1: cksnprintb.c lint1.h tree.c

Log Message:
lint: remove unneeded checks for left and right operands


To generate a diff of this commit:
cvs rdiff -u -r1.7 -r1.8 src/usr.bin/xlint/lint1/cksnprintb.c
cvs rdiff -u -r1.216 -r1.217 src/usr.bin/xlint/lint1/lint1.h
cvs rdiff -u -r1.609 -r1.610 src/usr.bin/xlint/lint1/tree.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/xlint/lint1/cksnprintb.c
diff -u src/usr.bin/xlint/lint1/cksnprintb.c:1.7 src/usr.bin/xlint/lint1/cksnprintb.c:1.8
--- src/usr.bin/xlint/lint1/cksnprintb.c:1.7	Sun Mar  3 16:09:01 2024
+++ src/usr.bin/xlint/lint1/cksnprintb.c	Sat Mar  9 10:47:16 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: cksnprintb.c,v 1.7 2024/03/03 16:09:01 rillig Exp $	*/
+/*	$NetBSD: cksnprintb.c,v 1.8 2024/03/09 10:47:16 rillig Exp $	*/
 
 /*-
  * Copyright (c) 2024 The NetBSD Foundation, Inc.
@@ -35,7 +35,7 @@
 
 #include 
 #if defined(__RCSID)
-__RCSID("$NetBSD: cksnprintb.c,v 1.7 2024/03/03 16:09:01 rillig Exp $");
+__RCSID("$NetBSD: cksnprintb.c,v 1.8 2024/03/09 10:47:16 rillig Exp $");
 #endif
 
 #include 
@@ -59,7 +59,7 @@ static bool
 match_string_literal(const tnode_t *tn, const buffer **str)
 {
 	while (tn->tn_op == CVT)
-		tn = tn_ck_left(tn);
+		tn = tn->tn_left;
 	return tn->tn_op == ADDR
 	&& tn->tn_left->tn_op == STRING
 	&& (*str = tn->tn_left->tn_string, (*str)->data != NULL);

Index: src/usr.bin/xlint/lint1/lint1.h
diff -u src/usr.bin/xlint/lint1/lint1.h:1.216 src/usr.bin/xlint/lint1/lint1.h:1.217
--- src/usr.bin/xlint/lint1/lint1.h:1.216	Sat Mar  9 10:41:11 2024
+++ src/usr.bin/xlint/lint1/lint1.h	Sat Mar  9 10:47:16 2024
@@ -1,4 +1,4 @@
-/* $NetBSD: lint1.h,v 1.216 2024/03/09 10:41:11 rillig Exp $ */
+/* $NetBSD: lint1.h,v 1.217 2024/03/09 10:47:16 rillig Exp $ */
 
 /*
  * Copyright (c) 1996 Christopher G. Demetriou.  All Rights Reserved.
@@ -555,20 +555,6 @@ typedef struct {
 			assert_failed(__FILE__, __LINE__, __func__, #cond); \
 	} while (false)
 
-static inline tnode_t *
-tn_ck_left(const tnode_t *tn)
-{
-	lint_assert(has_operands(tn));
-	return tn->tn_left;
-}
-
-static inline tnode_t *
-tn_ck_right(const tnode_t *tn)
-{
-	lint_assert(has_operands(tn));
-	return tn->tn_right;
-}
-
 #ifdef DEBUG
 #  include "err-msgs.h"
 

Index: src/usr.bin/xlint/lint1/tree.c
diff -u src/usr.bin/xlint/lint1/tree.c:1.609 src/usr.bin/xlint/lint1/tree.c:1.610
--- src/usr.bin/xlint/lint1/tree.c:1.609	Sun Mar  3 16:09:01 2024
+++ src/usr.bin/xlint/lint1/tree.c	Sat Mar  9 10:47:16 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: tree.c,v 1.609 2024/03/03 16:09:01 rillig Exp $	*/
+/*	$NetBSD: tree.c,v 1.610 2024/03/09 10:47:16 rillig Exp $	*/
 
 /*
  * Copyright (c) 1994, 1995 Jochen Pohl
@@ -37,7 +37,7 @@
 
 #include 
 #if defined(__RCSID)
-__RCSID("$NetBSD: tree.c,v 1.609 2024/03/03 16:09:01 rillig Exp $");
+__RCSID("$NetBSD: tree.c,v 1.610 2024/03/09 10:47:16 rillig Exp $");
 #endif
 
 #include 
@@ -1236,7 +1236,7 @@ build_colon(bool sys, tnode_t *ln, tnode
 static bool
 is_cast_redundant(const tnode_t *tn)
 {
-	const type_t *ntp = tn->tn_type, *otp = tn_ck_left(tn)->tn_type;
+	const type_t *ntp = tn->tn_type, *otp = tn->tn_left->tn_type;
 	tspec_t nt = ntp->t_tspec, ot = otp->t_tspec;
 
 	if (nt == BOOL || ot == BOOL)



CVS commit: src/usr.bin/xlint/lint1

2024-03-09 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sat Mar  9 10:47:16 UTC 2024

Modified Files:
src/usr.bin/xlint/lint1: cksnprintb.c lint1.h tree.c

Log Message:
lint: remove unneeded checks for left and right operands


To generate a diff of this commit:
cvs rdiff -u -r1.7 -r1.8 src/usr.bin/xlint/lint1/cksnprintb.c
cvs rdiff -u -r1.216 -r1.217 src/usr.bin/xlint/lint1/lint1.h
cvs rdiff -u -r1.609 -r1.610 src/usr.bin/xlint/lint1/tree.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/xlint/lint1

2024-03-09 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sat Mar  9 10:41:11 UTC 2024

Modified Files:
src/usr.bin/xlint/lint1: cgram.y decl.c externs1.h lint1.h

Log Message:
lint: use fewer struct keywords


To generate a diff of this commit:
cvs rdiff -u -r1.489 -r1.490 src/usr.bin/xlint/lint1/cgram.y
cvs rdiff -u -r1.394 -r1.395 src/usr.bin/xlint/lint1/decl.c
cvs rdiff -u -r1.218 -r1.219 src/usr.bin/xlint/lint1/externs1.h
cvs rdiff -u -r1.215 -r1.216 src/usr.bin/xlint/lint1/lint1.h

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



CVS commit: src/usr.bin/xlint/lint1

2024-03-09 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sat Mar  9 10:41:11 UTC 2024

Modified Files:
src/usr.bin/xlint/lint1: cgram.y decl.c externs1.h lint1.h

Log Message:
lint: use fewer struct keywords


To generate a diff of this commit:
cvs rdiff -u -r1.489 -r1.490 src/usr.bin/xlint/lint1/cgram.y
cvs rdiff -u -r1.394 -r1.395 src/usr.bin/xlint/lint1/decl.c
cvs rdiff -u -r1.218 -r1.219 src/usr.bin/xlint/lint1/externs1.h
cvs rdiff -u -r1.215 -r1.216 src/usr.bin/xlint/lint1/lint1.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/xlint/lint1/cgram.y
diff -u src/usr.bin/xlint/lint1/cgram.y:1.489 src/usr.bin/xlint/lint1/cgram.y:1.490
--- src/usr.bin/xlint/lint1/cgram.y:1.489	Thu Feb  8 20:45:20 2024
+++ src/usr.bin/xlint/lint1/cgram.y	Sat Mar  9 10:41:11 2024
@@ -1,5 +1,5 @@
 %{
-/* $NetBSD: cgram.y,v 1.489 2024/02/08 20:45:20 rillig Exp $ */
+/* $NetBSD: cgram.y,v 1.490 2024/03/09 10:41:11 rillig Exp $ */
 
 /*
  * Copyright (c) 1996 Christopher G. Demetriou.  All Rights Reserved.
@@ -35,7 +35,7 @@
 
 #include 
 #if defined(__RCSID)
-__RCSID("$NetBSD: cgram.y,v 1.489 2024/02/08 20:45:20 rillig Exp $");
+__RCSID("$NetBSD: cgram.y,v 1.490 2024/03/09 10:41:11 rillig Exp $");
 #endif
 
 #include 
@@ -128,7 +128,7 @@ is_either(const char *s, const char *a, 
 	tspec_t	y_tspec;
 	type_qualifiers y_type_qualifiers;
 	function_specifier y_function_specifier;
-	struct parameter_list y_parameter_list;
+	parameter_list y_parameter_list;
 	function_call *y_arguments;
 	type_t	*y_type;
 	tnode_t	*y_tnode;
@@ -137,7 +137,7 @@ is_either(const char *s, const char *a, 
 	qual_ptr *y_qual_ptr;
 	bool	y_seen_statement;
 	struct generic_association *y_generic;
-	struct array_size y_array_size;
+	array_size y_array_size;
 	bool	y_in_system_header;
 	designation y_designation;
 };
@@ -1421,7 +1421,7 @@ param_list:
 		block_level++;
 		begin_declaration_level(DLK_PROTO_PARAMS);
 	} identifier_list T_RPAREN {
-		$$ = (struct parameter_list){ .first = $3 };
+		$$ = (parameter_list){ .first = $3 };
 	}
 |	abstract_decl_param_list
 ;
@@ -1541,7 +1541,7 @@ direct_abstract_declarator:
 
 abstract_decl_param_list:	/* specific to lint */
 	abstract_decl_lparen T_RPAREN type_attribute_opt {
-		$$ = (struct parameter_list){ .first = NULL };
+		$$ = (parameter_list){ .first = NULL };
 	}
 |	abstract_decl_lparen vararg_parameter_type_list T_RPAREN
 	type_attribute_opt {
@@ -1549,7 +1549,7 @@ abstract_decl_param_list:	/* specific to
 		$$.prototype = true;
 	}
 |	abstract_decl_lparen error T_RPAREN type_attribute_opt {
-		$$ = (struct parameter_list){ .first = NULL };
+		$$ = (parameter_list){ .first = NULL };
 	}
 ;
 
@@ -1574,14 +1574,14 @@ vararg_parameter_type_list:	/* specific 
 		else if (allow_c90)
 			/* C90 to C17 require formal parameter before '...' */
 			warning(84);
-		$$ = (struct parameter_list){ .vararg = true };
+		$$ = (parameter_list){ .vararg = true };
 	}
 ;
 
 /* XXX: C99 6.7.5 defines the same name, but it looks different. */
 parameter_type_list:
 	parameter_declaration {
-		$$ = (struct parameter_list){ .first = $1 };
+		$$ = (parameter_list){ .first = $1 };
 	}
 |	parameter_type_list T_COMMA parameter_declaration {
 		$$ = $1;

Index: src/usr.bin/xlint/lint1/decl.c
diff -u src/usr.bin/xlint/lint1/decl.c:1.394 src/usr.bin/xlint/lint1/decl.c:1.395
--- src/usr.bin/xlint/lint1/decl.c:1.394	Sat Mar  2 09:32:18 2024
+++ src/usr.bin/xlint/lint1/decl.c	Sat Mar  9 10:41:11 2024
@@ -1,4 +1,4 @@
-/* $NetBSD: decl.c,v 1.394 2024/03/02 09:32:18 rillig Exp $ */
+/* $NetBSD: decl.c,v 1.395 2024/03/09 10:41:11 rillig Exp $ */
 
 /*
  * Copyright (c) 1996 Christopher G. Demetriou.  All Rights Reserved.
@@ -38,7 +38,7 @@
 
 #include 
 #if defined(__RCSID)
-__RCSID("$NetBSD: decl.c,v 1.394 2024/03/02 09:32:18 rillig Exp $");
+__RCSID("$NetBSD: decl.c,v 1.395 2024/03/09 10:41:11 rillig Exp $");
 #endif
 
 #include 
@@ -1334,7 +1334,7 @@ old_style_function(sym_t *decl, sym_t *p
 }
 
 sym_t *
-add_function(sym_t *decl, struct parameter_list params)
+add_function(sym_t *decl, parameter_list params)
 {
 
 	debug_enter();

Index: src/usr.bin/xlint/lint1/externs1.h
diff -u src/usr.bin/xlint/lint1/externs1.h:1.218 src/usr.bin/xlint/lint1/externs1.h:1.219
--- src/usr.bin/xlint/lint1/externs1.h:1.218	Sun Mar  3 00:50:41 2024
+++ src/usr.bin/xlint/lint1/externs1.h	Sat Mar  9 10:41:11 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: externs1.h,v 1.218 2024/03/03 00:50:41 rillig Exp $	*/
+/*	$NetBSD: externs1.h,v 1.219 2024/03/09 10:41:11 rillig Exp $	*/
 
 /*
  * Copyright (c) 1994, 1995 Jochen Pohl
@@ -233,7 +233,7 @@ void add_type_qualifiers(type_qualifiers
 qual_ptr *append_qualified_pointer(qual_ptr *, qual_ptr *);
 sym_t *add_pointer(sym_t *, qual_ptr *);
 sym_t *add_array(sym_t *, bool, int);
-sym_t *add_function(sym_t *, struct parameter_list);
+sym_t *add_function(sym_t *, parameter_list);
 void check_extern_declaration(const sym_t *);
 

CVS commit: src/usr.sbin/postinstall

2024-03-08 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sat Mar  9 06:51:40 UTC 2024

Modified Files:
src/usr.sbin/postinstall: postinstall.in

Log Message:
postinstall: fix endless loop (since 2024-03-07)


To generate a diff of this commit:
cvs rdiff -u -r1.60 -r1.61 src/usr.sbin/postinstall/postinstall.in

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



CVS commit: src/usr.sbin/postinstall

2024-03-08 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sat Mar  9 06:51:40 UTC 2024

Modified Files:
src/usr.sbin/postinstall: postinstall.in

Log Message:
postinstall: fix endless loop (since 2024-03-07)


To generate a diff of this commit:
cvs rdiff -u -r1.60 -r1.61 src/usr.sbin/postinstall/postinstall.in

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

Modified files:

Index: src/usr.sbin/postinstall/postinstall.in
diff -u src/usr.sbin/postinstall/postinstall.in:1.60 src/usr.sbin/postinstall/postinstall.in:1.61
--- src/usr.sbin/postinstall/postinstall.in:1.60	Thu Mar  7 22:03:16 2024
+++ src/usr.sbin/postinstall/postinstall.in	Sat Mar  9 06:51:40 2024
@@ -1,6 +1,6 @@
 #!/bin/sh
 #
-# $NetBSD: postinstall.in,v 1.60 2024/03/07 22:03:16 christos Exp $
+# $NetBSD: postinstall.in,v 1.61 2024/03/09 06:51:40 rillig Exp $
 #
 # Copyright (c) 2002-2022 The NetBSD Foundation, Inc.
 # All rights reserved.
@@ -100,7 +100,7 @@ mkdtemp()
 	while true; do
 		dir="${base}.${serial}"
 		mkdir -m 0700 "${dir}" && break
-		_serial=$((${serial} + 1))
+		serial=$((${serial} + 1))
 	done
 	echo "${dir}"
 }



CVS commit: src

2024-03-08 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Fri Mar  8 20:29:18 UTC 2024

Modified Files:
src/sys/arch/x86/include: specialreg.h
src/usr.sbin/cpuctl/arch: i386.c

Log Message:
cpuctl: fix i386 bit descriptions for CPUID_SEF_FLAGS1

warning: non-printing character '\31' in description
'BUS_LOCK_DETECT""b\31' [363]


To generate a diff of this commit:
cvs rdiff -u -r1.209 -r1.210 src/sys/arch/x86/include/specialreg.h
cvs rdiff -u -r1.143 -r1.144 src/usr.sbin/cpuctl/arch/i386.c

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



CVS commit: src

2024-03-08 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Fri Mar  8 20:29:18 UTC 2024

Modified Files:
src/sys/arch/x86/include: specialreg.h
src/usr.sbin/cpuctl/arch: i386.c

Log Message:
cpuctl: fix i386 bit descriptions for CPUID_SEF_FLAGS1

warning: non-printing character '\31' in description
'BUS_LOCK_DETECT""b\31' [363]


To generate a diff of this commit:
cvs rdiff -u -r1.209 -r1.210 src/sys/arch/x86/include/specialreg.h
cvs rdiff -u -r1.143 -r1.144 src/usr.sbin/cpuctl/arch/i386.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/x86/include/specialreg.h
diff -u src/sys/arch/x86/include/specialreg.h:1.209 src/sys/arch/x86/include/specialreg.h:1.210
--- src/sys/arch/x86/include/specialreg.h:1.209	Fri Oct 27 06:31:48 2023
+++ src/sys/arch/x86/include/specialreg.h	Fri Mar  8 20:29:17 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: specialreg.h,v 1.209 2023/10/27 06:31:48 mrg Exp $	*/
+/*	$NetBSD: specialreg.h,v 1.210 2024/03/08 20:29:17 rillig Exp $	*/
 
 /*
  * Copyright (c) 2014-2020 The NetBSD Foundation, Inc.
@@ -481,7 +481,7 @@
 	"b\14AVX512_BITALG\0" "b\15TME_EN\0" "b\16AVX512_VPOPCNTDQ\0"	  \
 	"b\20LA57\0"			  \
 	"f\21\5MAWAU\0"			"b\26RDPID\0"	"b\27KL\0"	  \
-	"b\30BUS_LOCK_DETECT" "b\31CLDEMOTE\0"		"b\33MOVDIRI\0"	  \
+	"b\30BUS_LOCK_DETECT\0" "b\31CLDEMOTE\0"	"b\33MOVDIRI\0"	  \
 	"b\34MOVDIR64B\0" "b\35ENQCMD\0" "b\36SGXLC\0"	"b\37PKS\0"
 
 /* %ecx = 0, %edx */

Index: src/usr.sbin/cpuctl/arch/i386.c
diff -u src/usr.sbin/cpuctl/arch/i386.c:1.143 src/usr.sbin/cpuctl/arch/i386.c:1.144
--- src/usr.sbin/cpuctl/arch/i386.c:1.143	Sat Feb 10 18:43:53 2024
+++ src/usr.sbin/cpuctl/arch/i386.c	Fri Mar  8 20:29:17 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: i386.c,v 1.143 2024/02/10 18:43:53 andvar Exp $	*/
+/*	$NetBSD: i386.c,v 1.144 2024/03/08 20:29:17 rillig Exp $	*/
 
 /*-
  * Copyright (c) 1999, 2000, 2001, 2006, 2007, 2008 The NetBSD Foundation, Inc.
@@ -57,7 +57,7 @@
 
 #include 
 #ifndef lint
-__RCSID("$NetBSD: i386.c,v 1.143 2024/02/10 18:43:53 andvar Exp $");
+__RCSID("$NetBSD: i386.c,v 1.144 2024/03/08 20:29:17 rillig Exp $");
 #endif /* not lint */
 
 #include 
@@ -1728,6 +1728,13 @@ print_bits(const char *cpuname, const ch
 		bp += strlen(bp) + 1;
 	}
 }
+#ifdef lint
+#define print_bits(cpuname, hdr, fmt, val) \
+	do {	\
+		print_bits(cpuname, hdr, fmt, val); \
+		snprintb(NULL, 0, fmt, val); \
+	} while (0)
+#endif
 
 static void
 dump_descs(uint32_t leafstart, uint32_t leafend, const char *cpuname,



CVS commit: src/sys/net/agr

2024-03-08 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Fri Mar  8 19:45:59 UTC 2024

Modified Files:
src/sys/net/agr: if_agrioctl.h

Log Message:
ifconfig: fix agr status

Previously, when the interface was collecting, its status was reported
as '', even when it was not distributing.

sbin/ifconfig/agr.c(170): warning: 'b\0DISTRIBUTING\0' overlaps earlier
'b\0COLLECTING\0' on bit 0 [376]


To generate a diff of this commit:
cvs rdiff -u -r1.2 -r1.3 src/sys/net/agr/if_agrioctl.h

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



CVS commit: src/sys/net/agr

2024-03-08 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Fri Mar  8 19:45:59 UTC 2024

Modified Files:
src/sys/net/agr: if_agrioctl.h

Log Message:
ifconfig: fix agr status

Previously, when the interface was collecting, its status was reported
as '', even when it was not distributing.

sbin/ifconfig/agr.c(170): warning: 'b\0DISTRIBUTING\0' overlaps earlier
'b\0COLLECTING\0' on bit 0 [376]


To generate a diff of this commit:
cvs rdiff -u -r1.2 -r1.3 src/sys/net/agr/if_agrioctl.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/net/agr/if_agrioctl.h
diff -u src/sys/net/agr/if_agrioctl.h:1.2 src/sys/net/agr/if_agrioctl.h:1.3
--- src/sys/net/agr/if_agrioctl.h:1.2	Sat Dec 10 23:21:39 2005
+++ src/sys/net/agr/if_agrioctl.h	Fri Mar  8 19:45:59 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_agrioctl.h,v 1.2 2005/12/10 23:21:39 elad Exp $	*/
+/*	$NetBSD: if_agrioctl.h,v 1.3 2024/03/08 19:45:59 rillig Exp $	*/
 
 /*-
  * Copyright (c)2005 YAMAMOTO Takashi,
@@ -64,7 +64,7 @@ struct agrportinfo {
 #define	AGRPORTINFO_BITS \
 	"\177\020" \
 	"b\0COLLECTING\0" \
-	"b\0DISTRIBUTING\0"
+	"b\1DISTRIBUTING\0"
 
 struct agrportlist {
 	int apl_nports;



CVS commit: src/usr.bin/make/unit-tests

2024-03-05 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Tue Mar  5 23:07:58 UTC 2024

Modified Files:
src/usr.bin/make/unit-tests: var-scope-local.exp var-scope-local.mk

Log Message:
tests/make: clean up test for local scope variables

Use the same style of quotes for both kinds of variables.  To make the
variable values more easily comparable, write them to a single line.
Add the output to the 'expect' lines.


To generate a diff of this commit:
cvs rdiff -u -r1.8 -r1.9 src/usr.bin/make/unit-tests/var-scope-local.exp
cvs rdiff -u -r1.10 -r1.11 src/usr.bin/make/unit-tests/var-scope-local.mk

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



CVS commit: src/usr.bin/make/unit-tests

2024-03-05 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Tue Mar  5 23:07:58 UTC 2024

Modified Files:
src/usr.bin/make/unit-tests: var-scope-local.exp var-scope-local.mk

Log Message:
tests/make: clean up test for local scope variables

Use the same style of quotes for both kinds of variables.  To make the
variable values more easily comparable, write them to a single line.
Add the output to the 'expect' lines.


To generate a diff of this commit:
cvs rdiff -u -r1.8 -r1.9 src/usr.bin/make/unit-tests/var-scope-local.exp
cvs rdiff -u -r1.10 -r1.11 src/usr.bin/make/unit-tests/var-scope-local.mk

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/make/unit-tests/var-scope-local.exp
diff -u src/usr.bin/make/unit-tests/var-scope-local.exp:1.8 src/usr.bin/make/unit-tests/var-scope-local.exp:1.9
--- src/usr.bin/make/unit-tests/var-scope-local.exp:1.8	Fri Mar  1 20:15:59 2024
+++ src/usr.bin/make/unit-tests/var-scope-local.exp	Tue Mar  5 23:07:58 2024
@@ -60,19 +60,12 @@ dir/subdir/inference-rule-chain.ir-to: *
 : Making var-scope-local.c out of nothing.
 : Making var-scope-local.o from var-scope-local.c.
 : Making basename "var-scope-local.o" in "." from "var-scope-local.c" in ".".
-: Making var-scope-local-assign.o with VAR="local".
-var-scope-local-assign.o env has VAR='local'
-: Making var-scope-local-append.o with VAR="local to var-scope-local-append.o".
-var-scope-local-append.o env has VAR='local to var-scope-local-append.o'
-: Making var-scope-local-append-global.o with VAR="global+local".
-var-scope-local-append-global.o env has VAR='global+local'
-: Making var-scope-local-default.o with VAR="global".
-var-scope-local-default.o env has VAR='global'
-: Making var-scope-local-subst.o with VAR="global+local".
-var-scope-local-subst.o env has VAR='global+local'
-: Making var-scope-local-shell.o with VAR="output".
-var-scope-local-shell.o env has VAR='output'
-: var-scope-local-use.o uses .USE VAR="global"
-var-scope-local-use.o env has VAR='global'
+Making var-scope-local-assign.o with make 'local' and env 'local'.
+Making var-scope-local-append.o with make 'local to var-scope-local-append.o' and env 'local to var-scope-local-append.o'.
+Making var-scope-local-append-global.o with make 'global+local' and env 'global+local'.
+Making var-scope-local-default.o with make 'global' and env 'global'.
+Making var-scope-local-subst.o with make 'global+local' and env 'global+local'.
+Making var-scope-local-shell.o with make 'output' and env 'output'.
+Making .USE var-scope-local-use.o with make 'global' and env 'global'.
 : all overwritten
 exit status 0

Index: src/usr.bin/make/unit-tests/var-scope-local.mk
diff -u src/usr.bin/make/unit-tests/var-scope-local.mk:1.10 src/usr.bin/make/unit-tests/var-scope-local.mk:1.11
--- src/usr.bin/make/unit-tests/var-scope-local.mk:1.10	Fri Mar  1 20:15:59 2024
+++ src/usr.bin/make/unit-tests/var-scope-local.mk	Tue Mar  5 23:07:58 2024
@@ -1,4 +1,4 @@
-# $NetBSD: var-scope-local.mk,v 1.10 2024/03/01 20:15:59 sjg Exp $
+# $NetBSD: var-scope-local.mk,v 1.11 2024/03/05 23:07:58 rillig Exp $
 #
 # Tests for target-local variables, such as ${.TARGET} or $@.  These variables
 # are relatively short-lived as they are created just before making the
@@ -199,8 +199,7 @@ var-scope-local-append-global.o \
 var-scope-local-default.o \
 var-scope-local-subst.o \
 var-scope-local-shell.o:
-	: Making ${.TARGET} with VAR="${VAR}".
-	@echo "${.TARGET} env has VAR='$$VAR'"
+	@echo "Making ${.TARGET} with make '"${VAR:Q}"' and env '$$VAR'."
 
 # Target-local variables are enabled by default.  Force them to be enabled
 # just in case a test above has disabled them.
@@ -215,7 +214,7 @@ VAR=	global
 # irrelevant.
 #
 # expect-reset
-# expect: : Making var-scope-local-assign.o with VAR="local".
+# expect: Making var-scope-local-assign.o with make 'local' and env 'local'.
 var-scope-local-assign.o: VAR= local
 
 # Assignments using '+=' do *not* look up the global value, instead they only
@@ -225,7 +224,7 @@ var-scope-local-append.o: VAR+= local
 # behaves as expected.  Note that the expression '${.TARGET}' is not resolved
 # when parsing the dependency line, its evaluation is deferred until the
 # target is actually made.
-# expect: : Making var-scope-local-append.o with VAR="local to var-scope-local-append.o".
+# expect: Making var-scope-local-append.o with make 'local to var-scope-local-append.o' and env 'local to var-scope-local-append.o'.
 var-scope-local-append.o: VAR += to ${.TARGET}
 # To access the value of a global variable, use an expression.  This
 # expression is expanded before parsing the whole dependency line.  Since the
@@ -235,7 +234,7 @@ var-scope-local-append.o: VAR += to ${.T
 # not influence the parsing of the variable assignment.  The effective
 # variable assignment, after expanding the whole line first, is thus
 # 'VAR= global+local'.
-# expect: : Making 

CVS commit: src/common/lib/libutil

2024-03-04 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Tue Mar  5 07:37:08 UTC 2024

Modified Files:
src/common/lib/libutil: snprintb.c

Log Message:
snprintb: shrink code size, both in source and binary


To generate a diff of this commit:
cvs rdiff -u -r1.42 -r1.43 src/common/lib/libutil/snprintb.c

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



CVS commit: src/common/lib/libutil

2024-03-04 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Tue Mar  5 07:37:08 UTC 2024

Modified Files:
src/common/lib/libutil: snprintb.c

Log Message:
snprintb: shrink code size, both in source and binary


To generate a diff of this commit:
cvs rdiff -u -r1.42 -r1.43 src/common/lib/libutil/snprintb.c

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

Modified files:

Index: src/common/lib/libutil/snprintb.c
diff -u src/common/lib/libutil/snprintb.c:1.42 src/common/lib/libutil/snprintb.c:1.43
--- src/common/lib/libutil/snprintb.c:1.42	Mon Mar  4 21:35:28 2024
+++ src/common/lib/libutil/snprintb.c	Tue Mar  5 07:37:08 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: snprintb.c,v 1.42 2024/03/04 21:35:28 rillig Exp $	*/
+/*	$NetBSD: snprintb.c,v 1.43 2024/03/05 07:37:08 rillig Exp $	*/
 
 /*-
  * Copyright (c) 2002, 2024 The NetBSD Foundation, Inc.
@@ -35,17 +35,18 @@
 
 #  include 
 #  if defined(LIBC_SCCS)
-__RCSID("$NetBSD: snprintb.c,v 1.42 2024/03/04 21:35:28 rillig Exp $");
+__RCSID("$NetBSD: snprintb.c,v 1.43 2024/03/05 07:37:08 rillig Exp $");
 #  endif
 
 #  include 
 #  include 
 #  include 
+#  include 
 #  include 
 #  include 
 # else /* ! _KERNEL */
 #  include 
-__KERNEL_RCSID(0, "$NetBSD: snprintb.c,v 1.42 2024/03/04 21:35:28 rillig Exp $");
+__KERNEL_RCSID(0, "$NetBSD: snprintb.c,v 1.43 2024/03/05 07:37:08 rillig Exp $");
 #  include 
 #  include 
 #  include 
@@ -60,7 +61,7 @@ typedef struct {
 	uint64_t const val;
 	size_t const line_max;
 
-	const char *const num_fmt;
+	char num_fmt[5];
 	size_t total_len;
 	size_t line_pos;
 	size_t comma_pos;
@@ -255,48 +256,42 @@ snprintb_m(char *buf, size_t bufsize, co
 	if (!old)
 		bitfmt++;
 
-	const char *num_fmt;
-	switch (*bitfmt++) {
-	case 8:
-		num_fmt = "%#jo";
-		break;
-	case 10:
-		num_fmt = "%ju";
-		break;
-	case 16:
-		num_fmt = "%#jx";
-		break;
-	default:
-		num_fmt = NULL;
-	}
-
 	state s = {
 		.buf = buf,
 		.bufsize = bufsize,
 		.bitfmt = bitfmt,
 		.val = val,
 		.line_max = line_max,
-		.num_fmt = num_fmt,
 	};
-	if (num_fmt == NULL)
-		goto internal;
+	int had_error = 0;
 
-	store_num(, num_fmt, val);
+	switch (*s.bitfmt++) {
+	case 8:
+		memcpy(s.num_fmt, "%#jo", 4);
+		break;
+	case 10:
+		memcpy(s.num_fmt, "%ju", 4);
+		break;
+	case 16:
+		memcpy(s.num_fmt, "%#jx", 4);
+		break;
+	default:
+		goto had_error;
+	}
 
-	if ((old ? old_style() : new_style()) < 0)
-		goto internal;
+	store_num(, s.num_fmt, val);
 
-	if (s.in_angle_brackets)
-		store(, '>');
-	finish_buffer();
-	return (int)(s.total_len - 1);
-internal:
+	if ((old ? old_style() : new_style()) < 0) {
+had_error:
 #ifndef _KERNEL
-	errno = EINVAL;
+		errno = EINVAL;
 #endif
-	store(, '#');
+		had_error = 1;
+		store(, '#');
+	} else if (s.in_angle_brackets)
+		store(, '>');
 	finish_buffer();
-	return -1;
+	return had_error ? -1 : (int)(s.total_len - 1);
 }
 
 int



CVS commit: src

2024-03-04 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Mon Mar  4 21:35:28 UTC 2024

Modified Files:
src/common/lib/libutil: snprintb.c
src/tests/lib/libutil: t_snprintb.c

Log Message:
snprintb: error out on unknown new-style formatting directive


To generate a diff of this commit:
cvs rdiff -u -r1.41 -r1.42 src/common/lib/libutil/snprintb.c
cvs rdiff -u -r1.29 -r1.30 src/tests/lib/libutil/t_snprintb.c

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

Modified files:

Index: src/common/lib/libutil/snprintb.c
diff -u src/common/lib/libutil/snprintb.c:1.41 src/common/lib/libutil/snprintb.c:1.42
--- src/common/lib/libutil/snprintb.c:1.41	Sat Feb 24 12:44:11 2024
+++ src/common/lib/libutil/snprintb.c	Mon Mar  4 21:35:28 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: snprintb.c,v 1.41 2024/02/24 12:44:11 rillig Exp $	*/
+/*	$NetBSD: snprintb.c,v 1.42 2024/03/04 21:35:28 rillig Exp $	*/
 
 /*-
  * Copyright (c) 2002, 2024 The NetBSD Foundation, Inc.
@@ -35,7 +35,7 @@
 
 #  include 
 #  if defined(LIBC_SCCS)
-__RCSID("$NetBSD: snprintb.c,v 1.41 2024/02/24 12:44:11 rillig Exp $");
+__RCSID("$NetBSD: snprintb.c,v 1.42 2024/03/04 21:35:28 rillig Exp $");
 #  endif
 
 #  include 
@@ -45,7 +45,7 @@ __RCSID("$NetBSD: snprintb.c,v 1.41 2024
 #  include 
 # else /* ! _KERNEL */
 #  include 
-__KERNEL_RCSID(0, "$NetBSD: snprintb.c,v 1.41 2024/02/24 12:44:11 rillig Exp $");
+__KERNEL_RCSID(0, "$NetBSD: snprintb.c,v 1.42 2024/03/04 21:35:28 rillig Exp $");
 #  include 
 #  include 
 #  include 
@@ -215,7 +215,7 @@ new_style(state *s)
 			maybe_wrap_line(s, prev_bitfmt);
 			goto skip_description;
 		default:
-			s->bitfmt += 2;
+			return -1;
 		skip_description:
 			while (*s->bitfmt++ != '\0')
 continue;

Index: src/tests/lib/libutil/t_snprintb.c
diff -u src/tests/lib/libutil/t_snprintb.c:1.29 src/tests/lib/libutil/t_snprintb.c:1.30
--- src/tests/lib/libutil/t_snprintb.c:1.29	Sat Feb 24 13:00:00 2024
+++ src/tests/lib/libutil/t_snprintb.c	Mon Mar  4 21:35:28 2024
@@ -1,4 +1,4 @@
-/* $NetBSD: t_snprintb.c,v 1.29 2024/02/24 13:00:00 rillig Exp $ */
+/* $NetBSD: t_snprintb.c,v 1.30 2024/03/04 21:35:28 rillig Exp $ */
 
 /*
  * Copyright (c) 2002, 2004, 2008, 2010, 2024 The NetBSD Foundation, Inc.
@@ -32,7 +32,7 @@
 #include 
 __COPYRIGHT("@(#) Copyright (c) 2008, 2010, 2024\
  The NetBSD Foundation, inc. All rights reserved.");
-__RCSID("$NetBSD: t_snprintb.c,v 1.29 2024/02/24 13:00:00 rillig Exp $");
+__RCSID("$NetBSD: t_snprintb.c,v 1.30 2024/03/04 21:35:28 rillig Exp $");
 
 #include 
 #include 
@@ -807,18 +807,24 @@ ATF_TC_BODY(snprintb, tc)
 	0xff,
 	"0xff");
 
-	// new style unknown directive
-	//
-	// Unknown directives are assumed to have a single byte argument
-	// followed by a description; they are skipped up to the next '\0'.
-	h_snprintb(
+	// new style unknown directive, at the beginning
+	h_snprintb_len(
+	128,
+	"\177\020"
+	"unknown\0",
+	0xff,
+	-1,
+	"0xff#");
+
+	// new style unknown directive, after a known directive
+	h_snprintb_len(
+	128,
 	"\177\020"
-	"c\010ignored\0"
-	"c\000b\0"
-	"lsb\0"
-	"b\007msb\0",
+	"b\007msb\0"
+	"unknown\0",
 	0xff,
-	"0xff");
+	-1,
+	"0xff

CVS commit: src

2024-03-04 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Mon Mar  4 21:35:28 UTC 2024

Modified Files:
src/common/lib/libutil: snprintb.c
src/tests/lib/libutil: t_snprintb.c

Log Message:
snprintb: error out on unknown new-style formatting directive


To generate a diff of this commit:
cvs rdiff -u -r1.41 -r1.42 src/common/lib/libutil/snprintb.c
cvs rdiff -u -r1.29 -r1.30 src/tests/lib/libutil/t_snprintb.c

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



CVS commit: src

2024-03-03 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sun Mar  3 16:09:01 UTC 2024

Modified Files:
src/tests/usr.bin/xlint/lint1: msg_363.c
src/usr.bin/xlint/lint1: ckgetopt.c cksnprintb.c emit1.c init.c lex.c
lint1.h tree.c

Log Message:
lint: clean up string parsing and snprintb check


To generate a diff of this commit:
cvs rdiff -u -r1.3 -r1.4 src/tests/usr.bin/xlint/lint1/msg_363.c
cvs rdiff -u -r1.24 -r1.25 src/usr.bin/xlint/lint1/ckgetopt.c
cvs rdiff -u -r1.6 -r1.7 src/usr.bin/xlint/lint1/cksnprintb.c
cvs rdiff -u -r1.89 -r1.90 src/usr.bin/xlint/lint1/emit1.c
cvs rdiff -u -r1.260 -r1.261 src/usr.bin/xlint/lint1/init.c
cvs rdiff -u -r1.221 -r1.222 src/usr.bin/xlint/lint1/lex.c
cvs rdiff -u -r1.214 -r1.215 src/usr.bin/xlint/lint1/lint1.h
cvs rdiff -u -r1.608 -r1.609 src/usr.bin/xlint/lint1/tree.c

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



CVS commit: src

2024-03-03 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sun Mar  3 16:09:01 UTC 2024

Modified Files:
src/tests/usr.bin/xlint/lint1: msg_363.c
src/usr.bin/xlint/lint1: ckgetopt.c cksnprintb.c emit1.c init.c lex.c
lint1.h tree.c

Log Message:
lint: clean up string parsing and snprintb check


To generate a diff of this commit:
cvs rdiff -u -r1.3 -r1.4 src/tests/usr.bin/xlint/lint1/msg_363.c
cvs rdiff -u -r1.24 -r1.25 src/usr.bin/xlint/lint1/ckgetopt.c
cvs rdiff -u -r1.6 -r1.7 src/usr.bin/xlint/lint1/cksnprintb.c
cvs rdiff -u -r1.89 -r1.90 src/usr.bin/xlint/lint1/emit1.c
cvs rdiff -u -r1.260 -r1.261 src/usr.bin/xlint/lint1/init.c
cvs rdiff -u -r1.221 -r1.222 src/usr.bin/xlint/lint1/lex.c
cvs rdiff -u -r1.214 -r1.215 src/usr.bin/xlint/lint1/lint1.h
cvs rdiff -u -r1.608 -r1.609 src/usr.bin/xlint/lint1/tree.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/xlint/lint1/msg_363.c
diff -u src/tests/usr.bin/xlint/lint1/msg_363.c:1.3 src/tests/usr.bin/xlint/lint1/msg_363.c:1.4
--- src/tests/usr.bin/xlint/lint1/msg_363.c:1.3	Sun Mar  3 13:09:23 2024
+++ src/tests/usr.bin/xlint/lint1/msg_363.c	Sun Mar  3 16:09:01 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: msg_363.c,v 1.3 2024/03/03 13:09:23 rillig Exp $	*/
+/*	$NetBSD: msg_363.c,v 1.4 2024/03/03 16:09:01 rillig Exp $	*/
 # 3 "msg_363.c"
 
 // Test for message: non-printing character '%.*s' in description '%.*s' [363]
@@ -29,6 +29,18 @@ old_style_description(unsigned u32)
 	"\001non\tprint\nable\377",
 	u32);
 
+	/* expect+10: warning: non-printing character '\177' in description '\177' [363] */
+	/* expect+9: warning: non-printing character '\177' in description 'aa\177' [363] */
+	/* expect+8: warning: non-printing character '\177' in description 'bb""\177' [363] */
+	/* expect+7: warning: non-printing character '\177' in description 'cc\177' [363] */
+	snprintb(buf, sizeof(buf),
+	"\020"
+	"\002""\177"
+	"\003aa\177"
+	"\004""bb""\177"
+	"\005cc\177",
+	u32);
+
 	/* expect+6: warning: bit position '\000' (0) in '\000print' out of range 1..32 [371] */
 	/* expect+5: warning: bit position '\n' in '\nable' should be escaped as octal or hex [369] */
 	/* expect+4: warning: redundant '\0' at the end of the format [377] */

Index: src/usr.bin/xlint/lint1/ckgetopt.c
diff -u src/usr.bin/xlint/lint1/ckgetopt.c:1.24 src/usr.bin/xlint/lint1/ckgetopt.c:1.25
--- src/usr.bin/xlint/lint1/ckgetopt.c:1.24	Fri Mar  1 21:52:48 2024
+++ src/usr.bin/xlint/lint1/ckgetopt.c	Sun Mar  3 16:09:01 2024
@@ -1,4 +1,4 @@
-/* $NetBSD: ckgetopt.c,v 1.24 2024/03/01 21:52:48 rillig Exp $ */
+/* $NetBSD: ckgetopt.c,v 1.25 2024/03/03 16:09:01 rillig Exp $ */
 
 /*-
  * Copyright (c) 2021 The NetBSD Foundation, Inc.
@@ -35,7 +35,7 @@
 
 #include 
 #if defined(__RCSID)
-__RCSID("$NetBSD: ckgetopt.c,v 1.24 2024/03/01 21:52:48 rillig Exp $");
+__RCSID("$NetBSD: ckgetopt.c,v 1.25 2024/03/03 16:09:01 rillig Exp $");
 #endif
 
 #include 
@@ -105,7 +105,7 @@ is_getopt_condition(const tnode_t *tn, c
 	&& (str = last_arg->tn_left->tn_left->tn_string)->data != NULL) {
 		buffer buf;
 		buf_init();
-		quoted_iterator it = { .i = 0 };
+		quoted_iterator it = { .end = 0 };
 		while (quoted_next(str, ))
 			buf_add_char(, (char)it.value);
 		*out_options = buf.data;

Index: src/usr.bin/xlint/lint1/cksnprintb.c
diff -u src/usr.bin/xlint/lint1/cksnprintb.c:1.6 src/usr.bin/xlint/lint1/cksnprintb.c:1.7
--- src/usr.bin/xlint/lint1/cksnprintb.c:1.6	Sun Mar  3 13:09:22 2024
+++ src/usr.bin/xlint/lint1/cksnprintb.c	Sun Mar  3 16:09:01 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: cksnprintb.c,v 1.6 2024/03/03 13:09:22 rillig Exp $	*/
+/*	$NetBSD: cksnprintb.c,v 1.7 2024/03/03 16:09:01 rillig Exp $	*/
 
 /*-
  * Copyright (c) 2024 The NetBSD Foundation, Inc.
@@ -35,7 +35,7 @@
 
 #include 
 #if defined(__RCSID)
-__RCSID("$NetBSD: cksnprintb.c,v 1.6 2024/03/03 13:09:22 rillig Exp $");
+__RCSID("$NetBSD: cksnprintb.c,v 1.7 2024/03/03 16:09:01 rillig Exp $");
 #endif
 
 #include 
@@ -90,13 +90,13 @@ match_snprintb_call(const function_call 
 static int
 len(quoted_iterator it)
 {
-	return (int)(it.i - it.start);
+	return (int)(it.end - it.start);
 }
 
 static int
 range(quoted_iterator start, quoted_iterator end)
 {
-	return (int)(end.i - start.start);
+	return (int)(end.end - start.start);
 }
 
 static const char *
@@ -117,7 +117,7 @@ check_hex_escape(const buffer *buf, quot
 	if (it.hex_digits > 1) {
 		bool upper = false;
 		bool lower = false;
-		for (size_t i = it.start + 2; i < it.i; i++) {
+		for (size_t i = it.start + 2; i < it.end; i++) {
 			if (isupper((unsigned char)buf->data[i]))
 upper = true;
 			if (islower((unsigned char)buf->data[i]))
@@ -181,31 +181,28 @@ check_reachable(checker *ck, uint64_t di
 		warning(378, (int)(end - start), ck->fmt->data + start);
 }
 
-static void
-parse_description(checker *ck, bool *seen_null, bool *descr_empty)

CVS commit: src

2024-03-03 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sun Mar  3 13:09:23 UTC 2024

Modified Files:
src/tests/usr.bin/xlint/lint1: msg_358.c msg_362.c msg_363.c msg_372.c
msg_373.c msg_374.c msg_377.c
src/usr.bin/xlint/lint1: cksnprintb.c err.c

Log Message:
lint: warn about escaped snprintb directive

Repurpose message 362, as the previous version was redundant since null
bytes in old-style formats are already covered by message 371 (bit
position out of range) and 377 (redundant '\0' at the end).


To generate a diff of this commit:
cvs rdiff -u -r1.1 -r1.2 src/tests/usr.bin/xlint/lint1/msg_358.c \
src/tests/usr.bin/xlint/lint1/msg_362.c
cvs rdiff -u -r1.2 -r1.3 src/tests/usr.bin/xlint/lint1/msg_363.c \
src/tests/usr.bin/xlint/lint1/msg_372.c \
src/tests/usr.bin/xlint/lint1/msg_373.c \
src/tests/usr.bin/xlint/lint1/msg_377.c
cvs rdiff -u -r1.3 -r1.4 src/tests/usr.bin/xlint/lint1/msg_374.c
cvs rdiff -u -r1.5 -r1.6 src/usr.bin/xlint/lint1/cksnprintb.c
cvs rdiff -u -r1.230 -r1.231 src/usr.bin/xlint/lint1/err.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/xlint/lint1/msg_358.c
diff -u src/tests/usr.bin/xlint/lint1/msg_358.c:1.1 src/tests/usr.bin/xlint/lint1/msg_358.c:1.2
--- src/tests/usr.bin/xlint/lint1/msg_358.c:1.1	Fri Mar  1 19:39:28 2024
+++ src/tests/usr.bin/xlint/lint1/msg_358.c	Sun Mar  3 13:09:23 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: msg_358.c,v 1.1 2024/03/01 19:39:28 rillig Exp $	*/
+/*	$NetBSD: msg_358.c,v 1.2 2024/03/03 13:09:23 rillig Exp $	*/
 # 3 "msg_358.c"
 
 // Test for message: hex escape '%.*s' has more than 2 digits [358]
@@ -49,4 +49,13 @@ examples(unsigned u32, uint64_t u64)
 	snprintb(buf, sizeof(buf),
 	"\177\020f\x00\x02bit\0",
 	u64);
+
+	// In this example from the snprintb manual page, the descriptions
+	// that start with a hexadecimal digit must be separated from the
+	// hexadecimal escape sequence for the bit position.
+	snprintb(buf, sizeof(buf),
+	"\20\x10NOTBOOT\x0f" "FPP\x0eSDVMA\x0cVIDEO"
+	"\x0bLORES\x0a" "FPA\x09" "DIAG\x07" "CACHE"
+	"\x06IOCACHE\x05LOOPBACK\x04" "DBGCACHE",
+	u32);
 }
Index: src/tests/usr.bin/xlint/lint1/msg_362.c
diff -u src/tests/usr.bin/xlint/lint1/msg_362.c:1.1 src/tests/usr.bin/xlint/lint1/msg_362.c:1.2
--- src/tests/usr.bin/xlint/lint1/msg_362.c:1.1	Fri Mar  1 19:39:28 2024
+++ src/tests/usr.bin/xlint/lint1/msg_362.c	Sun Mar  3 13:09:23 2024
@@ -1,11 +1,11 @@
-/*	$NetBSD: msg_362.c,v 1.1 2024/03/01 19:39:28 rillig Exp $	*/
+/*	$NetBSD: msg_362.c,v 1.2 2024/03/03 13:09:23 rillig Exp $	*/
 # 3 "msg_362.c"
 
-// Test for message: old-style format contains '\0' [362]
+// Test for message: directive '%.*s' should not be escaped [362]
 
 /*
- * The old-style format uses 1-based bit positions, from 1 up to 32.
- * A null character would prematurely end the format argument.
+ * Since the characters used for the directive type are chosen to be easily
+ * readable, it doesn't make sense to obfuscate them.
  */
 
 /* lint1-extra-flags: -X 351 */
@@ -20,9 +20,14 @@ example(unsigned u32)
 {
 	char buf[64];
 
-	/* expect+1: warning: bit position '\000' (0) in '\000lsb' out of range 1..32 [371] */
-	snprintb(buf, sizeof(buf), "\020\000lsb\037msb", u32);
-	/* expect+2: warning: old-style format contains '\0' [362] */
-	/* expect+1: warning: bit position '\000' (0) in '\000lsb' out of range 1..32 [371] */
-	snprintb(buf, sizeof(buf), "\020\037msb\000lsb", u32);
+	/* expect+9: warning: directive '\142' should not be escaped [362] */
+	/* expect+8: warning: bit position 'o' in '\142old-style-lsb\0' should be escaped as octal or hex [369] */
+	/* expect+7: warning: bit position 'o' (111) in '\142old-style-lsb\0' out of range 0..63 [371] */
+	/* expect+6: warning: unknown directive '\001', must be one of 'bfF=:*' [374] */
+	snprintb(buf, sizeof(buf),
+	"\177\020"
+	"\142old-style-lsb\0"
+	"\001old-style-lsb\0"
+	"\142\000old-style-lsb\0",
+	u32);
 }

Index: src/tests/usr.bin/xlint/lint1/msg_363.c
diff -u src/tests/usr.bin/xlint/lint1/msg_363.c:1.2 src/tests/usr.bin/xlint/lint1/msg_363.c:1.3
--- src/tests/usr.bin/xlint/lint1/msg_363.c:1.2	Sun Mar  3 10:27:18 2024
+++ src/tests/usr.bin/xlint/lint1/msg_363.c	Sun Mar  3 13:09:23 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: msg_363.c,v 1.2 2024/03/03 10:27:18 rillig Exp $	*/
+/*	$NetBSD: msg_363.c,v 1.3 2024/03/03 13:09:23 rillig Exp $	*/
 # 3 "msg_363.c"
 
 // Test for message: non-printing character '%.*s' in description '%.*s' [363]
@@ -29,9 +29,7 @@ old_style_description(unsigned u32)
 	"\001non\tprint\nable\377",
 	u32);
 
-	/* expect+8: warning: old-style format contains '\0' [362] */
-	/* expect+7: warning: bit position '\000' (0) in '\000print' out of range 1..32 [371] */
-	/* expect+6: warning: old-style format contains '\0' [362] */
+	/* expect+6: warning: bit position '\000' (0) in '\000print' out of range 1..32 

CVS commit: src

2024-03-03 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sun Mar  3 13:09:23 UTC 2024

Modified Files:
src/tests/usr.bin/xlint/lint1: msg_358.c msg_362.c msg_363.c msg_372.c
msg_373.c msg_374.c msg_377.c
src/usr.bin/xlint/lint1: cksnprintb.c err.c

Log Message:
lint: warn about escaped snprintb directive

Repurpose message 362, as the previous version was redundant since null
bytes in old-style formats are already covered by message 371 (bit
position out of range) and 377 (redundant '\0' at the end).


To generate a diff of this commit:
cvs rdiff -u -r1.1 -r1.2 src/tests/usr.bin/xlint/lint1/msg_358.c \
src/tests/usr.bin/xlint/lint1/msg_362.c
cvs rdiff -u -r1.2 -r1.3 src/tests/usr.bin/xlint/lint1/msg_363.c \
src/tests/usr.bin/xlint/lint1/msg_372.c \
src/tests/usr.bin/xlint/lint1/msg_373.c \
src/tests/usr.bin/xlint/lint1/msg_377.c
cvs rdiff -u -r1.3 -r1.4 src/tests/usr.bin/xlint/lint1/msg_374.c
cvs rdiff -u -r1.5 -r1.6 src/usr.bin/xlint/lint1/cksnprintb.c
cvs rdiff -u -r1.230 -r1.231 src/usr.bin/xlint/lint1/err.c

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



CVS commit: src

2024-03-03 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sun Mar  3 10:27:18 UTC 2024

Modified Files:
src/tests/usr.bin/xlint/lint1: msg_363.c msg_364.c msg_365.c msg_366.c
msg_367.c msg_374.c msg_377.c
src/usr.bin/xlint/lint1: cksnprintb.c err.c

Log Message:
lint: fix warning about "empty" single-letter snprintb descriptions


To generate a diff of this commit:
cvs rdiff -u -r1.1 -r1.2 src/tests/usr.bin/xlint/lint1/msg_363.c \
src/tests/usr.bin/xlint/lint1/msg_364.c \
src/tests/usr.bin/xlint/lint1/msg_365.c \
src/tests/usr.bin/xlint/lint1/msg_367.c \
src/tests/usr.bin/xlint/lint1/msg_377.c
cvs rdiff -u -r1.2 -r1.3 src/tests/usr.bin/xlint/lint1/msg_366.c \
src/tests/usr.bin/xlint/lint1/msg_374.c
cvs rdiff -u -r1.4 -r1.5 src/usr.bin/xlint/lint1/cksnprintb.c
cvs rdiff -u -r1.229 -r1.230 src/usr.bin/xlint/lint1/err.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/xlint/lint1/msg_363.c
diff -u src/tests/usr.bin/xlint/lint1/msg_363.c:1.1 src/tests/usr.bin/xlint/lint1/msg_363.c:1.2
--- src/tests/usr.bin/xlint/lint1/msg_363.c:1.1	Fri Mar  1 19:39:28 2024
+++ src/tests/usr.bin/xlint/lint1/msg_363.c	Sun Mar  3 10:27:18 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: msg_363.c,v 1.1 2024/03/01 19:39:28 rillig Exp $	*/
+/*	$NetBSD: msg_363.c,v 1.2 2024/03/03 10:27:18 rillig Exp $	*/
 # 3 "msg_363.c"
 
 // Test for message: non-printing character '%.*s' in description '%.*s' [363]
@@ -33,7 +33,7 @@ old_style_description(unsigned u32)
 	/* expect+7: warning: bit position '\000' (0) in '\000print' out of range 1..32 [371] */
 	/* expect+6: warning: old-style format contains '\0' [362] */
 	/* expect+5: warning: bit position '\n' in '\nable' should be escaped as octal or hex [369] */
-	/* expect+4: warning: empty description in '\0' [367] */
+	/* expect+4: warning: redundant '\0' at the end of the format [377] */
 	snprintb(buf, sizeof(buf),
 	"\020"
 	"\001non\000print\nable\0",
Index: src/tests/usr.bin/xlint/lint1/msg_364.c
diff -u src/tests/usr.bin/xlint/lint1/msg_364.c:1.1 src/tests/usr.bin/xlint/lint1/msg_364.c:1.2
--- src/tests/usr.bin/xlint/lint1/msg_364.c:1.1	Fri Mar  1 19:39:28 2024
+++ src/tests/usr.bin/xlint/lint1/msg_364.c	Sun Mar  3 10:27:18 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: msg_364.c,v 1.1 2024/03/01 19:39:28 rillig Exp $	*/
+/*	$NetBSD: msg_364.c,v 1.2 2024/03/03 10:27:18 rillig Exp $	*/
 # 3 "msg_364.c"
 
 // Test for message: missing bit position after '%.*s' [364]
@@ -26,6 +26,7 @@ example(unsigned u32)
 	"b",
 	u32);
 
+	/* expect+5: warning: empty description in 'b\007' [367] */
 	/* expect+4: warning: missing '\0' at the end of 'b\007' [366] */
 	snprintb(buf, sizeof(buf),
 	"\177\020"
Index: src/tests/usr.bin/xlint/lint1/msg_365.c
diff -u src/tests/usr.bin/xlint/lint1/msg_365.c:1.1 src/tests/usr.bin/xlint/lint1/msg_365.c:1.2
--- src/tests/usr.bin/xlint/lint1/msg_365.c:1.1	Fri Mar  1 19:39:28 2024
+++ src/tests/usr.bin/xlint/lint1/msg_365.c	Sun Mar  3 10:27:18 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: msg_365.c,v 1.1 2024/03/01 19:39:28 rillig Exp $	*/
+/*	$NetBSD: msg_365.c,v 1.2 2024/03/03 10:27:18 rillig Exp $	*/
 # 3 "msg_365.c"
 
 // Test for message: missing field width after '%.*s' [365]
@@ -25,6 +25,7 @@ example(unsigned u32)
 	"f\000",
 	u32);
 
+	/* expect+5: warning: empty description in 'f\007\010' [367] */
 	/* expect+4: warning: missing '\0' at the end of 'f\007\010' [366] */
 	snprintb(buf, sizeof(buf),
 	"\177\020"
Index: src/tests/usr.bin/xlint/lint1/msg_367.c
diff -u src/tests/usr.bin/xlint/lint1/msg_367.c:1.1 src/tests/usr.bin/xlint/lint1/msg_367.c:1.2
--- src/tests/usr.bin/xlint/lint1/msg_367.c:1.1	Fri Mar  1 19:39:28 2024
+++ src/tests/usr.bin/xlint/lint1/msg_367.c	Sun Mar  3 10:27:18 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: msg_367.c,v 1.1 2024/03/01 19:39:28 rillig Exp $	*/
+/*	$NetBSD: msg_367.c,v 1.2 2024/03/03 10:27:18 rillig Exp $	*/
 # 3 "msg_367.c"
 
 // Test for message: empty description in '%.*s' [367]
@@ -18,7 +18,46 @@ typedef unsigned long long uint64_t;
 int snprintb(char*, size_t, const char*, uint64_t);
 
 void
-example(unsigned u32)
+old_style(unsigned u32)
+{
+	char buf[64];
+
+	/* expect+10: warning: empty description in '\001' [367] */
+	/* expect+9: warning: empty description in '\002' [367] */
+	/* expect+8: warning: empty description in '\003' [367] */
+	/* expect+7: warning: empty description in '\004' [367] */
+	snprintb(buf, sizeof(buf),
+	"\020"
+	"\001"
+	"\002"
+	"\003"
+	"\004",
+	u32);
+
+	/* expect+10: warning: empty description in '\001' [367] */
+	/* expect+9: warning: empty description in '\002' [367] */
+	/* expect+8: warning: empty description in '\003' [367] */
+	/* expect+7: warning: empty description in '\004' [367] */
+	snprintb(buf, sizeof(buf),
+	"\020"
+	"\001" "" ""
+	"\002" "" ""
+	"\003" "" ""
+	"\004" "" "",
+	u32);
+
+	// 

CVS commit: src

2024-03-03 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sun Mar  3 10:27:18 UTC 2024

Modified Files:
src/tests/usr.bin/xlint/lint1: msg_363.c msg_364.c msg_365.c msg_366.c
msg_367.c msg_374.c msg_377.c
src/usr.bin/xlint/lint1: cksnprintb.c err.c

Log Message:
lint: fix warning about "empty" single-letter snprintb descriptions


To generate a diff of this commit:
cvs rdiff -u -r1.1 -r1.2 src/tests/usr.bin/xlint/lint1/msg_363.c \
src/tests/usr.bin/xlint/lint1/msg_364.c \
src/tests/usr.bin/xlint/lint1/msg_365.c \
src/tests/usr.bin/xlint/lint1/msg_367.c \
src/tests/usr.bin/xlint/lint1/msg_377.c
cvs rdiff -u -r1.2 -r1.3 src/tests/usr.bin/xlint/lint1/msg_366.c \
src/tests/usr.bin/xlint/lint1/msg_374.c
cvs rdiff -u -r1.4 -r1.5 src/usr.bin/xlint/lint1/cksnprintb.c
cvs rdiff -u -r1.229 -r1.230 src/usr.bin/xlint/lint1/err.c

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



CVS commit: src

2024-03-02 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sun Mar  3 00:50:42 UTC 2024

Modified Files:
src/distrib/sets/lists/tests: mi
src/tests/usr.bin/xlint/lint1: msg_360.c msg_361.c msg_366.c msg_374.c
msg_375.c msg_376.c t_usage.sh
src/usr.bin/xlint/lint1: cksnprintb.c err.c externs1.h tree.c
Added Files:
src/tests/usr.bin/xlint/lint1: msg_377.c msg_378.c

Log Message:
lint: check for unreachable bits and fields in snprintb formats

While here, clean up a few existing checks.


To generate a diff of this commit:
cvs rdiff -u -r1.1308 -r1.1309 src/distrib/sets/lists/tests/mi
cvs rdiff -u -r1.1 -r1.2 src/tests/usr.bin/xlint/lint1/msg_360.c \
src/tests/usr.bin/xlint/lint1/msg_361.c \
src/tests/usr.bin/xlint/lint1/msg_366.c \
src/tests/usr.bin/xlint/lint1/msg_374.c \
src/tests/usr.bin/xlint/lint1/msg_376.c
cvs rdiff -u -r1.2 -r1.3 src/tests/usr.bin/xlint/lint1/msg_375.c
cvs rdiff -u -r0 -r1.1 src/tests/usr.bin/xlint/lint1/msg_377.c \
src/tests/usr.bin/xlint/lint1/msg_378.c
cvs rdiff -u -r1.17 -r1.18 src/tests/usr.bin/xlint/lint1/t_usage.sh
cvs rdiff -u -r1.3 -r1.4 src/usr.bin/xlint/lint1/cksnprintb.c
cvs rdiff -u -r1.228 -r1.229 src/usr.bin/xlint/lint1/err.c
cvs rdiff -u -r1.217 -r1.218 src/usr.bin/xlint/lint1/externs1.h
cvs rdiff -u -r1.607 -r1.608 src/usr.bin/xlint/lint1/tree.c

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/tests/mi
diff -u src/distrib/sets/lists/tests/mi:1.1308 src/distrib/sets/lists/tests/mi:1.1309
--- src/distrib/sets/lists/tests/mi:1.1308	Sat Mar  2 11:56:37 2024
+++ src/distrib/sets/lists/tests/mi	Sun Mar  3 00:50:41 2024
@@ -1,4 +1,4 @@
-# $NetBSD: mi,v 1.1308 2024/03/02 11:56:37 rillig Exp $
+# $NetBSD: mi,v 1.1309 2024/03/03 00:50:41 rillig Exp $
 #
 # Note: don't delete entries from here - mark them as "obsolete" instead.
 #
@@ -7491,6 +7491,8 @@
 ./usr/tests/usr.bin/xlint/lint1/msg_374.c			tests-usr.bin-tests	compattestfile,atf
 ./usr/tests/usr.bin/xlint/lint1/msg_375.c			tests-usr.bin-tests	compattestfile,atf
 ./usr/tests/usr.bin/xlint/lint1/msg_376.c			tests-usr.bin-tests	compattestfile,atf
+./usr/tests/usr.bin/xlint/lint1/msg_377.c			tests-usr.bin-tests	compattestfile,atf
+./usr/tests/usr.bin/xlint/lint1/msg_378.c			tests-usr.bin-tests	compattestfile,atf
 ./usr/tests/usr.bin/xlint/lint1/op_colon.c			tests-usr.bin-tests	compattestfile,atf
 ./usr/tests/usr.bin/xlint/lint1/op_colon.exp			tests-obsolete		obsolete,atf
 ./usr/tests/usr.bin/xlint/lint1/op_shl_lp64.c			tests-usr.bin-tests	compattestfile,atf

Index: src/tests/usr.bin/xlint/lint1/msg_360.c
diff -u src/tests/usr.bin/xlint/lint1/msg_360.c:1.1 src/tests/usr.bin/xlint/lint1/msg_360.c:1.2
--- src/tests/usr.bin/xlint/lint1/msg_360.c:1.1	Fri Mar  1 19:39:28 2024
+++ src/tests/usr.bin/xlint/lint1/msg_360.c	Sun Mar  3 00:50:41 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: msg_360.c,v 1.1 2024/03/01 19:39:28 rillig Exp $	*/
+/*	$NetBSD: msg_360.c,v 1.2 2024/03/03 00:50:41 rillig Exp $	*/
 # 3 "msg_360.c"
 
 // Test for message: missing new-style number base after '\177' [360]
@@ -23,6 +23,6 @@ new_style_number_base(void)
 
 	/* expect+1: warning: missing new-style number base after '\177' [360] */
 	snprintb(buf, sizeof(buf), "\177", 0);
-	/* expect+1: warning: number base '\002' is 2, should be 8, 10 or 16 [361] */
+	/* expect+1: warning: number base '\002' is 2, must be 8, 10 or 16 [361] */
 	snprintb(buf, sizeof(buf), "\177\002", 0);
 }
Index: src/tests/usr.bin/xlint/lint1/msg_361.c
diff -u src/tests/usr.bin/xlint/lint1/msg_361.c:1.1 src/tests/usr.bin/xlint/lint1/msg_361.c:1.2
--- src/tests/usr.bin/xlint/lint1/msg_361.c:1.1	Fri Mar  1 19:39:28 2024
+++ src/tests/usr.bin/xlint/lint1/msg_361.c	Sun Mar  3 00:50:41 2024
@@ -1,7 +1,7 @@
-/*	$NetBSD: msg_361.c,v 1.1 2024/03/01 19:39:28 rillig Exp $	*/
+/*	$NetBSD: msg_361.c,v 1.2 2024/03/03 00:50:41 rillig Exp $	*/
 # 3 "msg_361.c"
 
-// Test for message: number base '%.*s' is %ju, should be 8, 10 or 16 [361]
+// Test for message: number base '%.*s' is %ju, must be 8, 10 or 16 [361]
 
 /*
  * The first or second character of the snprintb format specifies the number
@@ -22,12 +22,12 @@ old_style_number_base(void)
 
 	/* expect+1: warning: missing new-style '\177' or old-style number base [359] */
 	snprintb(buf, sizeof(buf), "", 0);
-	/* expect+1: warning: number base '\002' is 2, should be 8, 10 or 16 [361] */
+	/* expect+1: warning: number base '\002' is 2, must be 8, 10 or 16 [361] */
 	snprintb(buf, sizeof(buf), "\002", 0);
 	snprintb(buf, sizeof(buf), "\010", 0);
 	snprintb(buf, sizeof(buf), "\n", 0);
 	snprintb(buf, sizeof(buf), "\020", 0);
-	/* expect+1: warning: number base '\014' is 12, should be 8, 10 or 16 [361] */
+	/* expect+1: warning: number base '\014' is 12, must be 8, 10 or 16 [361] */
 	snprintb(buf, sizeof(buf), "" "\014" "", 0);
 	snprintb(buf, sizeof(buf), "" "\020" "", 0);
 }
@@ -39,14 +39,14 

CVS commit: src

2024-03-02 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sun Mar  3 00:50:42 UTC 2024

Modified Files:
src/distrib/sets/lists/tests: mi
src/tests/usr.bin/xlint/lint1: msg_360.c msg_361.c msg_366.c msg_374.c
msg_375.c msg_376.c t_usage.sh
src/usr.bin/xlint/lint1: cksnprintb.c err.c externs1.h tree.c
Added Files:
src/tests/usr.bin/xlint/lint1: msg_377.c msg_378.c

Log Message:
lint: check for unreachable bits and fields in snprintb formats

While here, clean up a few existing checks.


To generate a diff of this commit:
cvs rdiff -u -r1.1308 -r1.1309 src/distrib/sets/lists/tests/mi
cvs rdiff -u -r1.1 -r1.2 src/tests/usr.bin/xlint/lint1/msg_360.c \
src/tests/usr.bin/xlint/lint1/msg_361.c \
src/tests/usr.bin/xlint/lint1/msg_366.c \
src/tests/usr.bin/xlint/lint1/msg_374.c \
src/tests/usr.bin/xlint/lint1/msg_376.c
cvs rdiff -u -r1.2 -r1.3 src/tests/usr.bin/xlint/lint1/msg_375.c
cvs rdiff -u -r0 -r1.1 src/tests/usr.bin/xlint/lint1/msg_377.c \
src/tests/usr.bin/xlint/lint1/msg_378.c
cvs rdiff -u -r1.17 -r1.18 src/tests/usr.bin/xlint/lint1/t_usage.sh
cvs rdiff -u -r1.3 -r1.4 src/usr.bin/xlint/lint1/cksnprintb.c
cvs rdiff -u -r1.228 -r1.229 src/usr.bin/xlint/lint1/err.c
cvs rdiff -u -r1.217 -r1.218 src/usr.bin/xlint/lint1/externs1.h
cvs rdiff -u -r1.607 -r1.608 src/usr.bin/xlint/lint1/tree.c

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



CVS commit: src

2024-03-02 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sat Mar  2 11:56:37 UTC 2024

Modified Files:
src/distrib/sets/lists/tests: mi
src/tests/usr.bin/xlint/lint1: msg_369.c msg_370.c msg_372.c msg_373.c
msg_375.c t_usage.sh
src/usr.bin/xlint/lint1: cksnprintb.c err.c
Added Files:
src/tests/usr.bin/xlint/lint1: msg_376.c

Log Message:
lint: check snprintb formats for overlapping bits and fields


To generate a diff of this commit:
cvs rdiff -u -r1.1307 -r1.1308 src/distrib/sets/lists/tests/mi
cvs rdiff -u -r1.1 -r1.2 src/tests/usr.bin/xlint/lint1/msg_369.c \
src/tests/usr.bin/xlint/lint1/msg_370.c \
src/tests/usr.bin/xlint/lint1/msg_372.c \
src/tests/usr.bin/xlint/lint1/msg_373.c \
src/tests/usr.bin/xlint/lint1/msg_375.c
cvs rdiff -u -r0 -r1.1 src/tests/usr.bin/xlint/lint1/msg_376.c
cvs rdiff -u -r1.16 -r1.17 src/tests/usr.bin/xlint/lint1/t_usage.sh
cvs rdiff -u -r1.2 -r1.3 src/usr.bin/xlint/lint1/cksnprintb.c
cvs rdiff -u -r1.227 -r1.228 src/usr.bin/xlint/lint1/err.c

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



CVS commit: src

2024-03-02 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sat Mar  2 11:56:37 UTC 2024

Modified Files:
src/distrib/sets/lists/tests: mi
src/tests/usr.bin/xlint/lint1: msg_369.c msg_370.c msg_372.c msg_373.c
msg_375.c t_usage.sh
src/usr.bin/xlint/lint1: cksnprintb.c err.c
Added Files:
src/tests/usr.bin/xlint/lint1: msg_376.c

Log Message:
lint: check snprintb formats for overlapping bits and fields


To generate a diff of this commit:
cvs rdiff -u -r1.1307 -r1.1308 src/distrib/sets/lists/tests/mi
cvs rdiff -u -r1.1 -r1.2 src/tests/usr.bin/xlint/lint1/msg_369.c \
src/tests/usr.bin/xlint/lint1/msg_370.c \
src/tests/usr.bin/xlint/lint1/msg_372.c \
src/tests/usr.bin/xlint/lint1/msg_373.c \
src/tests/usr.bin/xlint/lint1/msg_375.c
cvs rdiff -u -r0 -r1.1 src/tests/usr.bin/xlint/lint1/msg_376.c
cvs rdiff -u -r1.16 -r1.17 src/tests/usr.bin/xlint/lint1/t_usage.sh
cvs rdiff -u -r1.2 -r1.3 src/usr.bin/xlint/lint1/cksnprintb.c
cvs rdiff -u -r1.227 -r1.228 src/usr.bin/xlint/lint1/err.c

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/tests/mi
diff -u src/distrib/sets/lists/tests/mi:1.1307 src/distrib/sets/lists/tests/mi:1.1308
--- src/distrib/sets/lists/tests/mi:1.1307	Fri Mar  1 19:39:28 2024
+++ src/distrib/sets/lists/tests/mi	Sat Mar  2 11:56:37 2024
@@ -1,4 +1,4 @@
-# $NetBSD: mi,v 1.1307 2024/03/01 19:39:28 rillig Exp $
+# $NetBSD: mi,v 1.1308 2024/03/02 11:56:37 rillig Exp $
 #
 # Note: don't delete entries from here - mark them as "obsolete" instead.
 #
@@ -7490,6 +7490,7 @@
 ./usr/tests/usr.bin/xlint/lint1/msg_373.c			tests-usr.bin-tests	compattestfile,atf
 ./usr/tests/usr.bin/xlint/lint1/msg_374.c			tests-usr.bin-tests	compattestfile,atf
 ./usr/tests/usr.bin/xlint/lint1/msg_375.c			tests-usr.bin-tests	compattestfile,atf
+./usr/tests/usr.bin/xlint/lint1/msg_376.c			tests-usr.bin-tests	compattestfile,atf
 ./usr/tests/usr.bin/xlint/lint1/op_colon.c			tests-usr.bin-tests	compattestfile,atf
 ./usr/tests/usr.bin/xlint/lint1/op_colon.exp			tests-obsolete		obsolete,atf
 ./usr/tests/usr.bin/xlint/lint1/op_shl_lp64.c			tests-usr.bin-tests	compattestfile,atf

Index: src/tests/usr.bin/xlint/lint1/msg_369.c
diff -u src/tests/usr.bin/xlint/lint1/msg_369.c:1.1 src/tests/usr.bin/xlint/lint1/msg_369.c:1.2
--- src/tests/usr.bin/xlint/lint1/msg_369.c:1.1	Fri Mar  1 19:39:29 2024
+++ src/tests/usr.bin/xlint/lint1/msg_369.c	Sat Mar  2 11:56:37 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: msg_369.c,v 1.1 2024/03/01 19:39:29 rillig Exp $	*/
+/*	$NetBSD: msg_369.c,v 1.2 2024/03/02 11:56:37 rillig Exp $	*/
 # 3 "msg_369.c"
 
 // Test for message: bit position '%.*s' in '%.*s' should be escaped as octal or hex [369]
@@ -42,11 +42,11 @@ example(unsigned u32, uint64_t u64)
 	"b\nnewline\0",
 	u64);
 
-	/* expect+6: warning: bit position '\t' in 'f\t\010tab\0' should be escaped as octal or hex [369] */
-	/* expect+5: warning: bit position '\n' in 'F\n\010newline\0' should be escaped as octal or hex [369] */
+	/* expect+6: warning: bit position '\t' in 'f\t\001tab\0' should be escaped as octal or hex [369] */
+	/* expect+5: warning: bit position '\n' in 'F\n\001newline\0' should be escaped as octal or hex [369] */
 	snprintb(buf, sizeof(buf),
 	"\177\020"
-	"f\t\010tab\0"
-	"F\n\010newline\0",
+	"f\t\001tab\0"
+	"F\n\001newline\0",
 	u64);
 }
Index: src/tests/usr.bin/xlint/lint1/msg_370.c
diff -u src/tests/usr.bin/xlint/lint1/msg_370.c:1.1 src/tests/usr.bin/xlint/lint1/msg_370.c:1.2
--- src/tests/usr.bin/xlint/lint1/msg_370.c:1.1	Fri Mar  1 19:39:29 2024
+++ src/tests/usr.bin/xlint/lint1/msg_370.c	Sat Mar  2 11:56:37 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: msg_370.c,v 1.1 2024/03/01 19:39:29 rillig Exp $	*/
+/*	$NetBSD: msg_370.c,v 1.2 2024/03/02 11:56:37 rillig Exp $	*/
 # 3 "msg_370.c"
 
 // Test for message: field width '%.*s' in '%.*s' should be escaped as octal or hex [370]
@@ -34,6 +34,7 @@ example(uint64_t u64)
 	"f\t\ttab\0"
 	"f\n\nnewline\0",
 	u64);
+	/* expect-1: warning: 'f\n\nnewline\0' overlaps earlier 'f\t\ttab\0' on bit 10 [376] */
 
 	/* expect+11: warning: bit position ' ' in 'F  space\0' should be escaped as octal or hex [369] */
 	/* expect+10: warning: field width ' ' in 'F  space\0' should be escaped as octal or hex [370] */
@@ -47,4 +48,5 @@ example(uint64_t u64)
 	"F\t\ttab\0"
 	"F\n\nnewline\0",
 	u64);
+	/* expect-1: warning: 'F\n\nnewline\0' overlaps earlier 'F\t\ttab\0' on bit 10 [376] */
 }
Index: src/tests/usr.bin/xlint/lint1/msg_372.c
diff -u src/tests/usr.bin/xlint/lint1/msg_372.c:1.1 src/tests/usr.bin/xlint/lint1/msg_372.c:1.2
--- src/tests/usr.bin/xlint/lint1/msg_372.c:1.1	Fri Mar  1 19:39:29 2024
+++ src/tests/usr.bin/xlint/lint1/msg_372.c	Sat Mar  2 11:56:37 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: msg_372.c,v 1.1 2024/03/01 19:39:29 rillig Exp $	*/
+/*	$NetBSD: msg_372.c,v 1.2 2024/03/02 11:56:37 

CVS commit: src/usr.bin/xlint

2024-03-02 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sat Mar  2 09:32:19 UTC 2024

Modified Files:
src/usr.bin/xlint/common: lint.h
src/usr.bin/xlint/lint1: decl.c emit1.c err.c lex.c
src/usr.bin/xlint/lint2: chk.c emit2.c read.c
src/usr.bin/xlint/xlint: xlint.c

Log Message:
lint: remove custom wrappers around  functions


To generate a diff of this commit:
cvs rdiff -u -r1.48 -r1.49 src/usr.bin/xlint/common/lint.h
cvs rdiff -u -r1.393 -r1.394 src/usr.bin/xlint/lint1/decl.c
cvs rdiff -u -r1.88 -r1.89 src/usr.bin/xlint/lint1/emit1.c
cvs rdiff -u -r1.226 -r1.227 src/usr.bin/xlint/lint1/err.c
cvs rdiff -u -r1.220 -r1.221 src/usr.bin/xlint/lint1/lex.c
cvs rdiff -u -r1.65 -r1.66 src/usr.bin/xlint/lint2/chk.c
cvs rdiff -u -r1.37 -r1.38 src/usr.bin/xlint/lint2/emit2.c
cvs rdiff -u -r1.90 -r1.91 src/usr.bin/xlint/lint2/read.c
cvs rdiff -u -r1.122 -r1.123 src/usr.bin/xlint/xlint/xlint.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/xlint/common/lint.h
diff -u src/usr.bin/xlint/common/lint.h:1.48 src/usr.bin/xlint/common/lint.h:1.49
--- src/usr.bin/xlint/common/lint.h:1.48	Thu Feb  1 18:37:06 2024
+++ src/usr.bin/xlint/common/lint.h	Sat Mar  2 09:32:18 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: lint.h,v 1.48 2024/02/01 18:37:06 rillig Exp $	*/
+/*	$NetBSD: lint.h,v 1.49 2024/03/02 09:32:18 rillig Exp $	*/
 
 /*
  * Copyright (c) 1994, 1995 Jochen Pohl
@@ -161,33 +161,3 @@ typedef struct lint2_type type_t;
 #endif
 
 #include "externs.h"
-
-static inline bool
-ch_isalnum(char ch)
-{
-	return isalnum((unsigned char)ch) != 0;
-}
-
-static inline bool
-ch_isdigit(char ch)
-{
-	return isdigit((unsigned char)ch) != 0;
-}
-
-static inline bool
-ch_isprint(char ch)
-{
-	return isprint((unsigned char)ch) != 0;
-}
-
-static inline bool
-ch_isspace(char ch)
-{
-	return isspace((unsigned char)ch) != 0;
-}
-
-static inline bool
-ch_isupper(char ch)
-{
-	return isupper((unsigned char)ch) != 0;
-}

Index: src/usr.bin/xlint/lint1/decl.c
diff -u src/usr.bin/xlint/lint1/decl.c:1.393 src/usr.bin/xlint/lint1/decl.c:1.394
--- src/usr.bin/xlint/lint1/decl.c:1.393	Thu Feb  8 20:59:19 2024
+++ src/usr.bin/xlint/lint1/decl.c	Sat Mar  2 09:32:18 2024
@@ -1,4 +1,4 @@
-/* $NetBSD: decl.c,v 1.393 2024/02/08 20:59:19 rillig Exp $ */
+/* $NetBSD: decl.c,v 1.394 2024/03/02 09:32:18 rillig Exp $ */
 
 /*
  * Copyright (c) 1996 Christopher G. Demetriou.  All Rights Reserved.
@@ -38,7 +38,7 @@
 
 #include 
 #if defined(__RCSID)
-__RCSID("$NetBSD: decl.c,v 1.393 2024/02/08 20:59:19 rillig Exp $");
+__RCSID("$NetBSD: decl.c,v 1.394 2024/03/02 09:32:18 rillig Exp $");
 #endif
 
 #include 
@@ -1776,7 +1776,7 @@ check_extern_declaration(const sym_t *sy
 	dcs->d_redeclared_symbol == NULL &&
 	ends_with(curr_pos.p_file, ".c") &&
 	allow_c90 &&
-	!ch_isdigit(sym->s_name[0]) &&	/* see mktempsym */
+	!isdigit((unsigned char)sym->s_name[0]) &&	/* see mktempsym */
 	strcmp(sym->s_name, "main") != 0) {
 		/* missing%s header declaration for '%s' */
 		warning(351, sym->s_type->t_tspec == FUNC ? "" : " 'extern'",
@@ -2873,7 +2873,7 @@ check_variable_usage(bool novar, const s
 	lint_assert(block_level != 0);
 
 	/* example at file scope: int c = ({ return 3; }); */
-	if (sym->s_block_level == 0 && ch_isdigit(sym->s_name[0]))
+	if (sym->s_block_level == 0 && isdigit((unsigned char)sym->s_name[0]))
 		return;
 
 	/* errors in expressions easily cause lots of these warnings */

Index: src/usr.bin/xlint/lint1/emit1.c
diff -u src/usr.bin/xlint/lint1/emit1.c:1.88 src/usr.bin/xlint/lint1/emit1.c:1.89
--- src/usr.bin/xlint/lint1/emit1.c:1.88	Fri Mar  1 21:52:48 2024
+++ src/usr.bin/xlint/lint1/emit1.c	Sat Mar  2 09:32:18 2024
@@ -1,4 +1,4 @@
-/* $NetBSD: emit1.c,v 1.88 2024/03/01 21:52:48 rillig Exp $ */
+/* $NetBSD: emit1.c,v 1.89 2024/03/02 09:32:18 rillig Exp $ */
 
 /*
  * Copyright (c) 1996 Christopher G. Demetriou.  All Rights Reserved.
@@ -38,7 +38,7 @@
 
 #include 
 #if defined(__RCSID)
-__RCSID("$NetBSD: emit1.c,v 1.88 2024/03/01 21:52:48 rillig Exp $");
+__RCSID("$NetBSD: emit1.c,v 1.89 2024/03/02 09:32:18 rillig Exp $");
 #endif
 
 #include 
@@ -185,7 +185,7 @@ outsym(const sym_t *sym, scl_t sc, def_t
 	 */
 	if (sc != EXTERN && !(sc == STATIC && sym->s_type->t_tspec == FUNC))
 		return;
-	if (ch_isdigit(sym->s_name[0]))	/* _tmp */
+	if (isdigit((unsigned char)sym->s_name[0]))	/* _tmp */
 		return;
 
 	outint(csrc_pos.p_line);
@@ -392,7 +392,7 @@ static void
 outqchar(char c)
 {
 
-	if (ch_isprint(c) && c != '\\' && c != '"' && c != '\'') {
+	if (isprint((unsigned char)c) && c != '\\' && c != '"' && c != '\'') {
 		outchar(c);
 		return;
 	}
@@ -466,7 +466,7 @@ outfstrg(const char *cp)
 		}
 
 		/* numeric field width */
-		while (ch_isdigit(c)) {
+		while (isdigit((unsigned char)c)) {
 			outchar(c);
 			c = *cp++;
 		}
@@ -479,7 +479,7 @@ outfstrg(const char *cp)
 outchar(c);
 c = 

CVS commit: src/usr.bin/xlint

2024-03-02 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sat Mar  2 09:32:19 UTC 2024

Modified Files:
src/usr.bin/xlint/common: lint.h
src/usr.bin/xlint/lint1: decl.c emit1.c err.c lex.c
src/usr.bin/xlint/lint2: chk.c emit2.c read.c
src/usr.bin/xlint/xlint: xlint.c

Log Message:
lint: remove custom wrappers around  functions


To generate a diff of this commit:
cvs rdiff -u -r1.48 -r1.49 src/usr.bin/xlint/common/lint.h
cvs rdiff -u -r1.393 -r1.394 src/usr.bin/xlint/lint1/decl.c
cvs rdiff -u -r1.88 -r1.89 src/usr.bin/xlint/lint1/emit1.c
cvs rdiff -u -r1.226 -r1.227 src/usr.bin/xlint/lint1/err.c
cvs rdiff -u -r1.220 -r1.221 src/usr.bin/xlint/lint1/lex.c
cvs rdiff -u -r1.65 -r1.66 src/usr.bin/xlint/lint2/chk.c
cvs rdiff -u -r1.37 -r1.38 src/usr.bin/xlint/lint2/emit2.c
cvs rdiff -u -r1.90 -r1.91 src/usr.bin/xlint/lint2/read.c
cvs rdiff -u -r1.122 -r1.123 src/usr.bin/xlint/xlint/xlint.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/xlint/lint1

2024-03-01 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Fri Mar  1 21:52:48 UTC 2024

Modified Files:
src/usr.bin/xlint/lint1: ckgetopt.c cksnprintb.c emit1.c init.c lex.c
tree.c

Log Message:
lint: fix misleading initializer for string iterator

The field 'start' marks the start of the previous matching character,
not the current iterator position.

No binary change.


To generate a diff of this commit:
cvs rdiff -u -r1.23 -r1.24 src/usr.bin/xlint/lint1/ckgetopt.c
cvs rdiff -u -r1.1 -r1.2 src/usr.bin/xlint/lint1/cksnprintb.c
cvs rdiff -u -r1.87 -r1.88 src/usr.bin/xlint/lint1/emit1.c
cvs rdiff -u -r1.259 -r1.260 src/usr.bin/xlint/lint1/init.c
cvs rdiff -u -r1.219 -r1.220 src/usr.bin/xlint/lint1/lex.c
cvs rdiff -u -r1.606 -r1.607 src/usr.bin/xlint/lint1/tree.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/xlint/lint1/ckgetopt.c
diff -u src/usr.bin/xlint/lint1/ckgetopt.c:1.23 src/usr.bin/xlint/lint1/ckgetopt.c:1.24
--- src/usr.bin/xlint/lint1/ckgetopt.c:1.23	Mon Feb  5 23:11:22 2024
+++ src/usr.bin/xlint/lint1/ckgetopt.c	Fri Mar  1 21:52:48 2024
@@ -1,4 +1,4 @@
-/* $NetBSD: ckgetopt.c,v 1.23 2024/02/05 23:11:22 rillig Exp $ */
+/* $NetBSD: ckgetopt.c,v 1.24 2024/03/01 21:52:48 rillig Exp $ */
 
 /*-
  * Copyright (c) 2021 The NetBSD Foundation, Inc.
@@ -35,7 +35,7 @@
 
 #include 
 #if defined(__RCSID)
-__RCSID("$NetBSD: ckgetopt.c,v 1.23 2024/02/05 23:11:22 rillig Exp $");
+__RCSID("$NetBSD: ckgetopt.c,v 1.24 2024/03/01 21:52:48 rillig Exp $");
 #endif
 
 #include 
@@ -105,7 +105,7 @@ is_getopt_condition(const tnode_t *tn, c
 	&& (str = last_arg->tn_left->tn_left->tn_string)->data != NULL) {
 		buffer buf;
 		buf_init();
-		quoted_iterator it = { .start = 0 };
+		quoted_iterator it = { .i = 0 };
 		while (quoted_next(str, ))
 			buf_add_char(, (char)it.value);
 		*out_options = buf.data;

Index: src/usr.bin/xlint/lint1/cksnprintb.c
diff -u src/usr.bin/xlint/lint1/cksnprintb.c:1.1 src/usr.bin/xlint/lint1/cksnprintb.c:1.2
--- src/usr.bin/xlint/lint1/cksnprintb.c:1.1	Fri Mar  1 19:40:45 2024
+++ src/usr.bin/xlint/lint1/cksnprintb.c	Fri Mar  1 21:52:48 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: cksnprintb.c,v 1.1 2024/03/01 19:40:45 rillig Exp $	*/
+/*	$NetBSD: cksnprintb.c,v 1.2 2024/03/01 21:52:48 rillig Exp $	*/
 
 /*-
  * Copyright (c) 2024 The NetBSD Foundation, Inc.
@@ -35,7 +35,7 @@
 
 #include 
 #if defined(__RCSID)
-__RCSID("$NetBSD: cksnprintb.c,v 1.1 2024/03/01 19:40:45 rillig Exp $");
+__RCSID("$NetBSD: cksnprintb.c,v 1.2 2024/03/01 21:52:48 rillig Exp $");
 #endif
 
 #include 
@@ -266,7 +266,7 @@ check_snprintb(const tnode_t *expr)
 	if (!match_snprintb_call(expr->tn_call, , ))
 		return;
 
-	quoted_iterator it = { .start = 0 };
+	quoted_iterator it = { .i = 0 };
 	if (!quoted_next(fmt, )) {
 		/* missing new-style '\177' or old-style number base */
 		warning(359);

Index: src/usr.bin/xlint/lint1/emit1.c
diff -u src/usr.bin/xlint/lint1/emit1.c:1.87 src/usr.bin/xlint/lint1/emit1.c:1.88
--- src/usr.bin/xlint/lint1/emit1.c:1.87	Thu Feb  8 20:45:20 2024
+++ src/usr.bin/xlint/lint1/emit1.c	Fri Mar  1 21:52:48 2024
@@ -1,4 +1,4 @@
-/* $NetBSD: emit1.c,v 1.87 2024/02/08 20:45:20 rillig Exp $ */
+/* $NetBSD: emit1.c,v 1.88 2024/03/01 21:52:48 rillig Exp $ */
 
 /*
  * Copyright (c) 1996 Christopher G. Demetriou.  All Rights Reserved.
@@ -38,7 +38,7 @@
 
 #include 
 #if defined(__RCSID)
-__RCSID("$NetBSD: emit1.c,v 1.87 2024/02/08 20:45:20 rillig Exp $");
+__RCSID("$NetBSD: emit1.c,v 1.88 2024/03/01 21:52:48 rillig Exp $");
 #endif
 
 #include 
@@ -362,7 +362,7 @@ outcall(const tnode_t *tn, bool retval_u
 		arg->tn_left->tn_string->data != NULL) {
 			buffer buf;
 			buf_init();
-			quoted_iterator it = { .start = 0 };
+			quoted_iterator it = { .i = 0 };
 			while (quoted_next(arg->tn_left->tn_string, ))
 buf_add_char(, (char)it.value);
 

Index: src/usr.bin/xlint/lint1/init.c
diff -u src/usr.bin/xlint/lint1/init.c:1.259 src/usr.bin/xlint/lint1/init.c:1.260
--- src/usr.bin/xlint/lint1/init.c:1.259	Thu Feb  8 20:45:20 2024
+++ src/usr.bin/xlint/lint1/init.c	Fri Mar  1 21:52:48 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: init.c,v 1.259 2024/02/08 20:45:20 rillig Exp $	*/
+/*	$NetBSD: init.c,v 1.260 2024/03/01 21:52:48 rillig Exp $	*/
 
 /*
  * Copyright (c) 1994, 1995 Jochen Pohl
@@ -38,7 +38,7 @@
 
 #include 
 #if defined(__RCSID)
-__RCSID("$NetBSD: init.c,v 1.259 2024/02/08 20:45:20 rillig Exp $");
+__RCSID("$NetBSD: init.c,v 1.260 2024/03/01 21:52:48 rillig Exp $");
 #endif
 
 #include 
@@ -886,7 +886,7 @@ initialization_init_array_from_string(in
 
 	size_t len = tn->tn_string->len;
 	if (tn->tn_string->data != NULL) {
-		quoted_iterator it = { .start = 0 };
+		quoted_iterator it = { .i = 0 };
 		for (len = 0; quoted_next(tn->tn_string, ); len++)
 			continue;
 	}

Index: src/usr.bin/xlint/lint1/lex.c
diff -u src/usr.bin/xlint/lint1/lex.c:1.219 src/usr.bin/xlint/lint1/lex.c:1.220
--- 

CVS commit: src/usr.bin/xlint/lint1

2024-03-01 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Fri Mar  1 21:52:48 UTC 2024

Modified Files:
src/usr.bin/xlint/lint1: ckgetopt.c cksnprintb.c emit1.c init.c lex.c
tree.c

Log Message:
lint: fix misleading initializer for string iterator

The field 'start' marks the start of the previous matching character,
not the current iterator position.

No binary change.


To generate a diff of this commit:
cvs rdiff -u -r1.23 -r1.24 src/usr.bin/xlint/lint1/ckgetopt.c
cvs rdiff -u -r1.1 -r1.2 src/usr.bin/xlint/lint1/cksnprintb.c
cvs rdiff -u -r1.87 -r1.88 src/usr.bin/xlint/lint1/emit1.c
cvs rdiff -u -r1.259 -r1.260 src/usr.bin/xlint/lint1/init.c
cvs rdiff -u -r1.219 -r1.220 src/usr.bin/xlint/lint1/lex.c
cvs rdiff -u -r1.606 -r1.607 src/usr.bin/xlint/lint1/tree.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/xlint/lint1

2024-03-01 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Fri Mar  1 19:40:45 UTC 2024

Added Files:
src/usr.bin/xlint/lint1: cksnprintb.c

Log Message:
lint: test format strings from snprintb calls

The functions snprintb and snprintb_m are specific to NetBSD, and their
format strings are tricky to get correct.  Provide some assistance in
catching the most common mistakes.


To generate a diff of this commit:
cvs rdiff -u -r0 -r1.1 src/usr.bin/xlint/lint1/cksnprintb.c

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

Added files:

Index: src/usr.bin/xlint/lint1/cksnprintb.c
diff -u /dev/null src/usr.bin/xlint/lint1/cksnprintb.c:1.1
--- /dev/null	Fri Mar  1 19:40:45 2024
+++ src/usr.bin/xlint/lint1/cksnprintb.c	Fri Mar  1 19:40:45 2024
@@ -0,0 +1,290 @@
+/*	$NetBSD: cksnprintb.c,v 1.1 2024/03/01 19:40:45 rillig Exp $	*/
+
+/*-
+ * Copyright (c) 2024 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Roland Illig .
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *notice, this list of conditions and the following disclaimer in the
+ *documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#if HAVE_NBTOOL_CONFIG_H
+#include "nbtool_config.h"
+#endif
+
+#include 
+#if defined(__RCSID)
+__RCSID("$NetBSD: cksnprintb.c,v 1.1 2024/03/01 19:40:45 rillig Exp $");
+#endif
+
+#include 
+#include 
+
+#include "lint1.h"
+
+static bool
+match_string_literal(const tnode_t *tn, const buffer **str)
+{
+	while (tn->tn_op == CVT)
+		tn = tn_ck_left(tn);
+	return tn->tn_op == ADDR
+	&& tn->tn_left->tn_op == STRING
+	&& (*str = tn->tn_left->tn_string, (*str)->data != NULL);
+}
+
+static bool
+match_snprintb_call(const function_call *call,
+const buffer **out_fmt, const tnode_t **out_val)
+{
+	const char *func;
+	const tnode_t *val;
+	const buffer *str;
+
+	if (call->func->tn_op == ADDR
+	&& call->func->tn_left->tn_op == NAME
+	&& (func = call->func->tn_left->tn_sym->s_name, true)
+	&& ((strcmp(func, "snprintb") == 0 && call->args_len == 4)
+		|| (strcmp(func, "snprintb_m") == 0 && call->args_len == 5))
+	&& match_string_literal(call->args[2], )
+	&& (val = call->args[3], true)) {
+		*out_fmt = str;
+		*out_val = val;
+		return true;
+	}
+	return false;
+}
+
+static int
+len(quoted_iterator it)
+{
+	return (int)(it.i - it.start);
+}
+
+static int
+range(quoted_iterator start, quoted_iterator end)
+{
+	return (int)(end.i - start.start);
+}
+
+static const char *
+start(quoted_iterator it, const buffer *buf)
+{
+	return buf->data + it.start;
+}
+
+static uintmax_t
+val(quoted_iterator it)
+{
+	return it.value;
+}
+
+static void
+check_hex_escape(const buffer *buf, quoted_iterator it)
+{
+	if (it.hex_digits > 1) {
+		bool upper = false;
+		bool lower = false;
+		for (size_t i = it.start + 2; i < it.i; i++) {
+			if (isupper((unsigned char)buf->data[i]))
+upper = true;
+			if (islower((unsigned char)buf->data[i]))
+lower = true;
+		}
+		if (upper && lower)
+			/* hex escape '%.*s' mixes uppercase and lower... */
+			warning(357, len(it), start(it, buf));
+	}
+	if (it.hex_digits > 2)
+		/* hex escape '%.*s' has more than 2 digits */
+		warning(358, len(it), start(it, buf));
+}
+
+static bool
+check_directive(const buffer *fmt, quoted_iterator *it, bool new_style,
+		uint64_t *prev_field_width)
+{
+
+	if (!quoted_next(fmt, it))
+		return false;
+	quoted_iterator dir = *it;
+
+	bool has_bit = !new_style
+	|| dir.value == 'b' || dir.value == 'f' || dir.value == 'F';
+	if (has_bit

CVS commit: src/usr.bin/xlint/lint1

2024-03-01 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Fri Mar  1 19:40:45 UTC 2024

Added Files:
src/usr.bin/xlint/lint1: cksnprintb.c

Log Message:
lint: test format strings from snprintb calls

The functions snprintb and snprintb_m are specific to NetBSD, and their
format strings are tricky to get correct.  Provide some assistance in
catching the most common mistakes.


To generate a diff of this commit:
cvs rdiff -u -r0 -r1.1 src/usr.bin/xlint/lint1/cksnprintb.c

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



CVS commit: src

2024-03-01 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Fri Mar  1 19:39:29 UTC 2024

Modified Files:
src/distrib/sets/lists/tests: mi
src/tests/usr.bin/xlint/lint1: t_usage.sh
src/usr.bin/xlint/lint1: Makefile err.c externs1.h tree.c
Added Files:
src/tests/usr.bin/xlint/lint1: msg_357.c msg_358.c msg_359.c msg_360.c
msg_361.c msg_362.c msg_363.c msg_364.c msg_365.c msg_366.c
msg_367.c msg_368.c msg_369.c msg_370.c msg_371.c msg_372.c
msg_373.c msg_374.c msg_375.c

Log Message:
lint: test format strings from snprintb calls

The functions snprintb and snprintb_m are specific to NetBSD, and their
format strings are tricky to get correct.  Provide some assistance in
catching the most common mistakes.


To generate a diff of this commit:
cvs rdiff -u -r1.1306 -r1.1307 src/distrib/sets/lists/tests/mi
cvs rdiff -u -r0 -r1.1 src/tests/usr.bin/xlint/lint1/msg_357.c \
src/tests/usr.bin/xlint/lint1/msg_358.c \
src/tests/usr.bin/xlint/lint1/msg_359.c \
src/tests/usr.bin/xlint/lint1/msg_360.c \
src/tests/usr.bin/xlint/lint1/msg_361.c \
src/tests/usr.bin/xlint/lint1/msg_362.c \
src/tests/usr.bin/xlint/lint1/msg_363.c \
src/tests/usr.bin/xlint/lint1/msg_364.c \
src/tests/usr.bin/xlint/lint1/msg_365.c \
src/tests/usr.bin/xlint/lint1/msg_366.c \
src/tests/usr.bin/xlint/lint1/msg_367.c \
src/tests/usr.bin/xlint/lint1/msg_368.c \
src/tests/usr.bin/xlint/lint1/msg_369.c \
src/tests/usr.bin/xlint/lint1/msg_370.c \
src/tests/usr.bin/xlint/lint1/msg_371.c \
src/tests/usr.bin/xlint/lint1/msg_372.c \
src/tests/usr.bin/xlint/lint1/msg_373.c \
src/tests/usr.bin/xlint/lint1/msg_374.c \
src/tests/usr.bin/xlint/lint1/msg_375.c
cvs rdiff -u -r1.15 -r1.16 src/tests/usr.bin/xlint/lint1/t_usage.sh
cvs rdiff -u -r1.103 -r1.104 src/usr.bin/xlint/lint1/Makefile
cvs rdiff -u -r1.225 -r1.226 src/usr.bin/xlint/lint1/err.c
cvs rdiff -u -r1.216 -r1.217 src/usr.bin/xlint/lint1/externs1.h
cvs rdiff -u -r1.605 -r1.606 src/usr.bin/xlint/lint1/tree.c

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/tests/mi
diff -u src/distrib/sets/lists/tests/mi:1.1306 src/distrib/sets/lists/tests/mi:1.1307
--- src/distrib/sets/lists/tests/mi:1.1306	Mon Feb 19 04:30:38 2024
+++ src/distrib/sets/lists/tests/mi	Fri Mar  1 19:39:28 2024
@@ -1,4 +1,4 @@
-# $NetBSD: mi,v 1.1306 2024/02/19 04:30:38 riastradh Exp $
+# $NetBSD: mi,v 1.1307 2024/03/01 19:39:28 rillig Exp $
 #
 # Note: don't delete entries from here - mark them as "obsolete" instead.
 #
@@ -7471,6 +7471,25 @@
 ./usr/tests/usr.bin/xlint/lint1/msg_354.c			tests-usr.bin-tests	compattestfile,atf
 ./usr/tests/usr.bin/xlint/lint1/msg_355.c			tests-usr.bin-tests	compattestfile,atf
 ./usr/tests/usr.bin/xlint/lint1/msg_356.c			tests-usr.bin-tests	compattestfile,atf
+./usr/tests/usr.bin/xlint/lint1/msg_357.c			tests-usr.bin-tests	compattestfile,atf
+./usr/tests/usr.bin/xlint/lint1/msg_358.c			tests-usr.bin-tests	compattestfile,atf
+./usr/tests/usr.bin/xlint/lint1/msg_359.c			tests-usr.bin-tests	compattestfile,atf
+./usr/tests/usr.bin/xlint/lint1/msg_360.c			tests-usr.bin-tests	compattestfile,atf
+./usr/tests/usr.bin/xlint/lint1/msg_361.c			tests-usr.bin-tests	compattestfile,atf
+./usr/tests/usr.bin/xlint/lint1/msg_362.c			tests-usr.bin-tests	compattestfile,atf
+./usr/tests/usr.bin/xlint/lint1/msg_363.c			tests-usr.bin-tests	compattestfile,atf
+./usr/tests/usr.bin/xlint/lint1/msg_364.c			tests-usr.bin-tests	compattestfile,atf
+./usr/tests/usr.bin/xlint/lint1/msg_365.c			tests-usr.bin-tests	compattestfile,atf
+./usr/tests/usr.bin/xlint/lint1/msg_366.c			tests-usr.bin-tests	compattestfile,atf
+./usr/tests/usr.bin/xlint/lint1/msg_367.c			tests-usr.bin-tests	compattestfile,atf
+./usr/tests/usr.bin/xlint/lint1/msg_368.c			tests-usr.bin-tests	compattestfile,atf
+./usr/tests/usr.bin/xlint/lint1/msg_369.c			tests-usr.bin-tests	compattestfile,atf
+./usr/tests/usr.bin/xlint/lint1/msg_370.c			tests-usr.bin-tests	compattestfile,atf
+./usr/tests/usr.bin/xlint/lint1/msg_371.c			tests-usr.bin-tests	compattestfile,atf
+./usr/tests/usr.bin/xlint/lint1/msg_372.c			tests-usr.bin-tests	compattestfile,atf
+./usr/tests/usr.bin/xlint/lint1/msg_373.c			tests-usr.bin-tests	compattestfile,atf
+./usr/tests/usr.bin/xlint/lint1/msg_374.c			tests-usr.bin-tests	compattestfile,atf
+./usr/tests/usr.bin/xlint/lint1/msg_375.c			tests-usr.bin-tests	compattestfile,atf
 ./usr/tests/usr.bin/xlint/lint1/op_colon.c			tests-usr.bin-tests	compattestfile,atf
 ./usr/tests/usr.bin/xlint/lint1/op_colon.exp			tests-obsolete		obsolete,atf
 ./usr/tests/usr.bin/xlint/lint1/op_shl_lp64.c			tests-usr.bin-tests	compattestfile,atf

Index: src/tests/usr.bin/xlint/lint1/t_usage.sh
diff -u src/tests/usr.bin/xlint/lint1/t_usage.sh:1.15 src/tests/usr.bin/xlint/lint1/t_usage.sh:1.16
--- 

CVS commit: src

2024-03-01 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Fri Mar  1 19:39:29 UTC 2024

Modified Files:
src/distrib/sets/lists/tests: mi
src/tests/usr.bin/xlint/lint1: t_usage.sh
src/usr.bin/xlint/lint1: Makefile err.c externs1.h tree.c
Added Files:
src/tests/usr.bin/xlint/lint1: msg_357.c msg_358.c msg_359.c msg_360.c
msg_361.c msg_362.c msg_363.c msg_364.c msg_365.c msg_366.c
msg_367.c msg_368.c msg_369.c msg_370.c msg_371.c msg_372.c
msg_373.c msg_374.c msg_375.c

Log Message:
lint: test format strings from snprintb calls

The functions snprintb and snprintb_m are specific to NetBSD, and their
format strings are tricky to get correct.  Provide some assistance in
catching the most common mistakes.


To generate a diff of this commit:
cvs rdiff -u -r1.1306 -r1.1307 src/distrib/sets/lists/tests/mi
cvs rdiff -u -r0 -r1.1 src/tests/usr.bin/xlint/lint1/msg_357.c \
src/tests/usr.bin/xlint/lint1/msg_358.c \
src/tests/usr.bin/xlint/lint1/msg_359.c \
src/tests/usr.bin/xlint/lint1/msg_360.c \
src/tests/usr.bin/xlint/lint1/msg_361.c \
src/tests/usr.bin/xlint/lint1/msg_362.c \
src/tests/usr.bin/xlint/lint1/msg_363.c \
src/tests/usr.bin/xlint/lint1/msg_364.c \
src/tests/usr.bin/xlint/lint1/msg_365.c \
src/tests/usr.bin/xlint/lint1/msg_366.c \
src/tests/usr.bin/xlint/lint1/msg_367.c \
src/tests/usr.bin/xlint/lint1/msg_368.c \
src/tests/usr.bin/xlint/lint1/msg_369.c \
src/tests/usr.bin/xlint/lint1/msg_370.c \
src/tests/usr.bin/xlint/lint1/msg_371.c \
src/tests/usr.bin/xlint/lint1/msg_372.c \
src/tests/usr.bin/xlint/lint1/msg_373.c \
src/tests/usr.bin/xlint/lint1/msg_374.c \
src/tests/usr.bin/xlint/lint1/msg_375.c
cvs rdiff -u -r1.15 -r1.16 src/tests/usr.bin/xlint/lint1/t_usage.sh
cvs rdiff -u -r1.103 -r1.104 src/usr.bin/xlint/lint1/Makefile
cvs rdiff -u -r1.225 -r1.226 src/usr.bin/xlint/lint1/err.c
cvs rdiff -u -r1.216 -r1.217 src/usr.bin/xlint/lint1/externs1.h
cvs rdiff -u -r1.605 -r1.606 src/usr.bin/xlint/lint1/tree.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/make

2024-03-01 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Fri Mar  1 17:53:30 UTC 2024

Modified Files:
src/usr.bin/make: var.c

Log Message:
make: fix type mismatch in lint's strict bool mode (since today)


To generate a diff of this commit:
cvs rdiff -u -r1.1100 -r1.1101 src/usr.bin/make/var.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/make/var.c
diff -u src/usr.bin/make/var.c:1.1100 src/usr.bin/make/var.c:1.1101
--- src/usr.bin/make/var.c:1.1100	Fri Mar  1 16:41:42 2024
+++ src/usr.bin/make/var.c	Fri Mar  1 17:53:30 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: var.c,v 1.1100 2024/03/01 16:41:42 sjg Exp $	*/
+/*	$NetBSD: var.c,v 1.1101 2024/03/01 17:53:30 rillig Exp $	*/
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -137,7 +137,7 @@
 #include "metachar.h"
 
 /*	"@(#)var.c	8.3 (Berkeley) 3/19/94" */
-MAKE_RCSID("$NetBSD: var.c,v 1.1100 2024/03/01 16:41:42 sjg Exp $");
+MAKE_RCSID("$NetBSD: var.c,v 1.1101 2024/03/01 17:53:30 rillig Exp $");
 
 /*
  * Variables are defined using one of the VAR=value assignments.  Their
@@ -612,9 +612,9 @@ ExportVarEnv(Var *v, GNode *scope)
 	expr = str_concat3("${", name, "}");
 	val = Var_Subst(expr, scope, VARE_WANTRES);
 	if (scope != SCOPE_GLOBAL) {
-		/* we will need to re-rexport the Global version */
+		/* we will need to re-export the global version */
 		v = VarFind(name, SCOPE_GLOBAL, false);
-		if (v)
+		if (v != NULL)
 			v->exported = false;
 	}
 	/* TODO: handle errors */



CVS commit: src/usr.bin/make

2024-03-01 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Fri Mar  1 17:53:30 UTC 2024

Modified Files:
src/usr.bin/make: var.c

Log Message:
make: fix type mismatch in lint's strict bool mode (since today)


To generate a diff of this commit:
cvs rdiff -u -r1.1100 -r1.1101 src/usr.bin/make/var.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/make

2024-03-01 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Fri Mar  1 17:47:05 UTC 2024

Modified Files:
src/usr.bin/make: test-variants.mk

Log Message:
make: remove test variant for NO_REGEX

The compile-time toggle was removed in var.c 1.1099 from 2024-02-07.


To generate a diff of this commit:
cvs rdiff -u -r1.5 -r1.6 src/usr.bin/make/test-variants.mk

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/make/test-variants.mk
diff -u src/usr.bin/make/test-variants.mk:1.5 src/usr.bin/make/test-variants.mk:1.6
--- src/usr.bin/make/test-variants.mk:1.5	Thu Jan 19 19:55:27 2023
+++ src/usr.bin/make/test-variants.mk	Fri Mar  1 17:47:05 2024
@@ -1,4 +1,4 @@
-# $NetBSD: test-variants.mk,v 1.5 2023/01/19 19:55:27 rillig Exp $
+# $NetBSD: test-variants.mk,v 1.6 2024/03/01 17:47:05 rillig Exp $
 #
 # Build several variants of make and run the tests on them.
 #
@@ -81,15 +81,6 @@ TESTS+=			maxpathlen
 CPPFLAGS.maxpathlen=	-DMAXPATHLEN=20
 SKIP.maxpathlen=	yes
 
-# In this variant, the unit tests using the modifier ':C' fail, as expected.
-#
-TESTS+=			no-regex
-CPPFLAGS.no-regex=	-DNO_REGEX
-SKIP_TESTS.no-regex=	archive cond-short deptgt-makeflags dollar export-all
-SKIP_TESTS.no-regex+=	moderrs modmatch modmisc var-eval-short
-SKIP_TESTS.no-regex+=	varmod-select-words varmod-subst varmod-subst-regex
-SKIP_TESTS.no-regex+=	varname-dot-make-pid varname-dot-make-ppid
-
 # NetBSD 8.0 x86_64 says:
 # In file included from /usr/include/sys/param.h:115:0,
 # from arch.c:135:



CVS commit: src/usr.bin/make

2024-03-01 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Fri Mar  1 17:47:05 UTC 2024

Modified Files:
src/usr.bin/make: test-variants.mk

Log Message:
make: remove test variant for NO_REGEX

The compile-time toggle was removed in var.c 1.1099 from 2024-02-07.


To generate a diff of this commit:
cvs rdiff -u -r1.5 -r1.6 src/usr.bin/make/test-variants.mk

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



CVS commit: src

2024-03-01 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Fri Mar  1 17:22:55 UTC 2024

Modified Files:
src/tests/usr.bin/xlint/lint1: msg_348.c msg_349.c msg_350.c msg_351.c
msg_352.c msg_353.c msg_354.c msg_355.c msg_356.c
src/usr.bin/xlint/lint1: check-msgs.lua

Log Message:
tests/lint: remove redundant documentation


To generate a diff of this commit:
cvs rdiff -u -r1.9 -r1.10 src/tests/usr.bin/xlint/lint1/msg_348.c
cvs rdiff -u -r1.2 -r1.3 src/tests/usr.bin/xlint/lint1/msg_349.c \
src/tests/usr.bin/xlint/lint1/msg_352.c
cvs rdiff -u -r1.3 -r1.4 src/tests/usr.bin/xlint/lint1/msg_350.c
cvs rdiff -u -r1.7 -r1.8 src/tests/usr.bin/xlint/lint1/msg_351.c
cvs rdiff -u -r1.4 -r1.5 src/tests/usr.bin/xlint/lint1/msg_353.c
cvs rdiff -u -r1.1 -r1.2 src/tests/usr.bin/xlint/lint1/msg_354.c \
src/tests/usr.bin/xlint/lint1/msg_355.c \
src/tests/usr.bin/xlint/lint1/msg_356.c
cvs rdiff -u -r1.21 -r1.22 src/usr.bin/xlint/lint1/check-msgs.lua

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



CVS commit: src

2024-03-01 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Fri Mar  1 17:22:55 UTC 2024

Modified Files:
src/tests/usr.bin/xlint/lint1: msg_348.c msg_349.c msg_350.c msg_351.c
msg_352.c msg_353.c msg_354.c msg_355.c msg_356.c
src/usr.bin/xlint/lint1: check-msgs.lua

Log Message:
tests/lint: remove redundant documentation


To generate a diff of this commit:
cvs rdiff -u -r1.9 -r1.10 src/tests/usr.bin/xlint/lint1/msg_348.c
cvs rdiff -u -r1.2 -r1.3 src/tests/usr.bin/xlint/lint1/msg_349.c \
src/tests/usr.bin/xlint/lint1/msg_352.c
cvs rdiff -u -r1.3 -r1.4 src/tests/usr.bin/xlint/lint1/msg_350.c
cvs rdiff -u -r1.7 -r1.8 src/tests/usr.bin/xlint/lint1/msg_351.c
cvs rdiff -u -r1.4 -r1.5 src/tests/usr.bin/xlint/lint1/msg_353.c
cvs rdiff -u -r1.1 -r1.2 src/tests/usr.bin/xlint/lint1/msg_354.c \
src/tests/usr.bin/xlint/lint1/msg_355.c \
src/tests/usr.bin/xlint/lint1/msg_356.c
cvs rdiff -u -r1.21 -r1.22 src/usr.bin/xlint/lint1/check-msgs.lua

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/xlint/lint1/msg_348.c
diff -u src/tests/usr.bin/xlint/lint1/msg_348.c:1.9 src/tests/usr.bin/xlint/lint1/msg_348.c:1.10
--- src/tests/usr.bin/xlint/lint1/msg_348.c:1.9	Tue Mar 28 14:44:35 2023
+++ src/tests/usr.bin/xlint/lint1/msg_348.c	Fri Mar  1 17:22:55 2024
@@ -1,7 +1,7 @@
-/*	$NetBSD: msg_348.c,v 1.9 2023/03/28 14:44:35 rillig Exp $	*/
+/*	$NetBSD: msg_348.c,v 1.10 2024/03/01 17:22:55 rillig Exp $	*/
 # 3 "msg_348.c"
 
-// Test for message 348: maximum value %d of '%s' does not match maximum array index %d [348]
+// Test for message: maximum value %d of '%s' does not match maximum array index %d [348]
 
 /* lint1-extra-flags: -r -X 351 */
 

Index: src/tests/usr.bin/xlint/lint1/msg_349.c
diff -u src/tests/usr.bin/xlint/lint1/msg_349.c:1.2 src/tests/usr.bin/xlint/lint1/msg_349.c:1.3
--- src/tests/usr.bin/xlint/lint1/msg_349.c:1.2	Tue Mar 28 14:44:35 2023
+++ src/tests/usr.bin/xlint/lint1/msg_349.c	Fri Mar  1 17:22:55 2024
@@ -1,7 +1,7 @@
-/*	$NetBSD: msg_349.c,v 1.2 2023/03/28 14:44:35 rillig Exp $	*/
+/*	$NetBSD: msg_349.c,v 1.3 2024/03/01 17:22:55 rillig Exp $	*/
 # 3 "msg_349.c"
 
-// Test for message 349: non type argument to alignof is a GCC extension [348]
+// Test for message: non type argument to alignof is a GCC extension [349]
 
 /* lint1-flags: -S -w -X 351 */
 
Index: src/tests/usr.bin/xlint/lint1/msg_352.c
diff -u src/tests/usr.bin/xlint/lint1/msg_352.c:1.2 src/tests/usr.bin/xlint/lint1/msg_352.c:1.3
--- src/tests/usr.bin/xlint/lint1/msg_352.c:1.2	Fri Jul  7 19:45:22 2023
+++ src/tests/usr.bin/xlint/lint1/msg_352.c	Fri Mar  1 17:22:55 2024
@@ -1,7 +1,7 @@
-/*	$NetBSD: msg_352.c,v 1.2 2023/07/07 19:45:22 rillig Exp $	*/
+/*	$NetBSD: msg_352.c,v 1.3 2024/03/01 17:22:55 rillig Exp $	*/
 # 3 "msg_352.c"
 
-// Test for message 352: nested 'extern' declaration of '%s' [352]
+// Test for message: nested 'extern' declaration of '%s' [352]
 
 /*
  * C allows to declare external functions or objects inside function bodies,

Index: src/tests/usr.bin/xlint/lint1/msg_350.c
diff -u src/tests/usr.bin/xlint/lint1/msg_350.c:1.3 src/tests/usr.bin/xlint/lint1/msg_350.c:1.4
--- src/tests/usr.bin/xlint/lint1/msg_350.c:1.3	Fri Jul  7 19:45:22 2023
+++ src/tests/usr.bin/xlint/lint1/msg_350.c	Fri Mar  1 17:22:55 2024
@@ -1,7 +1,7 @@
-/*	$NetBSD: msg_350.c,v 1.3 2023/07/07 19:45:22 rillig Exp $	*/
+/*	$NetBSD: msg_350.c,v 1.4 2024/03/01 17:22:55 rillig Exp $	*/
 # 3 "msg_350.c"
 
-// Test for message 350: '_Atomic' requires C11 or later [350]
+// Test for message: '_Atomic' requires C11 or later [350]
 
 /*
  * The keyword '_Atomic' was added in C11.  This test ensures that in C99

Index: src/tests/usr.bin/xlint/lint1/msg_351.c
diff -u src/tests/usr.bin/xlint/lint1/msg_351.c:1.7 src/tests/usr.bin/xlint/lint1/msg_351.c:1.8
--- src/tests/usr.bin/xlint/lint1/msg_351.c:1.7	Fri Jul  7 19:45:22 2023
+++ src/tests/usr.bin/xlint/lint1/msg_351.c	Fri Mar  1 17:22:55 2024
@@ -1,7 +1,7 @@
-/*	$NetBSD: msg_351.c,v 1.7 2023/07/07 19:45:22 rillig Exp $	*/
+/*	$NetBSD: msg_351.c,v 1.8 2024/03/01 17:22:55 rillig Exp $	*/
 # 3 "msg_351.c"
 
-// Test for message 351: missing%s header declaration for '%s' [351]
+// Test for message: missing%s header declaration for '%s' [351]
 
 /*
  * Warn about declarations or definitions for functions or objects that are

Index: src/tests/usr.bin/xlint/lint1/msg_353.c
diff -u src/tests/usr.bin/xlint/lint1/msg_353.c:1.4 src/tests/usr.bin/xlint/lint1/msg_353.c:1.5
--- src/tests/usr.bin/xlint/lint1/msg_353.c:1.4	Fri Jul 14 08:53:52 2023
+++ src/tests/usr.bin/xlint/lint1/msg_353.c	Fri Mar  1 17:22:55 2024
@@ -1,7 +1,7 @@
-/*	$NetBSD: msg_353.c,v 1.4 2023/07/14 08:53:52 rillig Exp $	*/
+/*	$NetBSD: msg_353.c,v 1.5 2024/03/01 17:22:55 rillig Exp $	*/
 # 3 "msg_353.c"
 
-// Test for message 353: empty initializer braces require C23 or later [353]
+// Test for message: empty initializer 

CVS commit: src/usr.bin/xlint/lint1

2024-03-01 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Fri Mar  1 17:14:34 UTC 2024

Modified Files:
src/usr.bin/xlint/lint1: lex.c

Log Message:
lint: fix type error in strict bool mode (since yesterday)


To generate a diff of this commit:
cvs rdiff -u -r1.218 -r1.219 src/usr.bin/xlint/lint1/lex.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/xlint/lint1

2024-03-01 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Fri Mar  1 17:14:34 UTC 2024

Modified Files:
src/usr.bin/xlint/lint1: lex.c

Log Message:
lint: fix type error in strict bool mode (since yesterday)


To generate a diff of this commit:
cvs rdiff -u -r1.218 -r1.219 src/usr.bin/xlint/lint1/lex.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/xlint/lint1/lex.c
diff -u src/usr.bin/xlint/lint1/lex.c:1.218 src/usr.bin/xlint/lint1/lex.c:1.219
--- src/usr.bin/xlint/lint1/lex.c:1.218	Thu Feb 29 21:37:10 2024
+++ src/usr.bin/xlint/lint1/lex.c	Fri Mar  1 17:14:34 2024
@@ -1,4 +1,4 @@
-/* $NetBSD: lex.c,v 1.218 2024/02/29 21:37:10 rillig Exp $ */
+/* $NetBSD: lex.c,v 1.219 2024/03/01 17:14:34 rillig Exp $ */
 
 /*
  * Copyright (c) 1996 Christopher G. Demetriou.  All Rights Reserved.
@@ -38,7 +38,7 @@
 
 #include 
 #if defined(__RCSID)
-__RCSID("$NetBSD: lex.c,v 1.218 2024/02/29 21:37:10 rillig Exp $");
+__RCSID("$NetBSD: lex.c,v 1.219 2024/03/01 17:14:34 rillig Exp $");
 #endif
 
 #include 
@@ -597,7 +597,7 @@ lex_integer_constant(const char *yytext,
 	bool unsigned_since_c90 = allow_trad && allow_c90 && u_suffix == 0
 	&& is_unsigned_since_c90(l_suffix, ui, base);
 
-	tspec_t t = u_suffix
+	tspec_t t = u_suffix > 0
 	? integer_constant_type_unsigned(l_suffix, ui, warned)
 	: integer_constant_type_signed(l_suffix, ui, base, warned);
 	ui = (uint64_t)convert_integer((int64_t)ui, t, 0);



CVS commit: src/usr.bin/xlint/lint1

2024-02-29 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Thu Feb 29 21:37:10 UTC 2024

Modified Files:
src/usr.bin/xlint/lint1: lex.c

Log Message:
lint1: remove redundant type table for integer constant suffixes


To generate a diff of this commit:
cvs rdiff -u -r1.217 -r1.218 src/usr.bin/xlint/lint1/lex.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/xlint/lint1/lex.c
diff -u src/usr.bin/xlint/lint1/lex.c:1.217 src/usr.bin/xlint/lint1/lex.c:1.218
--- src/usr.bin/xlint/lint1/lex.c:1.217	Thu Feb  8 20:59:19 2024
+++ src/usr.bin/xlint/lint1/lex.c	Thu Feb 29 21:37:10 2024
@@ -1,4 +1,4 @@
-/* $NetBSD: lex.c,v 1.217 2024/02/08 20:59:19 rillig Exp $ */
+/* $NetBSD: lex.c,v 1.218 2024/02/29 21:37:10 rillig Exp $ */
 
 /*
  * Copyright (c) 1996 Christopher G. Demetriou.  All Rights Reserved.
@@ -38,7 +38,7 @@
 
 #include 
 #if defined(__RCSID)
-__RCSID("$NetBSD: lex.c,v 1.217 2024/02/08 20:59:19 rillig Exp $");
+__RCSID("$NetBSD: lex.c,v 1.218 2024/02/29 21:37:10 rillig Exp $");
 #endif
 
 #include 
@@ -481,84 +481,72 @@ lex_name(const char *yytext, size_t yyle
 // Determines whether the constant is signed in traditional C but unsigned in
 // C90 and later.
 static bool
-is_unsigned_since_c90(tspec_t t, uint64_t ui, int base)
+is_unsigned_since_c90(unsigned ls, uint64_t ui, int base)
 {
-	if (!(allow_trad && allow_c90))
+	if (ui <= TARG_INT_MAX)
 		return false;
-	if (t == INT) {
-		if (ui > TARG_INT_MAX && ui <= TARG_UINT_MAX && base != 10)
-			return true;
-		return ui > TARG_LONG_MAX;
-	}
-	return t == LONG && ui > TARG_LONG_MAX;
+	if (ls == 0 && ui <= TARG_UINT_MAX && base != 10)
+		return true;
+	return ls <= 1 && ui > TARG_LONG_MAX;
 }
 
 static tspec_t
-integer_constant_type(tspec_t t, uint64_t ui, int base, bool warned)
+integer_constant_type_signed(unsigned ls, uint64_t ui, int base, bool warned)
 {
-	switch (t) {
-	case INT:
-		if (ui <= TARG_INT_MAX)
-			return INT;
-		if (ui <= TARG_UINT_MAX && base != 10 && allow_c90)
-			return UINT;
-		if (ui <= TARG_LONG_MAX)
-			return LONG;
-		/* FALLTHROUGH */
-	case LONG:
-		if (ui <= TARG_LONG_MAX)
-			return LONG;
-		if (ui <= TARG_ULONG_MAX && base != 10)
-			return allow_c90 ? ULONG : LONG;
-		if (!allow_c99) {
-			if (!warned)
-/* integer constant out of range */
-warning(252);
-			return allow_c90 ? ULONG : LONG;
-		}
-		/* FALLTHROUGH */
-	case LLONG:
-		if (ui <= TARG_LLONG_MAX)
-			return LLONG;
-		if (ui <= TARG_ULLONG_MAX && base != 10)
-			return allow_c90 ? ULLONG : LLONG;
+	if (ls == 0 && ui <= TARG_INT_MAX)
+		return INT;
+	if (ls == 0 && ui <= TARG_UINT_MAX && base != 10 && allow_c90)
+		return UINT;
+	if (ls == 0 && ui <= TARG_LONG_MAX)
+		return LONG;
+
+	if (ls <= 1 && ui <= TARG_LONG_MAX)
+		return LONG;
+	if (ls <= 1 && ui <= TARG_ULONG_MAX && base != 10)
+		return allow_c90 ? ULONG : LONG;
+	if (ls <= 1 && !allow_c99) {
 		if (!warned)
 			/* integer constant out of range */
 			warning(252);
+		return allow_c90 ? ULONG : LONG;
+	}
+
+	if (ui <= TARG_LLONG_MAX)
+		return LLONG;
+	if (ui <= TARG_ULLONG_MAX && base != 10)
 		return allow_c90 ? ULLONG : LLONG;
-	case UINT:
-		if (ui <= TARG_UINT_MAX)
-			return UINT;
-		/* FALLTHROUGH */
-	case ULONG:
-		if (ui <= TARG_ULONG_MAX)
-			return ULONG;
-		if (!allow_c99) {
-			if (!warned)
-/* integer constant out of range */
-warning(252);
-			return ULONG;
-		}
-		/* FALLTHROUGH */
-	default:
-		if (ui <= TARG_ULLONG_MAX)
-			return ULLONG;
+	if (!warned)
+		/* integer constant out of range */
+		warning(252);
+	return allow_c90 ? ULLONG : LLONG;
+}
+
+static tspec_t
+integer_constant_type_unsigned(unsigned l, uint64_t ui, bool warned)
+{
+	if (l == 0 && ui <= TARG_UINT_MAX)
+		return UINT;
+
+	if (l <= 1 && ui <= TARG_ULONG_MAX)
+		return ULONG;
+	if (l <= 1 && !allow_c99) {
 		if (!warned)
 			/* integer constant out of range */
 			warning(252);
-		return ULLONG;
+		return ULONG;
 	}
+
+	if (ui <= TARG_ULLONG_MAX)
+		return ULLONG;
+	if (!warned)
+		/* integer constant out of range */
+		warning(252);
+	return ULLONG;
 }
 
 int
 lex_integer_constant(const char *yytext, size_t yyleng, int base)
 {
-	/* C11 6.4.4.1p5 */
-	static const tspec_t suffix_type[2][3] = {
-		{ INT,  LONG,  LLONG, },
-		{ UINT, ULONG, ULLONG, }
-	};
-
 	const char *cp = yytext;
 	size_t len = yyleng;
 
@@ -590,7 +578,6 @@ lex_integer_constant(const char *yytext,
 	if (!allow_c90 && u_suffix > 0)
 		/* suffix 'U' is illegal in traditional C */
 		warning(97);
-	tspec_t ct = suffix_type[u_suffix][l_suffix];
 
 	bool warned = false;
 	errno = 0;
@@ -607,14 +594,17 @@ lex_integer_constant(const char *yytext,
 		/* octal number '%.*s' */
 		query_message(8, (int)len, cp);
 
-	bool ansiu = is_unsigned_since_c90(ct, ui, base);
+	bool unsigned_since_c90 = allow_trad && allow_c90 && u_suffix == 0
+	&& is_unsigned_since_c90(l_suffix, ui, base);
 
-	tspec_t t = integer_constant_type(ct, ui, base, 

CVS commit: src/usr.bin/xlint/lint1

2024-02-29 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Thu Feb 29 21:37:10 UTC 2024

Modified Files:
src/usr.bin/xlint/lint1: lex.c

Log Message:
lint1: remove redundant type table for integer constant suffixes


To generate a diff of this commit:
cvs rdiff -u -r1.217 -r1.218 src/usr.bin/xlint/lint1/lex.c

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



CVS commit: src/lib/libutil

2024-02-29 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Thu Feb 29 21:08:55 UTC 2024

Modified Files:
src/lib/libutil: snprintb.3

Log Message:
snprintb.3: fix typo


To generate a diff of this commit:
cvs rdiff -u -r1.35 -r1.36 src/lib/libutil/snprintb.3

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

Modified files:

Index: src/lib/libutil/snprintb.3
diff -u src/lib/libutil/snprintb.3:1.35 src/lib/libutil/snprintb.3:1.36
--- src/lib/libutil/snprintb.3:1.35	Thu Feb 22 21:04:24 2024
+++ src/lib/libutil/snprintb.3	Thu Feb 29 21:08:54 2024
@@ -1,4 +1,4 @@
-.\" $NetBSD: snprintb.3,v 1.35 2024/02/22 21:04:24 rillig Exp $
+.\" $NetBSD: snprintb.3,v 1.36 2024/02/29 21:08:54 rillig Exp $
 .\"
 .\" Copyright (c) 1998, 2024 The NetBSD Foundation, Inc.
 .\" All rights reserved.
@@ -69,7 +69,7 @@ terminating
 If
 .Fa bufsize
 is zero, nothing is written and
-.Fa arg
+.Fa buf
 may be a null pointer.
 .Pp
 The



CVS commit: src/lib/libutil

2024-02-29 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Thu Feb 29 21:08:55 UTC 2024

Modified Files:
src/lib/libutil: snprintb.3

Log Message:
snprintb.3: fix typo


To generate a diff of this commit:
cvs rdiff -u -r1.35 -r1.36 src/lib/libutil/snprintb.3

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



CVS commit: src/lib/libutil

2024-02-29 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Thu Feb 29 20:55:35 UTC 2024

Modified Files:
src/lib/libutil: parsedate.y

Log Message:
parsedate.y: remove outdated comment

The number of shift/reduce conflicts has grown to 16.


To generate a diff of this commit:
cvs rdiff -u -r1.37 -r1.38 src/lib/libutil/parsedate.y

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

Modified files:

Index: src/lib/libutil/parsedate.y
diff -u src/lib/libutil/parsedate.y:1.37 src/lib/libutil/parsedate.y:1.38
--- src/lib/libutil/parsedate.y:1.37	Sat Apr 23 13:02:04 2022
+++ src/lib/libutil/parsedate.y	Thu Feb 29 20:55:35 2024
@@ -5,8 +5,6 @@
 **  a couple of people on Usenet.  Completely overhauled by Rich $alz
 **   and Jim Berets  in August, 1990;
 **
-**  This grammar has 10 shift/reduce conflicts.
-**
 **  This code is in the public domain and has no copyright.
 */
 /* SUPPRESS 287 on yaccpar_sccsid *//* Unused static variable */
@@ -14,7 +12,7 @@
 
 #include 
 #ifdef __RCSID
-__RCSID("$NetBSD: parsedate.y,v 1.37 2022/04/23 13:02:04 christos Exp $");
+__RCSID("$NetBSD: parsedate.y,v 1.38 2024/02/29 20:55:35 rillig Exp $");
 #endif
 
 #include 



CVS commit: src/lib/libutil

2024-02-29 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Thu Feb 29 20:55:35 UTC 2024

Modified Files:
src/lib/libutil: parsedate.y

Log Message:
parsedate.y: remove outdated comment

The number of shift/reduce conflicts has grown to 16.


To generate a diff of this commit:
cvs rdiff -u -r1.37 -r1.38 src/lib/libutil/parsedate.y

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



CVS commit: src/tests/lib/libutil

2024-02-24 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sat Feb 24 13:00:00 UTC 2024

Modified Files:
src/tests/lib/libutil: t_snprintb.c

Log Message:
tests/snprintb: clean up tests

Always write the value to be formatted in hexadecimal, to make it easily
distinguishable from the buffer size and maximum line length.

Use consistent wording in the comments of the test cases. Be stricter
about mistakes in a format.

Fix some wrong numbers in the snprintb_m tests for limited line length.


To generate a diff of this commit:
cvs rdiff -u -r1.28 -r1.29 src/tests/lib/libutil/t_snprintb.c

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



CVS commit: src/tests/lib/libutil

2024-02-24 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sat Feb 24 13:00:00 UTC 2024

Modified Files:
src/tests/lib/libutil: t_snprintb.c

Log Message:
tests/snprintb: clean up tests

Always write the value to be formatted in hexadecimal, to make it easily
distinguishable from the buffer size and maximum line length.

Use consistent wording in the comments of the test cases. Be stricter
about mistakes in a format.

Fix some wrong numbers in the snprintb_m tests for limited line length.


To generate a diff of this commit:
cvs rdiff -u -r1.28 -r1.29 src/tests/lib/libutil/t_snprintb.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/lib/libutil/t_snprintb.c
diff -u src/tests/lib/libutil/t_snprintb.c:1.28 src/tests/lib/libutil/t_snprintb.c:1.29
--- src/tests/lib/libutil/t_snprintb.c:1.28	Sat Feb 24 12:40:00 2024
+++ src/tests/lib/libutil/t_snprintb.c	Sat Feb 24 13:00:00 2024
@@ -1,4 +1,4 @@
-/* $NetBSD: t_snprintb.c,v 1.28 2024/02/24 12:40:00 rillig Exp $ */
+/* $NetBSD: t_snprintb.c,v 1.29 2024/02/24 13:00:00 rillig Exp $ */
 
 /*
  * Copyright (c) 2002, 2004, 2008, 2010, 2024 The NetBSD Foundation, Inc.
@@ -32,7 +32,7 @@
 #include 
 __COPYRIGHT("@(#) Copyright (c) 2008, 2010, 2024\
  The NetBSD Foundation, inc. All rights reserved.");
-__RCSID("$NetBSD: t_snprintb.c,v 1.28 2024/02/24 12:40:00 rillig Exp $");
+__RCSID("$NetBSD: t_snprintb.c,v 1.29 2024/02/24 13:00:00 rillig Exp $");
 
 #include 
 #include 
@@ -44,15 +44,16 @@ __RCSID("$NetBSD: t_snprintb.c,v 1.28 20
 static const char *
 vis_arr(const char *arr, size_t arrsize)
 {
-	static char buf[6][1024];
+	static char buf[3][1024];
 	static size_t i;
 
 	i = (i + 1) % (sizeof(buf) / sizeof(buf[0]));
-	buf[i][0] = '"';
 	int rv = strnvisx(buf[i] + 1, sizeof(buf[i]) - 2, arr, arrsize,
 	VIS_WHITE | VIS_OCTAL);
-	ATF_REQUIRE_MSG(rv >= 0, "strnvisx failed for size %zu", arrsize);
-	strcpy(buf[i] + 1 + rv, "\"");
+	ATF_REQUIRE_MSG(rv >= 0, "buffer too small for size %zu", arrsize);
+	buf[i][0] = '"';
+	buf[i][1 + rv] = '"';
+	buf[i][1 + rv + 1] = '\0';
 	return buf[i];
 }
 
@@ -73,12 +74,12 @@ check_snprintb_m(const char *file, size_
 		file, line);
 	if (bufsize == 0)
 		want_bufsize = 0;
+	memset(buf, 0x5a, sizeof(buf));
 
-	memset(buf, 'Z', sizeof(buf));
 	int rv = snprintb_m(buf, bufsize, bitfmt, val, line_max);
 
 	size_t have_bufsize = sizeof(buf);
-	while (have_bufsize > 0 && buf[have_bufsize - 1] == 'Z')
+	while (have_bufsize > 0 && buf[have_bufsize - 1] == 0x5a)
 		have_bufsize--;
 	if (rv > 0 && (unsigned)rv < have_bufsize
 	&& buf[rv - 1] == '\0' && buf[rv] == '\0')
@@ -122,7 +123,7 @@ check_snprintb_m(const char *file, size_
 	h_snprintb_m_len(bufsize, bitfmt, val, 0, want_rv, want_buf)
 
 #define	h_snprintb_error(bitfmt, want_buf)\
-	h_snprintb_m_len(1024, bitfmt, 0, 0, -1, want_buf)
+	h_snprintb_m_len(1024, bitfmt, 0x00, 0, -1, want_buf)
 
 #define	h_snprintb_m(bitfmt, val, line_max, want_buf)			\
 	h_snprintb_m_len(1024, bitfmt, val, line_max,			\
@@ -141,7 +142,7 @@ ATF_TC_BODY(snprintb, tc)
 	// The value 0 does not get a leading '0'.
 	h_snprintb(
 	"\010",
-	0,
+	0x00,
 	"0");
 
 	// style and number base, old style, octal, nonzero value
@@ -155,7 +156,7 @@ ATF_TC_BODY(snprintb, tc)
 	// style and number base, old style, decimal, zero value
 	h_snprintb(
 	"\012",
-	0,
+	0x00,
 	"0");
 
 	// style and number base, old style, decimal, nonzero value
@@ -169,7 +170,7 @@ ATF_TC_BODY(snprintb, tc)
 	// The value 0 does not get a leading '0x'.
 	h_snprintb(
 	"\020",
-	0,
+	0x00,
 	"0");
 
 	// style and number base, old style, hexadecimal, nonzero value
@@ -200,7 +201,7 @@ ATF_TC_BODY(snprintb, tc)
 	// The value 0 does not get a leading '0'.
 	h_snprintb(
 	"\177\010",
-	0,
+	0x00,
 	"0");
 
 	// style and number base, new style, octal, nonzero value
@@ -214,7 +215,7 @@ ATF_TC_BODY(snprintb, tc)
 	// style and number base, new style, decimal, zero value
 	h_snprintb(
 	"\177\012",
-	0,
+	0x00,
 	"0");
 
 	// style and number base, new style, decimal, nonzero value
@@ -228,7 +229,7 @@ ATF_TC_BODY(snprintb, tc)
 	// The value 0 does not get a leading '0x'.
 	h_snprintb(
 	"\177\020",
-	0,
+	0x00,
 	"0");
 
 	// style and number base, new style, hexadecimal, nonzero value
@@ -278,7 +279,7 @@ ATF_TC_BODY(snprintb, tc)
 	"\020"
 	"\001bit1"
 	"\041bit33",
-	0x1,
+	0x01,
 	"0x1");
 
 	// old style, repeated bit numbers
@@ -289,14 +290,14 @@ ATF_TC_BODY(snprintb, tc)
 	"\020"
 	"\001once"
 	"\001again",
-	0x1,
+	0x01,
 	"0x1");
 
 	// old style, non-printable description
 	//
 	// The characters ' ' and '\t' are interpreted as bit numbers,
-	// not as part of the description; the visual arrangement is
-	// misleading.
+	// not as part of the description; the visual arrangement in this
+	

CVS commit: src/common/lib/libutil

2024-02-24 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sat Feb 24 12:44:11 UTC 2024

Modified Files:
src/common/lib/libutil: snprintb.c

Log Message:
snprintb: clean up

Use consistent data types for buffer positions and lengths, to avoid
type casts.


To generate a diff of this commit:
cvs rdiff -u -r1.40 -r1.41 src/common/lib/libutil/snprintb.c

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



CVS commit: src/common/lib/libutil

2024-02-24 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sat Feb 24 12:44:11 UTC 2024

Modified Files:
src/common/lib/libutil: snprintb.c

Log Message:
snprintb: clean up

Use consistent data types for buffer positions and lengths, to avoid
type casts.


To generate a diff of this commit:
cvs rdiff -u -r1.40 -r1.41 src/common/lib/libutil/snprintb.c

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

Modified files:

Index: src/common/lib/libutil/snprintb.c
diff -u src/common/lib/libutil/snprintb.c:1.40 src/common/lib/libutil/snprintb.c:1.41
--- src/common/lib/libutil/snprintb.c:1.40	Sat Feb 24 12:40:00 2024
+++ src/common/lib/libutil/snprintb.c	Sat Feb 24 12:44:11 2024
@@ -1,7 +1,7 @@
-/*	$NetBSD: snprintb.c,v 1.40 2024/02/24 12:40:00 rillig Exp $	*/
+/*	$NetBSD: snprintb.c,v 1.41 2024/02/24 12:44:11 rillig Exp $	*/
 
 /*-
- * Copyright (c) 2002 The NetBSD Foundation, Inc.
+ * Copyright (c) 2002, 2024 The NetBSD Foundation, Inc.
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -26,12 +26,6 @@
  * POSSIBILITY OF SUCH DAMAGE.
  */
 
-/*
- * snprintb: print an interpreted bitmask to a buffer
- *
- * => returns the length of the buffer that would be required to print the
- *string minus the terminating NUL.
- */
 #ifndef _STANDALONE
 # ifndef _KERNEL
 
@@ -40,8 +34,8 @@
 #  endif
 
 #  include 
-#  if defined(LIBC_SCCS) && !defined(lint)
-__RCSID("$NetBSD: snprintb.c,v 1.40 2024/02/24 12:40:00 rillig Exp $");
+#  if defined(LIBC_SCCS)
+__RCSID("$NetBSD: snprintb.c,v 1.41 2024/02/24 12:44:11 rillig Exp $");
 #  endif
 
 #  include 
@@ -51,7 +45,7 @@ __RCSID("$NetBSD: snprintb.c,v 1.40 2024
 #  include 
 # else /* ! _KERNEL */
 #  include 
-__KERNEL_RCSID(0, "$NetBSD: snprintb.c,v 1.40 2024/02/24 12:40:00 rillig Exp $");
+__KERNEL_RCSID(0, "$NetBSD: snprintb.c,v 1.41 2024/02/24 12:44:11 rillig Exp $");
 #  include 
 #  include 
 #  include 
@@ -67,10 +61,10 @@ typedef struct {
 	size_t const line_max;
 
 	const char *const num_fmt;
-	unsigned total_len;
-	unsigned line_pos;
-	unsigned comma_pos;
-	char sep;
+	size_t total_len;
+	size_t line_pos;
+	size_t comma_pos;
+	int in_angle_brackets;
 } state;
 
 static void
@@ -94,39 +88,39 @@ store_num(state *s, const char *fmt, uin
 }
 
 static void
-put_eol(state *s)
+store_eol(state *s)
 {
 	if (s->total_len - s->line_pos > s->line_max) {
-		s->total_len = (unsigned)(s->line_pos + s->line_max - 1);
+		s->total_len = s->line_pos + s->line_max - 1;
 		store(s, '#');
 	}
 	store(s, '\0');
 	s->line_pos = s->total_len;
 	s->comma_pos = 0;
-	s->sep = '<';
+	s->in_angle_brackets = 0;
 }
 
 static void
-put_sep(state *s)
+store_delimiter(state *s)
 {
-	if (s->sep == ',') {
+	if (s->in_angle_brackets) {
 		s->comma_pos = s->total_len;
 		store(s, ',');
 	} else {
 		store(s, '<');
-		s->sep = ',';
+		s->in_angle_brackets = 1;
 	}
 }
 
 static void
-wrap_if_necessary(state *s, const char *bitfmt)
+maybe_wrap_line(state *s, const char *bitfmt)
 {
 	if (s->line_max > 0
 	&& s->comma_pos > 0
 	&& s->total_len - s->line_pos >= s->line_max) {
 		s->total_len = s->comma_pos;
 		store(s, '>');
-		put_eol(s);
+		store_eol(s);
 		store_num(s, s->num_fmt, s->val);
 		s->bitfmt = bitfmt;
 	}
@@ -141,10 +135,10 @@ old_style(state *s)
 		if (bit > ' ')
 			return -1;
 		if (s->val & (1U << (bit - 1))) {
-			put_sep(s);
+			store_delimiter(s);
 			while ((uint8_t)*++s->bitfmt > ' ')
 store(s, *s->bitfmt);
-			wrap_if_necessary(s, cur_bitfmt);
+			maybe_wrap_line(s, cur_bitfmt);
 		} else
 			while ((uint8_t)*++s->bitfmt > ' ')
 continue;
@@ -170,10 +164,10 @@ new_style(state *s)
 			s->bitfmt += 2;
 			if (((s->val >> b_bit) & 1) == 0)
 goto skip_description;
-			put_sep(s);
+			store_delimiter(s);
 			while (*s->bitfmt++ != '\0')
 store(s, s->bitfmt[-1]);
-			wrap_if_necessary(s, cur_bitfmt);
+			maybe_wrap_line(s, cur_bitfmt);
 			break;
 		case 'f':
 		case 'F':
@@ -189,14 +183,14 @@ new_style(state *s)
 			if (f_width < 64)
 field &= ((uint64_t) 1 << f_width) - 1;
 			s->bitfmt += 3;
-			put_sep(s);
+			store_delimiter(s);
 			if (kind == 'F')
 goto skip_description;
 			while (*s->bitfmt++ != '\0')
 store(s, s->bitfmt[-1]);
 			store(s, '=');
 			store_num(s, s->num_fmt, field);
-			wrap_if_necessary(s, cur_bitfmt);
+			maybe_wrap_line(s, cur_bitfmt);
 			break;
 		case '=':
 		case ':':
@@ -209,7 +203,7 @@ new_style(state *s)
 store(s, '=');
 			while (*s->bitfmt++ != '\0')
 store(s, s->bitfmt[-1]);
-			wrap_if_necessary(s, prev_bitfmt);
+			maybe_wrap_line(s, prev_bitfmt);
 			break;
 		case '*':
 			s->bitfmt++;
@@ -218,7 +212,7 @@ new_style(state *s)
 			matched = 1;
 			if (store_num(s, s->bitfmt, field) < 0)
 return -1;
-			wrap_if_necessary(s, prev_bitfmt);
+			maybe_wrap_line(s, prev_bitfmt);
 			goto skip_description;
 		default:
 			s->bitfmt += 2;
@@ -235,7 +229,7 @@ static void
 finish_buffer(state 

CVS commit: src

2024-02-24 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sat Feb 24 12:40:00 UTC 2024

Modified Files:
src/common/lib/libutil: snprintb.c
src/tests/lib/libutil: t_snprintb.c

Log Message:
snprintb: allow non-ASCII descriptions on all platforms

Previously, these descriptions were only allowed on platforms where
plain 'char' is unsigned. On platforms where plain 'char' is signed,
they invoked undefined behavior or terminated the output early.


To generate a diff of this commit:
cvs rdiff -u -r1.39 -r1.40 src/common/lib/libutil/snprintb.c
cvs rdiff -u -r1.27 -r1.28 src/tests/lib/libutil/t_snprintb.c

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

Modified files:

Index: src/common/lib/libutil/snprintb.c
diff -u src/common/lib/libutil/snprintb.c:1.39 src/common/lib/libutil/snprintb.c:1.40
--- src/common/lib/libutil/snprintb.c:1.39	Thu Feb 22 21:04:23 2024
+++ src/common/lib/libutil/snprintb.c	Sat Feb 24 12:40:00 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: snprintb.c,v 1.39 2024/02/22 21:04:23 rillig Exp $	*/
+/*	$NetBSD: snprintb.c,v 1.40 2024/02/24 12:40:00 rillig Exp $	*/
 
 /*-
  * Copyright (c) 2002 The NetBSD Foundation, Inc.
@@ -41,7 +41,7 @@
 
 #  include 
 #  if defined(LIBC_SCCS) && !defined(lint)
-__RCSID("$NetBSD: snprintb.c,v 1.39 2024/02/22 21:04:23 rillig Exp $");
+__RCSID("$NetBSD: snprintb.c,v 1.40 2024/02/24 12:40:00 rillig Exp $");
 #  endif
 
 #  include 
@@ -51,7 +51,7 @@ __RCSID("$NetBSD: snprintb.c,v 1.39 2024
 #  include 
 # else /* ! _KERNEL */
 #  include 
-__KERNEL_RCSID(0, "$NetBSD: snprintb.c,v 1.39 2024/02/22 21:04:23 rillig Exp $");
+__KERNEL_RCSID(0, "$NetBSD: snprintb.c,v 1.40 2024/02/24 12:40:00 rillig Exp $");
 #  include 
 #  include 
 #  include 
@@ -142,11 +142,11 @@ old_style(state *s)
 			return -1;
 		if (s->val & (1U << (bit - 1))) {
 			put_sep(s);
-			while (*++s->bitfmt > ' ')
+			while ((uint8_t)*++s->bitfmt > ' ')
 store(s, *s->bitfmt);
 			wrap_if_necessary(s, cur_bitfmt);
 		} else
-			while (*++s->bitfmt > ' ')
+			while ((uint8_t)*++s->bitfmt > ' ')
 continue;
 	}
 	return 0;

Index: src/tests/lib/libutil/t_snprintb.c
diff -u src/tests/lib/libutil/t_snprintb.c:1.27 src/tests/lib/libutil/t_snprintb.c:1.28
--- src/tests/lib/libutil/t_snprintb.c:1.27	Thu Feb 22 21:04:24 2024
+++ src/tests/lib/libutil/t_snprintb.c	Sat Feb 24 12:40:00 2024
@@ -1,4 +1,4 @@
-/* $NetBSD: t_snprintb.c,v 1.27 2024/02/22 21:04:24 rillig Exp $ */
+/* $NetBSD: t_snprintb.c,v 1.28 2024/02/24 12:40:00 rillig Exp $ */
 
 /*
  * Copyright (c) 2002, 2004, 2008, 2010, 2024 The NetBSD Foundation, Inc.
@@ -32,7 +32,7 @@
 #include 
 __COPYRIGHT("@(#) Copyright (c) 2008, 2010, 2024\
  The NetBSD Foundation, inc. All rights reserved.");
-__RCSID("$NetBSD: t_snprintb.c,v 1.27 2024/02/22 21:04:24 rillig Exp $");
+__RCSID("$NetBSD: t_snprintb.c,v 1.28 2024/02/24 12:40:00 rillig Exp $");
 
 #include 
 #include 
@@ -300,9 +300,10 @@ ATF_TC_BODY(snprintb, tc)
 	h_snprintb(
 	"\020"
 	"\001least significant"
-	"\002horizontal\ttab",
+	"\002horizontal\ttab"
+	"\003\xC3\xA4",
 	0xff,
-	"0xff");
+	"0xff");
 
 	// old style, empty description
 	//



CVS commit: src

2024-02-24 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sat Feb 24 12:40:00 UTC 2024

Modified Files:
src/common/lib/libutil: snprintb.c
src/tests/lib/libutil: t_snprintb.c

Log Message:
snprintb: allow non-ASCII descriptions on all platforms

Previously, these descriptions were only allowed on platforms where
plain 'char' is unsigned. On platforms where plain 'char' is signed,
they invoked undefined behavior or terminated the output early.


To generate a diff of this commit:
cvs rdiff -u -r1.39 -r1.40 src/common/lib/libutil/snprintb.c
cvs rdiff -u -r1.27 -r1.28 src/tests/lib/libutil/t_snprintb.c

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



CVS commit: src

2024-02-22 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Thu Feb 22 21:04:24 UTC 2024

Modified Files:
src/common/lib/libutil: snprintb.c
src/lib/libutil: snprintb.3
src/tests/lib/libutil: t_snprintb.c

Log Message:
snprintb: always null-terminate output

Always null-terminate the output in the buffer, even in error cases. The
wording in the manual page has been promising this since 2008. For
snprintb_m, ensure that the output is terminated with two null
characters, to gracefully handle situations in which the caller does not
check whether snprintb returned an error.

If the buffer size is zero, allow the buffer to be a null pointer,
analogous to snprintf.

Fix an out-of-bounds memory read if the bitfmt ends with a '*' directive
(since today).

In the tests, merge the helper functions for snprintb, snprintb_m, as
they were similar enough.

Fix a few 'line_max exceeded' tests, ensuring that they output a '#'
marker, and that the 'complete' tests don't.


To generate a diff of this commit:
cvs rdiff -u -r1.38 -r1.39 src/common/lib/libutil/snprintb.c
cvs rdiff -u -r1.34 -r1.35 src/lib/libutil/snprintb.3
cvs rdiff -u -r1.26 -r1.27 src/tests/lib/libutil/t_snprintb.c

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

Modified files:

Index: src/common/lib/libutil/snprintb.c
diff -u src/common/lib/libutil/snprintb.c:1.38 src/common/lib/libutil/snprintb.c:1.39
--- src/common/lib/libutil/snprintb.c:1.38	Thu Feb 22 18:26:15 2024
+++ src/common/lib/libutil/snprintb.c	Thu Feb 22 21:04:23 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: snprintb.c,v 1.38 2024/02/22 18:26:15 rillig Exp $	*/
+/*	$NetBSD: snprintb.c,v 1.39 2024/02/22 21:04:23 rillig Exp $	*/
 
 /*-
  * Copyright (c) 2002 The NetBSD Foundation, Inc.
@@ -41,7 +41,7 @@
 
 #  include 
 #  if defined(LIBC_SCCS) && !defined(lint)
-__RCSID("$NetBSD: snprintb.c,v 1.38 2024/02/22 18:26:15 rillig Exp $");
+__RCSID("$NetBSD: snprintb.c,v 1.39 2024/02/22 21:04:23 rillig Exp $");
 #  endif
 
 #  include 
@@ -51,7 +51,7 @@ __RCSID("$NetBSD: snprintb.c,v 1.38 2024
 #  include 
 # else /* ! _KERNEL */
 #  include 
-__KERNEL_RCSID(0, "$NetBSD: snprintb.c,v 1.38 2024/02/22 18:26:15 rillig Exp $");
+__KERNEL_RCSID(0, "$NetBSD: snprintb.c,v 1.39 2024/02/22 21:04:23 rillig Exp $");
 #  include 
 #  include 
 #  include 
@@ -219,7 +219,7 @@ new_style(state *s)
 			if (store_num(s, s->bitfmt, field) < 0)
 return -1;
 			wrap_if_necessary(s, prev_bitfmt);
-			/*FALLTHROUGH*/
+			goto skip_description;
 		default:
 			s->bitfmt += 2;
 		skip_description:
@@ -231,6 +231,19 @@ new_style(state *s)
 	return 0;
 }
 
+static void
+finish_buffer(state *s)
+{
+	if (s->line_max > 0) {
+		put_eol(s);
+		if (s->bufsize >= 2 && s->total_len > s->bufsize - 2)
+			s->buf[s->bufsize - 2] = '\0';
+	}
+	store(s, '\0');
+	if (s->bufsize >= 1 && s->total_len > s->bufsize - 1)
+		s->buf[s->bufsize - 1] = '\0';
+}
+
 int
 snprintb_m(char *buf, size_t bufsize, const char *bitfmt, uint64_t val,
 	   size_t line_max)
@@ -240,10 +253,10 @@ snprintb_m(char *buf, size_t bufsize, co
 	 * For safety; no other *s*printf() do this, but in the kernel
 	 * we don't usually check the return value
 	 */
-	(void)memset(buf, 0, bufsize);
+	if (bufsize > 0)
+		(void)memset(buf, 0, bufsize);
 #endif /* _KERNEL */
 
-
 	int old = *bitfmt != '\177';
 	if (!old)
 		bitfmt++;
@@ -260,13 +273,9 @@ snprintb_m(char *buf, size_t bufsize, co
 		num_fmt = "%#jx";
 		break;
 	default:
-		goto internal;
+		num_fmt = NULL;
 	}
 
-	int val_len = snprintf(buf, bufsize, num_fmt, (uintmax_t)val);
-	if (val_len < 0)
-		goto internal;
-
 	state s = {
 		.buf = buf,
 		.bufsize = bufsize,
@@ -275,28 +284,26 @@ snprintb_m(char *buf, size_t bufsize, co
 		.line_max = line_max,
 
 		.num_fmt = num_fmt,
-		.total_len = val_len,
 		.sep = '<',
 	};
+	if (num_fmt == NULL)
+		goto internal;
+
+	store_num(, num_fmt, val);
 
 	if ((old ? old_style() : new_style()) < 0)
 		goto internal;
 
 	if (s.sep != '<')
 		store(, '>');
-	if (s.line_max > 0) {
-		put_eol();
-		if (s.bufsize >= 2 && s.total_len > s.bufsize - 2)
-			s.buf[s.bufsize - 2] = '\0';
-	}
-	store(, '\0');
-	if (s.bufsize >= 1 && s.total_len > s.bufsize - 1)
-		s.buf[s.bufsize - 1] = '\0';
+	finish_buffer();
 	return (int)(s.total_len - 1);
 internal:
 #ifndef _KERNEL
 	errno = EINVAL;
 #endif
+	store(, '#');
+	finish_buffer();
 	return -1;
 }
 

Index: src/lib/libutil/snprintb.3
diff -u src/lib/libutil/snprintb.3:1.34 src/lib/libutil/snprintb.3:1.35
--- src/lib/libutil/snprintb.3:1.34	Thu Feb 22 18:26:16 2024
+++ src/lib/libutil/snprintb.3	Thu Feb 22 21:04:24 2024
@@ -1,4 +1,4 @@
-.\" $NetBSD: snprintb.3,v 1.34 2024/02/22 18:26:16 rillig Exp $
+.\" $NetBSD: snprintb.3,v 1.35 2024/02/22 21:04:24 rillig Exp $
 .\"
 .\" Copyright (c) 1998, 2024 The NetBSD Foundation, Inc.
 .\" All rights reserved.
@@ -55,8 +55,7 @@ into the buffer
 .Fa buf ,
 of size
 .Fa bufsize ,
-using a specified radix and an 

CVS commit: src

2024-02-22 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Thu Feb 22 21:04:24 UTC 2024

Modified Files:
src/common/lib/libutil: snprintb.c
src/lib/libutil: snprintb.3
src/tests/lib/libutil: t_snprintb.c

Log Message:
snprintb: always null-terminate output

Always null-terminate the output in the buffer, even in error cases. The
wording in the manual page has been promising this since 2008. For
snprintb_m, ensure that the output is terminated with two null
characters, to gracefully handle situations in which the caller does not
check whether snprintb returned an error.

If the buffer size is zero, allow the buffer to be a null pointer,
analogous to snprintf.

Fix an out-of-bounds memory read if the bitfmt ends with a '*' directive
(since today).

In the tests, merge the helper functions for snprintb, snprintb_m, as
they were similar enough.

Fix a few 'line_max exceeded' tests, ensuring that they output a '#'
marker, and that the 'complete' tests don't.


To generate a diff of this commit:
cvs rdiff -u -r1.38 -r1.39 src/common/lib/libutil/snprintb.c
cvs rdiff -u -r1.34 -r1.35 src/lib/libutil/snprintb.3
cvs rdiff -u -r1.26 -r1.27 src/tests/lib/libutil/t_snprintb.c

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



CVS commit: src

2024-02-22 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Thu Feb 22 18:26:16 UTC 2024

Modified Files:
src/common/lib/libutil: snprintb.c
src/lib/libutil: snprintb.3
src/tests/lib/libutil: t_snprintb.c

Log Message:
snprintb: error out on out-of-bounds bit shifts

Previously, these invoked undefined behavior, now they lead to an early
return. An example of out-of-bounds bit number is in SCZ_PCICTRL_BITS.
Bit fields that extend beyond the msb are still allowed.

Allow 'f' and 'F' to have fields that are 64 bits wide. This only makes
sense when the field starts at bit 0.

Remove the unused 'val_len', it was only needed before snprintb.c 1.20.


To generate a diff of this commit:
cvs rdiff -u -r1.37 -r1.38 src/common/lib/libutil/snprintb.c
cvs rdiff -u -r1.33 -r1.34 src/lib/libutil/snprintb.3
cvs rdiff -u -r1.25 -r1.26 src/tests/lib/libutil/t_snprintb.c

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

Modified files:

Index: src/common/lib/libutil/snprintb.c
diff -u src/common/lib/libutil/snprintb.c:1.37 src/common/lib/libutil/snprintb.c:1.38
--- src/common/lib/libutil/snprintb.c:1.37	Tue Feb 20 20:31:56 2024
+++ src/common/lib/libutil/snprintb.c	Thu Feb 22 18:26:15 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: snprintb.c,v 1.37 2024/02/20 20:31:56 rillig Exp $	*/
+/*	$NetBSD: snprintb.c,v 1.38 2024/02/22 18:26:15 rillig Exp $	*/
 
 /*-
  * Copyright (c) 2002 The NetBSD Foundation, Inc.
@@ -41,7 +41,7 @@
 
 #  include 
 #  if defined(LIBC_SCCS) && !defined(lint)
-__RCSID("$NetBSD: snprintb.c,v 1.37 2024/02/20 20:31:56 rillig Exp $");
+__RCSID("$NetBSD: snprintb.c,v 1.38 2024/02/22 18:26:15 rillig Exp $");
 #  endif
 
 #  include 
@@ -51,7 +51,7 @@ __RCSID("$NetBSD: snprintb.c,v 1.37 2024
 #  include 
 # else /* ! _KERNEL */
 #  include 
-__KERNEL_RCSID(0, "$NetBSD: snprintb.c,v 1.37 2024/02/20 20:31:56 rillig Exp $");
+__KERNEL_RCSID(0, "$NetBSD: snprintb.c,v 1.38 2024/02/22 18:26:15 rillig Exp $");
 #  include 
 #  include 
 #  include 
@@ -67,7 +67,6 @@ typedef struct {
 	size_t const line_max;
 
 	const char *const num_fmt;
-	unsigned const val_len;
 	unsigned total_len;
 	unsigned line_pos;
 	unsigned comma_pos;
@@ -161,12 +160,15 @@ new_style(state *s)
 	const char *prev_bitfmt = s->bitfmt;
 	while (*s->bitfmt != '\0') {
 		const char *cur_bitfmt = s->bitfmt;
-		uint8_t kind = *s->bitfmt++;
-		uint8_t bit = *s->bitfmt++;
+		uint8_t kind = cur_bitfmt[0];
 		switch (kind) {
 		case 'b':
 			prev_bitfmt = cur_bitfmt;
-			if (((s->val >> bit) & 1) == 0)
+			uint8_t b_bit = cur_bitfmt[1];
+			if (b_bit >= 64)
+return -1;
+			s->bitfmt += 2;
+			if (((s->val >> b_bit) & 1) == 0)
 goto skip_description;
 			put_sep(s);
 			while (*s->bitfmt++ != '\0')
@@ -177,8 +179,16 @@ new_style(state *s)
 		case 'F':
 			prev_bitfmt = cur_bitfmt;
 			matched = 0;
-			field = (s->val >> bit) &
-			(((uint64_t)1 << (uint8_t)*s->bitfmt++) - 1);
+			uint8_t f_lsb = cur_bitfmt[1];
+			if (f_lsb >= 64)
+return -1;
+			uint8_t f_width = cur_bitfmt[2];
+			if (f_width > 64)
+return -1;
+			field = s->val >> f_lsb;
+			if (f_width < 64)
+field &= ((uint64_t) 1 << f_width) - 1;
+			s->bitfmt += 3;
 			put_sep(s);
 			if (kind == 'F')
 goto skip_description;
@@ -190,8 +200,9 @@ new_style(state *s)
 			break;
 		case '=':
 		case ':':
-			/* Here "bit" is actually a value instead. */
-			if (field != bit)
+			s->bitfmt += 2;
+			uint8_t cmp = cur_bitfmt[1];
+			if (field != cmp)
 goto skip_description;
 			matched = 1;
 			if (kind == '=')
@@ -201,7 +212,7 @@ new_style(state *s)
 			wrap_if_necessary(s, prev_bitfmt);
 			break;
 		case '*':
-			s->bitfmt--;
+			s->bitfmt++;
 			if (matched)
 goto skip_description;
 			matched = 1;
@@ -210,6 +221,7 @@ new_style(state *s)
 			wrap_if_necessary(s, prev_bitfmt);
 			/*FALLTHROUGH*/
 		default:
+			s->bitfmt += 2;
 		skip_description:
 			while (*s->bitfmt++ != '\0')
 continue;
@@ -263,9 +275,7 @@ snprintb_m(char *buf, size_t bufsize, co
 		.line_max = line_max,
 
 		.num_fmt = num_fmt,
-		.val_len = val_len,
 		.total_len = val_len,
-
 		.sep = '<',
 	};
 

Index: src/lib/libutil/snprintb.3
diff -u src/lib/libutil/snprintb.3:1.33 src/lib/libutil/snprintb.3:1.34
--- src/lib/libutil/snprintb.3:1.33	Tue Feb 20 20:38:54 2024
+++ src/lib/libutil/snprintb.3	Thu Feb 22 18:26:16 2024
@@ -1,6 +1,6 @@
-.\" $NetBSD: snprintb.3,v 1.33 2024/02/20 20:38:54 rillig Exp $
+.\" $NetBSD: snprintb.3,v 1.34 2024/02/22 18:26:16 rillig Exp $
 .\"
-.\" Copyright (c) 1998 The NetBSD Foundation, Inc.
+.\" Copyright (c) 1998, 2024 The NetBSD Foundation, Inc.
 .\" All rights reserved.
 .\"
 .\" This code is derived from software contributed to The NetBSD Foundation
@@ -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 February 20, 2024
+.Dd February 22, 2024
 .Dt SNPRINTB 3
 .Os
 .Sh NAME
@@ -395,6 +395,9 

CVS commit: src

2024-02-22 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Thu Feb 22 18:26:16 UTC 2024

Modified Files:
src/common/lib/libutil: snprintb.c
src/lib/libutil: snprintb.3
src/tests/lib/libutil: t_snprintb.c

Log Message:
snprintb: error out on out-of-bounds bit shifts

Previously, these invoked undefined behavior, now they lead to an early
return. An example of out-of-bounds bit number is in SCZ_PCICTRL_BITS.
Bit fields that extend beyond the msb are still allowed.

Allow 'f' and 'F' to have fields that are 64 bits wide. This only makes
sense when the field starts at bit 0.

Remove the unused 'val_len', it was only needed before snprintb.c 1.20.


To generate a diff of this commit:
cvs rdiff -u -r1.37 -r1.38 src/common/lib/libutil/snprintb.c
cvs rdiff -u -r1.33 -r1.34 src/lib/libutil/snprintb.3
cvs rdiff -u -r1.25 -r1.26 src/tests/lib/libutil/t_snprintb.c

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



CVS commit: src/tests/lib/libutil

2024-02-20 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Tue Feb 20 21:45:36 UTC 2024

Modified Files:
src/tests/lib/libutil: t_snprintb.c

Log Message:
tests/snprintb: test '=' and '*' directives that can never match


To generate a diff of this commit:
cvs rdiff -u -r1.24 -r1.25 src/tests/lib/libutil/t_snprintb.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/lib/libutil/t_snprintb.c
diff -u src/tests/lib/libutil/t_snprintb.c:1.24 src/tests/lib/libutil/t_snprintb.c:1.25
--- src/tests/lib/libutil/t_snprintb.c:1.24	Tue Feb 20 20:31:56 2024
+++ src/tests/lib/libutil/t_snprintb.c	Tue Feb 20 21:45:36 2024
@@ -1,4 +1,4 @@
-/* $NetBSD: t_snprintb.c,v 1.24 2024/02/20 20:31:56 rillig Exp $ */
+/* $NetBSD: t_snprintb.c,v 1.25 2024/02/20 21:45:36 rillig Exp $ */
 
 /*
  * Copyright (c) 2002, 2004, 2008, 2010, 2024 The NetBSD Foundation, Inc.
@@ -32,7 +32,7 @@
 #include 
 __COPYRIGHT("@(#) Copyright (c) 2008, 2010, 2024\
  The NetBSD Foundation, inc. All rights reserved.");
-__RCSID("$NetBSD: t_snprintb.c,v 1.24 2024/02/20 20:31:56 rillig Exp $");
+__RCSID("$NetBSD: t_snprintb.c,v 1.25 2024/02/20 21:45:36 rillig Exp $");
 
 #include 
 #include 
@@ -75,7 +75,9 @@ h_snprintb_loc(const char *file, size_t 
 
 	memset(buf, 'Z', sizeof(buf));
 	int rv = snprintb(buf, bufsize, bitfmt, val);
-	ATF_REQUIRE(rv >= 0);
+	ATF_CHECK_MSG(rv >= 0, "%s:%zu: unexpected rv %d", file, line, rv);
+	if (rv < 0)
+		return;
 	size_t have_bufsize = sizeof(buf);
 	while (have_bufsize > 0 && buf[have_bufsize - 1] == 'Z')
 		have_bufsize--;
@@ -681,6 +683,15 @@ ATF_TC_BODY(snprintb, tc)
 	0x3,
 	"0x3");
 
+	// new style bit-field, '=', can never match
+	h_snprintb(
+	"\177\020"
+	"f\000\007f\0"
+		"=\200never\0"
+		"=\377never\0",
+	0xff,
+	"0xff");
+
 	// new style, two separate bit-fields
 	h_snprintb(
 	"\177\020"
@@ -763,6 +774,18 @@ ATF_TC_BODY(snprintb, tc)
 	0x1122,
 	"0x1122");
 
+	// new style bit-field default, can never match
+	h_snprintb(
+	"\177\020"
+	"f\010\002f\0"
+		"=\000zero\0"
+		"=\001one\0"
+		"=\002two\0"
+		"=\003three\0"
+		"*other\0",
+	0xff00,
+	"0xff00");
+
 	// new style bit-field default, invalid conversion specifier
 	//
 	// There is no reliable way to make snprintf return an error, as such



CVS commit: src/tests/lib/libutil

2024-02-20 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Tue Feb 20 21:45:36 UTC 2024

Modified Files:
src/tests/lib/libutil: t_snprintb.c

Log Message:
tests/snprintb: test '=' and '*' directives that can never match


To generate a diff of this commit:
cvs rdiff -u -r1.24 -r1.25 src/tests/lib/libutil/t_snprintb.c

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



CVS commit: src/lib/libutil

2024-02-20 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Tue Feb 20 20:38:54 UTC 2024

Modified Files:
src/lib/libutil: snprintb.3

Log Message:
snprintb.3: sync examples with reality


To generate a diff of this commit:
cvs rdiff -u -r1.32 -r1.33 src/lib/libutil/snprintb.3

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

Modified files:

Index: src/lib/libutil/snprintb.3
diff -u src/lib/libutil/snprintb.3:1.32 src/lib/libutil/snprintb.3:1.33
--- src/lib/libutil/snprintb.3:1.32	Sun Feb 18 16:55:02 2024
+++ src/lib/libutil/snprintb.3	Tue Feb 20 20:38:54 2024
@@ -1,4 +1,4 @@
-.\" $NetBSD: snprintb.3,v 1.32 2024/02/18 16:55:02 rillig Exp $
+.\" $NetBSD: snprintb.3,v 1.33 2024/02/20 20:38:54 rillig Exp $
 .\"
 .\" Copyright (c) 1998 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 February 18, 2024
+.Dd February 20, 2024
 .Dt SNPRINTB 3
 .Os
 .Sh NAME
@@ -305,7 +305,7 @@ snprintb(buf, bufsize,
 "f\ex10\e4BURST\e0" "=\e4FOUR\e0" "=\exf""FIFTEEN\e0"
 "b\ex1fMSB\e0",
 0x800f0701)
-\(rA "0x800f0701"
+\(rA "0x800f0701"
 .Ed
 .Pp
 The same example using snprintb_m:
@@ -316,7 +316,7 @@ snprintb_m(buf, bufsize,
 "f\ex10\e4BURST\e0" "=\e4FOUR\e0" "=\exf""FIFTEEN\e0"
 "b\ex1fMSB\e0",
 0x800f0701, 34)
-\(rA "0x800f0701\e0"
+\(rA "0x800f0701\e0"
"0x800f0701\e0"
""
 .Ed
@@ -377,7 +377,7 @@ snprintb(buf, bufsize, MAP_FMT, 0x0d0012
 \(rA "0xd001234"
 
 snprintb(buf, bufsize, MAP_FMT, 0x2e00)
-\(rA "0xd001234<0x2e00"
+\(rA "0x2e00"
 .Ed
 .Sh ERRORS
 .Fn snprintb



CVS commit: src/lib/libutil

2024-02-20 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Tue Feb 20 20:38:54 UTC 2024

Modified Files:
src/lib/libutil: snprintb.3

Log Message:
snprintb.3: sync examples with reality


To generate a diff of this commit:
cvs rdiff -u -r1.32 -r1.33 src/lib/libutil/snprintb.3

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



CVS commit: src

2024-02-20 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Tue Feb 20 20:31:56 UTC 2024

Modified Files:
src/common/lib/libutil: snprintb.c
src/tests/lib/libutil: t_snprintb.c

Log Message:
snprintb_m: limit length of generated strings

The manual page promises that the 'max' argument limits the length of
the generated strings, so don't generate any strings that are longer
than that limit. Mark incomplete strings with a trailing '#' to make
them easily recognizable.


To generate a diff of this commit:
cvs rdiff -u -r1.36 -r1.37 src/common/lib/libutil/snprintb.c
cvs rdiff -u -r1.23 -r1.24 src/tests/lib/libutil/t_snprintb.c

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



CVS commit: src

2024-02-20 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Tue Feb 20 20:31:56 UTC 2024

Modified Files:
src/common/lib/libutil: snprintb.c
src/tests/lib/libutil: t_snprintb.c

Log Message:
snprintb_m: limit length of generated strings

The manual page promises that the 'max' argument limits the length of
the generated strings, so don't generate any strings that are longer
than that limit. Mark incomplete strings with a trailing '#' to make
them easily recognizable.


To generate a diff of this commit:
cvs rdiff -u -r1.36 -r1.37 src/common/lib/libutil/snprintb.c
cvs rdiff -u -r1.23 -r1.24 src/tests/lib/libutil/t_snprintb.c

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

Modified files:

Index: src/common/lib/libutil/snprintb.c
diff -u src/common/lib/libutil/snprintb.c:1.36 src/common/lib/libutil/snprintb.c:1.37
--- src/common/lib/libutil/snprintb.c:1.36	Mon Feb 19 23:30:56 2024
+++ src/common/lib/libutil/snprintb.c	Tue Feb 20 20:31:56 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: snprintb.c,v 1.36 2024/02/19 23:30:56 rillig Exp $	*/
+/*	$NetBSD: snprintb.c,v 1.37 2024/02/20 20:31:56 rillig Exp $	*/
 
 /*-
  * Copyright (c) 2002 The NetBSD Foundation, Inc.
@@ -41,7 +41,7 @@
 
 #  include 
 #  if defined(LIBC_SCCS) && !defined(lint)
-__RCSID("$NetBSD: snprintb.c,v 1.36 2024/02/19 23:30:56 rillig Exp $");
+__RCSID("$NetBSD: snprintb.c,v 1.37 2024/02/20 20:31:56 rillig Exp $");
 #  endif
 
 #  include 
@@ -51,7 +51,7 @@ __RCSID("$NetBSD: snprintb.c,v 1.36 2024
 #  include 
 # else /* ! _KERNEL */
 #  include 
-__KERNEL_RCSID(0, "$NetBSD: snprintb.c,v 1.36 2024/02/19 23:30:56 rillig Exp $");
+__KERNEL_RCSID(0, "$NetBSD: snprintb.c,v 1.37 2024/02/20 20:31:56 rillig Exp $");
 #  include 
 #  include 
 #  include 
@@ -69,13 +69,8 @@ typedef struct {
 	const char *const num_fmt;
 	unsigned const val_len;
 	unsigned total_len;
-	unsigned line_len;
-
-	const char *cur_bitfmt;
-	int restart;
-
-	const char *sep_bitfmt;
-	unsigned sep_line_len;
+	unsigned line_pos;
+	unsigned comma_pos;
 	char sep;
 } state;
 
@@ -85,100 +80,77 @@ store(state *s, char c)
 	if (s->total_len < s->bufsize)
 		s->buf[s->total_len] = c;
 	s->total_len++;
-	s->line_len++;
 }
 
-static void
-backup(state *s)
+static int
+store_num(state *s, const char *fmt, uintmax_t num)
 {
-	if (s->sep_line_len > 0) {
-		s->total_len -= s->line_len - s->sep_line_len;
-		s->sep_line_len = 0;
-		s->restart = 1;
-		s->bitfmt = s->sep_bitfmt;
-	}
-	store(s, '>');
-	store(s, '\0');
-	if (s->total_len < s->bufsize)
-		snprintf(s->buf + s->total_len, s->bufsize - s->total_len,
-		s->num_fmt, (uintmax_t)s->val);
-	s->total_len += s->val_len;
-	s->line_len = s->val_len;
+	int num_len = s->total_len < s->bufsize
+	? snprintf(s->buf + s->total_len, s->bufsize - s->total_len,
+		fmt, num)
+	: snprintf(NULL, 0, fmt, num);
+	if (num_len > 0)
+		s->total_len += num_len;
+	return num_len;
 }
 
 static void
-put_sep(state *s)
+put_eol(state *s)
 {
-	if (s->line_max > 0 && s->line_len >= s->line_max) {
-		backup(s);
-		store(s, '<');
-	} else {
-		if (s->line_max > 0 && s->sep != '<') {
-			s->sep_line_len = s->line_len;
-			s->sep_bitfmt = s->cur_bitfmt;
-		}
-		store(s, s->sep);
-		s->restart = 0;
+	if (s->total_len - s->line_pos > s->line_max) {
+		s->total_len = (unsigned)(s->line_pos + s->line_max - 1);
+		store(s, '#');
 	}
+	store(s, '\0');
+	s->line_pos = s->total_len;
+	s->comma_pos = 0;
+	s->sep = '<';
 }
 
 static void
-put_chr(state *s, char c)
+put_sep(state *s)
 {
-	if (s->line_max > 0 && s->line_len >= s->line_max - 1) {
-		backup(s);
-		if (s->restart == 0)
-			store(s, c);
-		else
-			s->sep = '<';
+	if (s->sep == ',') {
+		s->comma_pos = s->total_len;
+		store(s, ',');
 	} else {
-		store(s, c);
-		s->restart = 0;
+		store(s, '<');
+		s->sep = ',';
 	}
 }
 
 static void
-put_bitfmt(state *s)
+wrap_if_necessary(state *s, const char *bitfmt)
 {
-	while (*s->bitfmt++ != 0) {
-		put_chr(s, s->bitfmt[-1]);
-		if (s->restart)
-			break;
+	if (s->line_max > 0
+	&& s->comma_pos > 0
+	&& s->total_len - s->line_pos >= s->line_max) {
+		s->total_len = s->comma_pos;
+		store(s, '>');
+		put_eol(s);
+		store_num(s, s->num_fmt, s->val);
+		s->bitfmt = bitfmt;
 	}
 }
 
 static int
-put_num(state *s, const char *fmt, uintmax_t v)
-{
-	char *bp = s->total_len < s->bufsize ? s->buf + s->total_len : NULL;
-	size_t n = s->total_len < s->bufsize ? s->bufsize - s->total_len : 0;
-	int fmt_len = snprintf(bp, n, fmt, v);
-	if (fmt_len >= 0) {
-		s->total_len += fmt_len;
-		s->line_len += fmt_len;
-	}
-	return fmt_len;
-}
-
-static void
 old_style(state *s)
 {
-	for (uint8_t bit; (bit = *s->bitfmt) != 0;) {
-		s->cur_bitfmt = s->bitfmt++;
+	while (*s->bitfmt != '\0') {
+		const char *cur_bitfmt = s->bitfmt;
+		uint8_t bit = *s->bitfmt;
+		if (bit > ' ')
+			return -1;
 		if (s->val & (1U << (bit - 1))) {
 			put_sep(s);
-			if (s->restart)
-continue;
-			s->sep = ',';
-			for (; *s->bitfmt 

CVS commit: src/tests/lib/libutil

2024-02-20 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Tue Feb 20 19:49:10 UTC 2024

Modified Files:
src/tests/lib/libutil: t_snprintb.c

Log Message:
tests/snprintb: fix out-of-bounds memory read (since 2024-02-16)

Before t_snprintb.c 1.20, the buffer size was required to be greater
than zero. Allowing the buffer size to be zero led to buf[-1] being
checked. On amd64, that byte happened to be 0, on i386 it didn't.

Fixes PR lib/57951.


To generate a diff of this commit:
cvs rdiff -u -r1.22 -r1.23 src/tests/lib/libutil/t_snprintb.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/lib/libutil/t_snprintb.c
diff -u src/tests/lib/libutil/t_snprintb.c:1.22 src/tests/lib/libutil/t_snprintb.c:1.23
--- src/tests/lib/libutil/t_snprintb.c:1.22	Mon Feb 19 23:30:56 2024
+++ src/tests/lib/libutil/t_snprintb.c	Tue Feb 20 19:49:10 2024
@@ -1,4 +1,4 @@
-/* $NetBSD: t_snprintb.c,v 1.22 2024/02/19 23:30:56 rillig Exp $ */
+/* $NetBSD: t_snprintb.c,v 1.23 2024/02/20 19:49:10 rillig Exp $ */
 
 /*
  * Copyright (c) 2002, 2004, 2008, 2010, 2024 The NetBSD Foundation, Inc.
@@ -32,7 +32,7 @@
 #include 
 __COPYRIGHT("@(#) Copyright (c) 2008, 2010, 2024\
  The NetBSD Foundation, inc. All rights reserved.");
-__RCSID("$NetBSD: t_snprintb.c,v 1.22 2024/02/19 23:30:56 rillig Exp $");
+__RCSID("$NetBSD: t_snprintb.c,v 1.23 2024/02/20 19:49:10 rillig Exp $");
 
 #include 
 #include 
@@ -48,9 +48,11 @@ vis_arr(const char *arr, size_t arrsize)
 	static size_t i;
 
 	i = (i + 1) % (sizeof(buf) / sizeof(buf[0]));
-	int rv = strnvisx(buf[i], sizeof(buf[i]), arr, arrsize,
+	buf[i][0] = '"';
+	int rv = strnvisx(buf[i] + 1, sizeof(buf[i]) - 2, arr, arrsize,
 	VIS_WHITE | VIS_OCTAL);
 	ATF_REQUIRE_MSG(rv >= 0, "strnvisx failed for size %zu", arrsize);
+	strcpy(buf[i] + 1 + rv, "\"");
 	return buf[i];
 }
 
@@ -95,7 +97,8 @@ h_snprintb_loc(const char *file, size_t 
 	ATF_CHECK_MSG(
 	rv == want_rv
 	&& memcmp(buf, want_buf, want_bufsize) == 0
-	&& buf[rlen < bufsize ? rlen : bufsize - 1] == '\0',
+	&& (bufsize < 1
+		|| buf[rlen < bufsize ? rlen : bufsize - 1] == '\0'),
 	"failed:\n"
 	"\ttest case: %s:%zu\n"
 	"\tformat: %s\n"
@@ -1110,7 +1113,12 @@ h_snprintb_m_loc(const char *file, size_
 
 	size_t total = rv;
 	ATF_CHECK_MSG(
-	total == want_rv && memcmp(buf, want_buf, want_bufsize) == 0,
+	total == want_rv
+	&& memcmp(buf, want_buf, want_bufsize) == 0
+	&& (bufsize < 1
+		|| buf[total < bufsize ? total : bufsize - 1] == '\0')
+	&& (bufsize < 2
+		|| buf[total < bufsize ? total - 1 : bufsize - 2] == '\0'),
 	"failed:\n"
 	"\ttest case: %s:%zu\n"
 	"\tformat: %s\n"



CVS commit: src/tests/lib/libutil

2024-02-20 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Tue Feb 20 19:49:10 UTC 2024

Modified Files:
src/tests/lib/libutil: t_snprintb.c

Log Message:
tests/snprintb: fix out-of-bounds memory read (since 2024-02-16)

Before t_snprintb.c 1.20, the buffer size was required to be greater
than zero. Allowing the buffer size to be zero led to buf[-1] being
checked. On amd64, that byte happened to be 0, on i386 it didn't.

Fixes PR lib/57951.


To generate a diff of this commit:
cvs rdiff -u -r1.22 -r1.23 src/tests/lib/libutil/t_snprintb.c

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



CVS commit: src

2024-02-19 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Mon Feb 19 23:30:56 UTC 2024

Modified Files:
src/common/lib/libutil: snprintb.c
src/tests/lib/libutil: t_snprintb.c

Log Message:
snprintb: fix how named bit-fields are split into multiple lines


To generate a diff of this commit:
cvs rdiff -u -r1.35 -r1.36 src/common/lib/libutil/snprintb.c
cvs rdiff -u -r1.21 -r1.22 src/tests/lib/libutil/t_snprintb.c

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

Modified files:

Index: src/common/lib/libutil/snprintb.c
diff -u src/common/lib/libutil/snprintb.c:1.35 src/common/lib/libutil/snprintb.c:1.36
--- src/common/lib/libutil/snprintb.c:1.35	Sat Feb 17 10:23:30 2024
+++ src/common/lib/libutil/snprintb.c	Mon Feb 19 23:30:56 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: snprintb.c,v 1.35 2024/02/17 10:23:30 rillig Exp $	*/
+/*	$NetBSD: snprintb.c,v 1.36 2024/02/19 23:30:56 rillig Exp $	*/
 
 /*-
  * Copyright (c) 2002 The NetBSD Foundation, Inc.
@@ -41,7 +41,7 @@
 
 #  include 
 #  if defined(LIBC_SCCS) && !defined(lint)
-__RCSID("$NetBSD: snprintb.c,v 1.35 2024/02/17 10:23:30 rillig Exp $");
+__RCSID("$NetBSD: snprintb.c,v 1.36 2024/02/19 23:30:56 rillig Exp $");
 #  endif
 
 #  include 
@@ -51,7 +51,7 @@ __RCSID("$NetBSD: snprintb.c,v 1.35 2024
 #  include 
 # else /* ! _KERNEL */
 #  include 
-__KERNEL_RCSID(0, "$NetBSD: snprintb.c,v 1.35 2024/02/17 10:23:30 rillig Exp $");
+__KERNEL_RCSID(0, "$NetBSD: snprintb.c,v 1.36 2024/02/19 23:30:56 rillig Exp $");
 #  include 
 #  include 
 #  include 
@@ -233,7 +233,8 @@ new_style(state *s)
 			matched = 1;
 			if (kind == '=')
 put_chr(s, '=');
-			put_bitfmt(s);
+			if (s->restart == 0)
+put_bitfmt(s);
 			break;
 		case '*':
 			s->bitfmt--;

Index: src/tests/lib/libutil/t_snprintb.c
diff -u src/tests/lib/libutil/t_snprintb.c:1.21 src/tests/lib/libutil/t_snprintb.c:1.22
--- src/tests/lib/libutil/t_snprintb.c:1.21	Mon Feb 19 23:22:03 2024
+++ src/tests/lib/libutil/t_snprintb.c	Mon Feb 19 23:30:56 2024
@@ -1,4 +1,4 @@
-/* $NetBSD: t_snprintb.c,v 1.21 2024/02/19 23:22:03 rillig Exp $ */
+/* $NetBSD: t_snprintb.c,v 1.22 2024/02/19 23:30:56 rillig Exp $ */
 
 /*
  * Copyright (c) 2002, 2004, 2008, 2010, 2024 The NetBSD Foundation, Inc.
@@ -32,7 +32,7 @@
 #include 
 __COPYRIGHT("@(#) Copyright (c) 2008, 2010, 2024\
  The NetBSD Foundation, inc. All rights reserved.");
-__RCSID("$NetBSD: t_snprintb.c,v 1.21 2024/02/19 23:22:03 rillig Exp $");
+__RCSID("$NetBSD: t_snprintb.c,v 1.22 2024/02/19 23:30:56 rillig Exp $");
 
 #include 
 #include 
@@ -1462,7 +1462,7 @@ ATF_TC_BODY(snprintb_m, tc)
 	0xff,
 	24,
 	"0xff\0"
-	"0xfff=match\0");		// FIXME: incomplete
+	"0xff\0");
 
 	// new style, line_max exceeded by unnamed bit-field number in line 1
 	h_snprintb_m(
@@ -1567,10 +1567,7 @@ ATF_TC_BODY(snprintb_m, tc)
 	0x800f0701,
 	34,
 	"0x800f0701\0"
-	// FIXME: The '\020\004' is wrong.
-	// FIXME: The '=0xf' is missing.
-	// FIXME: The '<' is in the wrong place.
-	"0x800f0701f\020\004BURST=FIFTEEN\0");
+	"0x800f0701\0");
 
 	// new style, buffer too small for complete number in line 2
 	h_snprintb_m_len(



CVS commit: src

2024-02-19 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Mon Feb 19 23:30:56 UTC 2024

Modified Files:
src/common/lib/libutil: snprintb.c
src/tests/lib/libutil: t_snprintb.c

Log Message:
snprintb: fix how named bit-fields are split into multiple lines


To generate a diff of this commit:
cvs rdiff -u -r1.35 -r1.36 src/common/lib/libutil/snprintb.c
cvs rdiff -u -r1.21 -r1.22 src/tests/lib/libutil/t_snprintb.c

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



CVS commit: src/tests/lib/libutil

2024-02-19 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Mon Feb 19 23:22:03 UTC 2024

Modified Files:
src/tests/lib/libutil: t_snprintb.c

Log Message:
tests/snprintb: add more tests, especially for snprintb_m


To generate a diff of this commit:
cvs rdiff -u -r1.20 -r1.21 src/tests/lib/libutil/t_snprintb.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/lib/libutil/t_snprintb.c
diff -u src/tests/lib/libutil/t_snprintb.c:1.20 src/tests/lib/libutil/t_snprintb.c:1.21
--- src/tests/lib/libutil/t_snprintb.c:1.20	Fri Feb 16 19:53:40 2024
+++ src/tests/lib/libutil/t_snprintb.c	Mon Feb 19 23:22:03 2024
@@ -1,4 +1,4 @@
-/* $NetBSD: t_snprintb.c,v 1.20 2024/02/16 19:53:40 rillig Exp $ */
+/* $NetBSD: t_snprintb.c,v 1.21 2024/02/19 23:22:03 rillig Exp $ */
 
 /*
  * Copyright (c) 2002, 2004, 2008, 2010, 2024 The NetBSD Foundation, Inc.
@@ -30,9 +30,9 @@
  */
 
 #include 
-__COPYRIGHT("@(#) Copyright (c) 2008, 2010\
+__COPYRIGHT("@(#) Copyright (c) 2008, 2010, 2024\
  The NetBSD Foundation, inc. All rights reserved.");
-__RCSID("$NetBSD: t_snprintb.c,v 1.20 2024/02/16 19:53:40 rillig Exp $");
+__RCSID("$NetBSD: t_snprintb.c,v 1.21 2024/02/19 23:22:03 rillig Exp $");
 
 #include 
 #include 
@@ -58,40 +58,43 @@ static void
 check_unmodified_loc(const char *file, size_t line,
 const char *arr, size_t begin, size_t end)
 {
-	size_t mod_begin = begin, mod_end = end;
-	while (mod_begin < mod_end && arr[mod_begin] == 'Z')
-		mod_begin++;
-	while (mod_begin < mod_end && arr[mod_end - 1] == 'Z')
-		mod_end--;
+	while (begin < end && arr[begin] == 'Z')
+		begin++;
+	while (begin < end && arr[end - 1] == 'Z')
+		end--;
 	ATF_CHECK_MSG(
-	mod_begin == mod_end,
+	begin == end,
 	"failed:\n"
 	"\ttest case: %s:%zu\n"
 	"\tout-of-bounds write from %zu to %zu: %s\n",
 	file, line,
-	mod_begin, mod_end, vis_arr(arr + mod_begin, mod_end - mod_begin));
+	begin, end, vis_arr(arr + begin, end - begin));
 }
 
 static void
 h_snprintb_loc(const char *file, size_t line,
-size_t bufsize, const char *fmt, size_t fmtlen, uint64_t val,
-int exp_rv, const char *res, size_t reslen)
+size_t bufsize, const char *bitfmt, size_t bitfmtlen, uint64_t val,
+int want_rv, const char *want_buf, size_t want_bufsize)
 {
 	char buf[1024];
 
 	ATF_REQUIRE(bufsize <= sizeof(buf));
-	ATF_REQUIRE(reslen <= sizeof(buf));
+	ATF_REQUIRE(want_bufsize <= sizeof(buf));
+	if (bitfmtlen > 2 && bitfmt[0] == '\177')
+		ATF_REQUIRE_MSG(bitfmt[bitfmtlen - 1] == '\0',
+		"%s:%zu: missing trailing '\\0' in bitfmt",
+		file, line);
+	if (bufsize == 0 && want_bufsize == 1)
+		want_bufsize = 0;
 
 	memset(buf, 'Z', sizeof(buf));
-	int rv = snprintb(buf, bufsize, fmt, val);
+	int rv = snprintb(buf, bufsize, bitfmt, val);
 	ATF_REQUIRE(rv >= 0);
 	size_t rlen = rv;
 
-	if (bufsize == 0 && reslen == 1)
-		reslen = 0;
 	ATF_CHECK_MSG(
-	rv == exp_rv
-	&& memcmp(buf, res, reslen) == 0
+	rv == want_rv
+	&& memcmp(buf, want_buf, want_bufsize) == 0
 	&& buf[rlen < bufsize ? rlen : bufsize - 1] == '\0',
 	"failed:\n"
 	"\ttest case: %s:%zu\n"
@@ -100,28 +103,28 @@ h_snprintb_loc(const char *file, size_t 
 	"\twant: %d bytes %s\n"
 	"\thave: %d bytes %s\n",
 	file, line,
-	vis_arr(fmt, fmtlen),
+	vis_arr(bitfmt, bitfmtlen),
 	(uintmax_t)val,
-	exp_rv, vis_arr(res, reslen),
-	rv, vis_arr(buf, reslen));
-	check_unmodified_loc(file, line, buf, reslen, sizeof(buf));
+	want_rv, vis_arr(want_buf, want_bufsize),
+	rv, vis_arr(buf, want_bufsize));
+	check_unmodified_loc(file, line, buf, want_bufsize, sizeof(buf));
 }
 
-#define	h_snprintb_len(bufsize, fmt, val, exp_rv, res)			\
+#define	h_snprintb_len(bufsize, bitfmt, val, want_rv, want_buf)		\
 	h_snprintb_loc(__FILE__, __LINE__,\
-	bufsize, fmt, sizeof(fmt) - 1, val,\
-	exp_rv, res, sizeof(res))
-#define	h_snprintb(fmt, val, res)	\
-	h_snprintb_len(1024, fmt, val, sizeof(res) - 1, res)
+	bufsize, bitfmt, sizeof(bitfmt) - 1, val,			\
+	want_rv, want_buf, sizeof(want_buf))
+#define	h_snprintb(bitfmt, val, want_buf)\
+	h_snprintb_len(1024, bitfmt, val, sizeof(want_buf) - 1, want_buf)
 
 static void
 h_snprintb_error_loc(const char *file, size_t line,
-const char *fmt, size_t fmtlen)
+const char *bitfmt, size_t bitfmtlen)
 {
 	char buf[1024];
 
 	memset(buf, 'Z', sizeof(buf));
-	int rv = snprintb(buf, sizeof(buf), fmt, 0);
+	int rv = snprintb(buf, sizeof(buf), bitfmt, 0);
 	size_t buflen = rv;
 
 	ATF_REQUIRE(rv >= -1);
@@ -131,12 +134,12 @@ h_snprintb_error_loc(const char *file, s
 	"\tformat: %s\n"
 	"\tresult: %zu bytes %s\n",
 	file, line,
-	vis_arr(fmt, fmtlen),
+	vis_arr(bitfmt, bitfmtlen),
 	buflen, vis_arr(buf, buflen));
 }
 
-#define	h_snprintb_error(fmt)		\
-	h_snprintb_error_loc(__FILE__, __LINE__, fmt, sizeof(fmt) - 1)
+#define	

CVS commit: src/tests/lib/libutil

2024-02-19 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Mon Feb 19 23:22:03 UTC 2024

Modified Files:
src/tests/lib/libutil: t_snprintb.c

Log Message:
tests/snprintb: add more tests, especially for snprintb_m


To generate a diff of this commit:
cvs rdiff -u -r1.20 -r1.21 src/tests/lib/libutil/t_snprintb.c

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



CVS commit: src

2024-02-18 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sun Feb 18 16:55:02 UTC 2024

Modified Files:
src/lib/libutil: snprintb.3
src/sys/sys: mman.h

Log Message:
mman.h: fix snprintb description for alignment 2^60


To generate a diff of this commit:
cvs rdiff -u -r1.31 -r1.32 src/lib/libutil/snprintb.3
cvs rdiff -u -r1.64 -r1.65 src/sys/sys/mman.h

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



CVS commit: src

2024-02-18 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sun Feb 18 16:55:02 UTC 2024

Modified Files:
src/lib/libutil: snprintb.3
src/sys/sys: mman.h

Log Message:
mman.h: fix snprintb description for alignment 2^60


To generate a diff of this commit:
cvs rdiff -u -r1.31 -r1.32 src/lib/libutil/snprintb.3
cvs rdiff -u -r1.64 -r1.65 src/sys/sys/mman.h

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

Modified files:

Index: src/lib/libutil/snprintb.3
diff -u src/lib/libutil/snprintb.3:1.31 src/lib/libutil/snprintb.3:1.32
--- src/lib/libutil/snprintb.3:1.31	Thu Feb 15 22:48:58 2024
+++ src/lib/libutil/snprintb.3	Sun Feb 18 16:55:02 2024
@@ -1,4 +1,4 @@
-.\" $NetBSD: snprintb.3,v 1.31 2024/02/15 22:48:58 rillig Exp $
+.\" $NetBSD: snprintb.3,v 1.32 2024/02/18 16:55:02 rillig Exp $
 .\"
 .\" Copyright (c) 1998 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 February 15, 2024
+.Dd February 18, 2024
 .Dt SNPRINTB 3
 .Os
 .Sh NAME
@@ -323,7 +323,7 @@ snprintb_m(buf, bufsize,
 .Pp
 A more complex example from
 .In sys/mman.h
-that uses the both bit position
+that uses both the bit position
 .Sq Cm b
 formatting as well as the
 .Sq Cm F
@@ -370,7 +370,7 @@ multibit field formatting with a default
 ":\e060" "ALIGN=256TB\e0" \e
 ":\e064" "ALIGN=4PB\e0"   \e
 ":\e070" "ALIGN=64PB\e0"  \e
-":\e074" "ALIGN=256PB\e0" \e
+":\e074" "ALIGN=1EB\e0"   \e
 "*" "ALIGN=2^%ju\e0"
 
 snprintb(buf, bufsize, MAP_FMT, 0x0d001234)

Index: src/sys/sys/mman.h
diff -u src/sys/sys/mman.h:1.64 src/sys/sys/mman.h:1.65
--- src/sys/sys/mman.h:1.64	Mon Jul 10 18:22:31 2023
+++ src/sys/sys/mman.h	Sun Feb 18 16:55:02 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: mman.h,v 1.64 2023/07/10 18:22:31 christos Exp $	*/
+/*	$NetBSD: mman.h,v 1.65 2024/02/18 16:55:02 rillig Exp $	*/
 
 /*-
  * Copyright (c) 1982, 1986, 1993
@@ -157,7 +157,7 @@ typedef	__off_t		off_t;		/* file offset 
 		":\060" "ALIGN=256TB\0"		\
 		":\064" "ALIGN=4PB\0"		\
 		":\070" "ALIGN=64PB\0"		\
-		":\074" "ALIGN=256PB\0"		\
+		":\074" "ALIGN=1EB\0"		\
 		"*"	"ALIGN=2^%ju\0"
 #endif
 



CVS commit: src/common/lib/libutil

2024-02-17 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sat Feb 17 10:23:30 UTC 2024

Modified Files:
src/common/lib/libutil: snprintb.c

Log Message:
snprintb: convert macros to local functions

Let the compiler decide whether to inline the functions; allow stepping
through the code in a debugger.


To generate a diff of this commit:
cvs rdiff -u -r1.34 -r1.35 src/common/lib/libutil/snprintb.c

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

Modified files:

Index: src/common/lib/libutil/snprintb.c
diff -u src/common/lib/libutil/snprintb.c:1.34 src/common/lib/libutil/snprintb.c:1.35
--- src/common/lib/libutil/snprintb.c:1.34	Fri Feb 16 21:25:46 2024
+++ src/common/lib/libutil/snprintb.c	Sat Feb 17 10:23:30 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: snprintb.c,v 1.34 2024/02/16 21:25:46 rillig Exp $	*/
+/*	$NetBSD: snprintb.c,v 1.35 2024/02/17 10:23:30 rillig Exp $	*/
 
 /*-
  * Copyright (c) 2002 The NetBSD Foundation, Inc.
@@ -41,7 +41,7 @@
 
 #  include 
 #  if defined(LIBC_SCCS) && !defined(lint)
-__RCSID("$NetBSD: snprintb.c,v 1.34 2024/02/16 21:25:46 rillig Exp $");
+__RCSID("$NetBSD: snprintb.c,v 1.35 2024/02/17 10:23:30 rillig Exp $");
 #  endif
 
 #  include 
@@ -51,7 +51,7 @@ __RCSID("$NetBSD: snprintb.c,v 1.34 2024
 #  include 
 # else /* ! _KERNEL */
 #  include 
-__KERNEL_RCSID(0, "$NetBSD: snprintb.c,v 1.34 2024/02/16 21:25:46 rillig Exp $");
+__KERNEL_RCSID(0, "$NetBSD: snprintb.c,v 1.35 2024/02/17 10:23:30 rillig Exp $");
 #  include 
 #  include 
 #  include 
@@ -59,14 +59,204 @@ __KERNEL_RCSID(0, "$NetBSD: snprintb.c,v
 # endif /* ! _KERNEL */
 
 # ifndef HAVE_SNPRINTB_M
+typedef struct {
+	char *const buf;
+	size_t const bufsize;
+	const char *bitfmt;
+	uint64_t const val;
+	size_t const line_max;
+
+	const char *const num_fmt;
+	unsigned const val_len;
+	unsigned total_len;
+	unsigned line_len;
+
+	const char *cur_bitfmt;
+	int restart;
+
+	const char *sep_bitfmt;
+	unsigned sep_line_len;
+	char sep;
+} state;
+
+static void
+store(state *s, char c)
+{
+	if (s->total_len < s->bufsize)
+		s->buf[s->total_len] = c;
+	s->total_len++;
+	s->line_len++;
+}
+
+static void
+backup(state *s)
+{
+	if (s->sep_line_len > 0) {
+		s->total_len -= s->line_len - s->sep_line_len;
+		s->sep_line_len = 0;
+		s->restart = 1;
+		s->bitfmt = s->sep_bitfmt;
+	}
+	store(s, '>');
+	store(s, '\0');
+	if (s->total_len < s->bufsize)
+		snprintf(s->buf + s->total_len, s->bufsize - s->total_len,
+		s->num_fmt, (uintmax_t)s->val);
+	s->total_len += s->val_len;
+	s->line_len = s->val_len;
+}
+
+static void
+put_sep(state *s)
+{
+	if (s->line_max > 0 && s->line_len >= s->line_max) {
+		backup(s);
+		store(s, '<');
+	} else {
+		if (s->line_max > 0 && s->sep != '<') {
+			s->sep_line_len = s->line_len;
+			s->sep_bitfmt = s->cur_bitfmt;
+		}
+		store(s, s->sep);
+		s->restart = 0;
+	}
+}
+
+static void
+put_chr(state *s, char c)
+{
+	if (s->line_max > 0 && s->line_len >= s->line_max - 1) {
+		backup(s);
+		if (s->restart == 0)
+			store(s, c);
+		else
+			s->sep = '<';
+	} else {
+		store(s, c);
+		s->restart = 0;
+	}
+}
+
+static void
+put_bitfmt(state *s)
+{
+	while (*s->bitfmt++ != 0) {
+		put_chr(s, s->bitfmt[-1]);
+		if (s->restart)
+			break;
+	}
+}
+
+static int
+put_num(state *s, const char *fmt, uintmax_t v)
+{
+	char *bp = s->total_len < s->bufsize ? s->buf + s->total_len : NULL;
+	size_t n = s->total_len < s->bufsize ? s->bufsize - s->total_len : 0;
+	int fmt_len = snprintf(bp, n, fmt, v);
+	if (fmt_len >= 0) {
+		s->total_len += fmt_len;
+		s->line_len += fmt_len;
+	}
+	return fmt_len;
+}
+
+static void
+old_style(state *s)
+{
+	for (uint8_t bit; (bit = *s->bitfmt) != 0;) {
+		s->cur_bitfmt = s->bitfmt++;
+		if (s->val & (1U << (bit - 1))) {
+			put_sep(s);
+			if (s->restart)
+continue;
+			s->sep = ',';
+			for (; *s->bitfmt > ' '; ++s->bitfmt) {
+put_chr(s, *s->bitfmt);
+if (s->restart)
+	break;
+			}
+		} else
+			for (; *s->bitfmt > ' '; ++s->bitfmt)
+continue;
+	}
+}
+
+static int
+new_style(state *s)
+{
+	uint64_t field = s->val;
+	int matched = 1;
+	while (*s->bitfmt != '\0') {
+		uint8_t kind = *s->bitfmt++;
+		uint8_t bit = *s->bitfmt++;
+		switch (kind) {
+		case 'b':
+			if (((s->val >> bit) & 1) == 0)
+goto skip;
+			s->cur_bitfmt = s->bitfmt - 2;
+			put_sep(s);
+			if (s->restart)
+break;
+			put_bitfmt(s);
+			if (s->restart == 0)
+s->sep = ',';
+			break;
+		case 'f':
+		case 'F':
+			matched = 0;
+			s->cur_bitfmt = s->bitfmt - 2;
+			uint8_t field_width = *s->bitfmt++;
+			field = (s->val >> bit) &
+			(((uint64_t)1 << field_width) - 1);
+			put_sep(s);
+			if (s->restart == 0)
+s->sep = ',';
+			if (kind == 'F')
+goto skip;
+			if (s->restart == 0)
+put_bitfmt(s);
+			if (s->restart == 0)
+put_chr(s, '=');
+			if (s->restart == 0) {
+if (put_num(s, s->num_fmt, field) < 0)
+	return -1;
+if (s->line_max > 0
+&& s->line_len > s->line_max)
+	

CVS commit: src/common/lib/libutil

2024-02-17 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sat Feb 17 10:23:30 UTC 2024

Modified Files:
src/common/lib/libutil: snprintb.c

Log Message:
snprintb: convert macros to local functions

Let the compiler decide whether to inline the functions; allow stepping
through the code in a debugger.


To generate a diff of this commit:
cvs rdiff -u -r1.34 -r1.35 src/common/lib/libutil/snprintb.c

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



CVS commit: src/common/lib/libutil

2024-02-16 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Fri Feb 16 21:25:46 UTC 2024

Modified Files:
src/common/lib/libutil: snprintb.c

Log Message:
snprintb: do not modify bufsize when producing multiple lines


To generate a diff of this commit:
cvs rdiff -u -r1.33 -r1.34 src/common/lib/libutil/snprintb.c

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

Modified files:

Index: src/common/lib/libutil/snprintb.c
diff -u src/common/lib/libutil/snprintb.c:1.33 src/common/lib/libutil/snprintb.c:1.34
--- src/common/lib/libutil/snprintb.c:1.33	Fri Feb 16 19:53:40 2024
+++ src/common/lib/libutil/snprintb.c	Fri Feb 16 21:25:46 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: snprintb.c,v 1.33 2024/02/16 19:53:40 rillig Exp $	*/
+/*	$NetBSD: snprintb.c,v 1.34 2024/02/16 21:25:46 rillig Exp $	*/
 
 /*-
  * Copyright (c) 2002 The NetBSD Foundation, Inc.
@@ -41,7 +41,7 @@
 
 #  include 
 #  if defined(LIBC_SCCS) && !defined(lint)
-__RCSID("$NetBSD: snprintb.c,v 1.33 2024/02/16 19:53:40 rillig Exp $");
+__RCSID("$NetBSD: snprintb.c,v 1.34 2024/02/16 21:25:46 rillig Exp $");
 #  endif
 
 #  include 
@@ -51,7 +51,7 @@ __RCSID("$NetBSD: snprintb.c,v 1.33 2024
 #  include 
 # else /* ! _KERNEL */
 #  include 
-__KERNEL_RCSID(0, "$NetBSD: snprintb.c,v 1.33 2024/02/16 19:53:40 rillig Exp $");
+__KERNEL_RCSID(0, "$NetBSD: snprintb.c,v 1.34 2024/02/16 21:25:46 rillig Exp $");
 #  include 
 #  include 
 #  include 
@@ -92,10 +92,6 @@ snprintb_m(char *buf, size_t bufsize, co
 		goto internal;
 	}
 
-	/* Reserve space for trailing blank line if needed */
-	if (line_max > 0)
-		bufsize--;
-
 	int val_len = snprintf(buf, bufsize, num_fmt, (uintmax_t)val);
 	if (val_len < 0)
 		goto internal;
@@ -268,13 +264,12 @@ snprintb_m(char *buf, size_t bufsize, co
 	if (sep != '<')
 		STORE('>');
 	if (line_max > 0) {
-		bufsize++;
 		STORE('\0');
-		if (total_len >= bufsize && bufsize > 1)
+		if (bufsize >= 2 && total_len > bufsize - 2)
 			buf[bufsize - 2] = '\0';
 	}
 	STORE('\0');
-	if (total_len >= bufsize && bufsize > 0)
+	if (bufsize >= 1 && total_len > bufsize - 1)
 		buf[bufsize - 1] = '\0';
 	return (int)(total_len - 1);
 internal:



CVS commit: src/common/lib/libutil

2024-02-16 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Fri Feb 16 21:25:46 UTC 2024

Modified Files:
src/common/lib/libutil: snprintb.c

Log Message:
snprintb: do not modify bufsize when producing multiple lines


To generate a diff of this commit:
cvs rdiff -u -r1.33 -r1.34 src/common/lib/libutil/snprintb.c

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



CVS commit: src

2024-02-16 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Fri Feb 16 19:53:40 UTC 2024

Modified Files:
src/common/lib/libutil: snprintb.c
src/tests/lib/libutil: t_snprintb.c

Log Message:
snprintb: eliminate two local variables, allow zero-size buffer

Like snprintf, the buffer size may be zero. Unlike snprintf, the buffer
must not be NULL.


To generate a diff of this commit:
cvs rdiff -u -r1.32 -r1.33 src/common/lib/libutil/snprintb.c
cvs rdiff -u -r1.19 -r1.20 src/tests/lib/libutil/t_snprintb.c

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

Modified files:

Index: src/common/lib/libutil/snprintb.c
diff -u src/common/lib/libutil/snprintb.c:1.32 src/common/lib/libutil/snprintb.c:1.33
--- src/common/lib/libutil/snprintb.c:1.32	Fri Feb 16 19:31:25 2024
+++ src/common/lib/libutil/snprintb.c	Fri Feb 16 19:53:40 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: snprintb.c,v 1.32 2024/02/16 19:31:25 rillig Exp $	*/
+/*	$NetBSD: snprintb.c,v 1.33 2024/02/16 19:53:40 rillig Exp $	*/
 
 /*-
  * Copyright (c) 2002 The NetBSD Foundation, Inc.
@@ -41,7 +41,7 @@
 
 #  include 
 #  if defined(LIBC_SCCS) && !defined(lint)
-__RCSID("$NetBSD: snprintb.c,v 1.32 2024/02/16 19:31:25 rillig Exp $");
+__RCSID("$NetBSD: snprintb.c,v 1.33 2024/02/16 19:53:40 rillig Exp $");
 #  endif
 
 #  include 
@@ -51,7 +51,7 @@ __RCSID("$NetBSD: snprintb.c,v 1.32 2024
 #  include 
 # else /* ! _KERNEL */
 #  include 
-__KERNEL_RCSID(0, "$NetBSD: snprintb.c,v 1.32 2024/02/16 19:31:25 rillig Exp $");
+__KERNEL_RCSID(0, "$NetBSD: snprintb.c,v 1.33 2024/02/16 19:53:40 rillig Exp $");
 #  include 
 #  include 
 #  include 
@@ -63,7 +63,6 @@ int
 snprintb_m(char *buf, size_t bufsize, const char *bitfmt, uint64_t val,
 	   size_t line_max)
 {
-	char *bp = buf, *sep_bp = NULL;
 	const char *num_fmt, *cur_bitfmt, *sep_bitfmt = NULL;
 	char sep;
 	int restart = 0;
@@ -97,39 +96,33 @@ snprintb_m(char *buf, size_t bufsize, co
 	if (line_max > 0)
 		bufsize--;
 
-	int val_len = snprintf(bp, bufsize, num_fmt, (uintmax_t)val);
+	int val_len = snprintf(buf, bufsize, num_fmt, (uintmax_t)val);
 	if (val_len < 0)
 		goto internal;
 
 	size_t total_len = val_len, line_len = val_len, sep_line_len = 0;
 
-	if (total_len < bufsize)
-		bp += total_len;
-	else
-		bp += bufsize - 1;
-
 #define	STORE(c) do {			\
+		if (total_len < bufsize)\
+			buf[total_len] = (c);\
+		total_len++;		\
 		line_len++;		\
-		if (++total_len < bufsize)\
-			*bp++ = (c);	\
 	} while (0)
 
 #define	BACKUP() do {			\
-		if (sep_bp != NULL) {	\
-			bp = sep_bp;	\
-			sep_bp = NULL;	\
+		if (sep_line_len > 0) {	\
 			total_len -= line_len - sep_line_len;		\
+			sep_line_len = 0;\
 			restart = 1;	\
 			bitfmt = sep_bitfmt;\
 		}			\
 		STORE('>');		\
 		STORE('\0');		\
 		if (total_len < bufsize)\
-			snprintf(bp, bufsize - total_len, num_fmt,	\
-			(uintmax_t)val);\
+			snprintf(buf + total_len, bufsize - total_len,	\
+			num_fmt, (uintmax_t)val);			\
 		total_len += val_len;	\
 		line_len = val_len;	\
-		bp += val_len;		\
 	} while (0)
 
 #define	PUTSEP() do {			\
@@ -137,10 +130,8 @@ snprintb_m(char *buf, size_t bufsize, co
 			BACKUP();	\
 			STORE('<');	\
 		} else {		\
-			/* Remember separator location */		\
 			if (line_max > 0 && sep != '<') {		\
 sep_line_len = line_len;		\
-sep_bp = bp;\
 sep_bitfmt = cur_bitfmt;		\
 			}		\
 			STORE(sep);	\
@@ -170,15 +161,13 @@ snprintb_m(char *buf, size_t bufsize, co
 	} while (0)
 
 #define	FMTSTR(sb, f) do {		\
-		size_t n = total_len < bufsize\
-		? bufsize - total_len : 0;\
+		char *bp = total_len < bufsize ? buf + total_len : NULL; \
+		size_t n = total_len < bufsize ? bufsize - total_len : 0; \
 		int fmt_len = snprintf(bp, n, sb, (uintmax_t)f);	\
 		if (fmt_len < 0)	\
 			goto internal;	\
 		total_len += fmt_len;	\
 		line_len += fmt_len;	\
-		if (total_len < bufsize)\
-			bp += fmt_len;	\
 	} while (0)
 
 	sep = '<';

Index: src/tests/lib/libutil/t_snprintb.c
diff -u src/tests/lib/libutil/t_snprintb.c:1.19 src/tests/lib/libutil/t_snprintb.c:1.20
--- src/tests/lib/libutil/t_snprintb.c:1.19	Fri Feb 16 19:20:38 2024
+++ src/tests/lib/libutil/t_snprintb.c	Fri Feb 16 19:53:40 2024
@@ -1,4 +1,4 @@
-/* $NetBSD: t_snprintb.c,v 1.19 2024/02/16 19:20:38 rillig Exp $ */
+/* $NetBSD: t_snprintb.c,v 1.20 2024/02/16 19:53:40 rillig Exp $ */
 
 /*
  * Copyright (c) 2002, 2004, 2008, 2010, 2024 The NetBSD Foundation, Inc.
@@ -32,7 +32,7 @@
 #include 
 __COPYRIGHT("@(#) Copyright (c) 2008, 2010\
  The NetBSD Foundation, inc. All rights reserved.");
-__RCSID("$NetBSD: t_snprintb.c,v 1.19 2024/02/16 19:20:38 rillig Exp $");
+__RCSID("$NetBSD: t_snprintb.c,v 1.20 2024/02/16 19:53:40 rillig Exp $");
 
 #include 
 #include 
@@ -79,9 +79,6 @@ h_snprintb_loc(const char *file, size_t 
 {
 	char buf[1024];
 
-	// 

CVS commit: src

2024-02-16 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Fri Feb 16 19:53:40 UTC 2024

Modified Files:
src/common/lib/libutil: snprintb.c
src/tests/lib/libutil: t_snprintb.c

Log Message:
snprintb: eliminate two local variables, allow zero-size buffer

Like snprintf, the buffer size may be zero. Unlike snprintf, the buffer
must not be NULL.


To generate a diff of this commit:
cvs rdiff -u -r1.32 -r1.33 src/common/lib/libutil/snprintb.c
cvs rdiff -u -r1.19 -r1.20 src/tests/lib/libutil/t_snprintb.c

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



<    1   2   3   4   5   6   7   8   9   10   >