CVS commit: src

2021-03-18 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Fri Mar 19 01:02:53 UTC 2021

Modified Files:
src/tests/usr.bin/xlint/lint1: d_c99_init.c d_c99_init.exp
src/usr.bin/xlint/lint1: init.c

Log Message:
lint: replace assertion in initialization with proper error message


To generate a diff of this commit:
cvs rdiff -u -r1.8 -r1.9 src/tests/usr.bin/xlint/lint1/d_c99_init.c
cvs rdiff -u -r1.7 -r1.8 src/tests/usr.bin/xlint/lint1/d_c99_init.exp
cvs rdiff -u -r1.103 -r1.104 src/usr.bin/xlint/lint1/init.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/d_c99_init.c
diff -u src/tests/usr.bin/xlint/lint1/d_c99_init.c:1.8 src/tests/usr.bin/xlint/lint1/d_c99_init.c:1.9
--- src/tests/usr.bin/xlint/lint1/d_c99_init.c:1.8	Thu Mar 18 22:51:32 2021
+++ src/tests/usr.bin/xlint/lint1/d_c99_init.c	Fri Mar 19 01:02:52 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: d_c99_init.c,v 1.8 2021/03/18 22:51:32 rillig Exp $	*/
+/*	$NetBSD: d_c99_init.c,v 1.9 2021/03/19 01:02:52 rillig Exp $	*/
 # 3 "d_c99_init.c"
 
 /*
@@ -128,8 +128,7 @@ struct point point_with_mixed_designator
 
 int array_with_designator[] = {
 	111,
-	// FIXME: assertion failure '== STRUCT'
-	// .member = 222,
+	.member = 222,		/* expect: 249 */
 	333,
 };
 

Index: src/tests/usr.bin/xlint/lint1/d_c99_init.exp
diff -u src/tests/usr.bin/xlint/lint1/d_c99_init.exp:1.7 src/tests/usr.bin/xlint/lint1/d_c99_init.exp:1.8
--- src/tests/usr.bin/xlint/lint1/d_c99_init.exp:1.7	Thu Mar 18 21:26:56 2021
+++ src/tests/usr.bin/xlint/lint1/d_c99_init.exp	Fri Mar 19 01:02:52 2021
@@ -2,3 +2,4 @@ d_c99_init.c(22): invalid initializer ty
 d_c99_init.c(23): too many initializers [174]
 d_c99_init.c(49): cannot initialize 'pointer to const void' from 'struct any' [185]
 d_c99_init.c(66): too many array initializers, expected 3 [173]
+d_c99_init.c(131): syntax error 'named member must only be used with struct/union' [249]

Index: src/usr.bin/xlint/lint1/init.c
diff -u src/usr.bin/xlint/lint1/init.c:1.103 src/usr.bin/xlint/lint1/init.c:1.104
--- src/usr.bin/xlint/lint1/init.c:1.103	Fri Mar 19 00:55:02 2021
+++ src/usr.bin/xlint/lint1/init.c	Fri Mar 19 01:02:52 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: init.c,v 1.103 2021/03/19 00:55:02 rillig Exp $	*/
+/*	$NetBSD: init.c,v 1.104 2021/03/19 01:02:52 rillig Exp $	*/
 
 /*
  * Copyright (c) 1994, 1995 Jochen Pohl
@@ -37,7 +37,7 @@
 
 #include 
 #if defined(__RCSID) && !defined(lint)
-__RCSID("$NetBSD: init.c,v 1.103 2021/03/19 00:55:02 rillig Exp $");
+__RCSID("$NetBSD: init.c,v 1.104 2021/03/19 01:02:52 rillig Exp $");
 #endif
 
 #include 
@@ -436,8 +436,14 @@ initstack_pop_item_named_member(void)
 
 	debug_step("initializing named member '%s'", namedmem->n_name);
 
-	lint_assert(istk->i_type->t_tspec == STRUCT ||
-	istk->i_type->t_tspec == UNION);
+	if (istk->i_type->t_tspec != STRUCT &&
+	istk->i_type->t_tspec != UNION) {
+		/* syntax error '%s' */
+		error(249, "named member must only be used with struct/union");
+		initerr = true;
+		return;
+	}
+
 	for (m = istk->i_type->t_str->sou_first_member;
 	 m != NULL; m = m->s_next) {
 



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

2021-03-18 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Fri Mar 19 00:55:02 UTC 2021

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

Log Message:
lint: rename push_member and pop_member

These two functions are supposed to model the designator that is used
for initializing structs and arrays.  The implementation is still buggy
and does not work at all for C99 designators with multiple names, see
d_init_pop_member.c.

For now, just rename the functions to head in the right direction.

No functional change.


To generate a diff of this commit:
cvs rdiff -u -r1.176 -r1.177 src/usr.bin/xlint/lint1/cgram.y
cvs rdiff -u -r1.76 -r1.77 src/usr.bin/xlint/lint1/externs1.h
cvs rdiff -u -r1.102 -r1.103 src/usr.bin/xlint/lint1/init.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/cgram.y
diff -u src/usr.bin/xlint/lint1/cgram.y:1.176 src/usr.bin/xlint/lint1/cgram.y:1.177
--- src/usr.bin/xlint/lint1/cgram.y:1.176	Wed Mar 17 15:45:30 2021
+++ src/usr.bin/xlint/lint1/cgram.y	Fri Mar 19 00:55:02 2021
@@ -1,5 +1,5 @@
 %{
-/* $NetBSD: cgram.y,v 1.176 2021/03/17 15:45:30 rillig Exp $ */
+/* $NetBSD: cgram.y,v 1.177 2021/03/19 00:55:02 rillig Exp $ */
 
 /*
  * Copyright (c) 1996 Christopher G. Demetriou.  All Rights Reserved.
@@ -35,7 +35,7 @@
 
 #include 
 #if defined(__RCSID) && !defined(lint)
-__RCSID("$NetBSD: cgram.y,v 1.176 2021/03/17 15:45:30 rillig Exp $");
+__RCSID("$NetBSD: cgram.y,v 1.177 2021/03/19 00:55:02 rillig Exp $");
 #endif
 
 #include 
@@ -1368,7 +1368,7 @@ designator:			/* C99 6.7.8 "Initializati
 		if (!Sflag)
 			/* struct or union member name in initializer is ... */
 			warning(313);
-		push_member($2);
+		designator_push_name($2);
 	  }
 	;
 
@@ -1382,7 +1382,7 @@ init_by_name:
 	| identifier T_COLON {
 		/* GCC style struct or union member name in initializer */
 		gnuism(315);
-		push_member($1);
+		designator_push_name($1);
 	  }
 	;
 

Index: src/usr.bin/xlint/lint1/externs1.h
diff -u src/usr.bin/xlint/lint1/externs1.h:1.76 src/usr.bin/xlint/lint1/externs1.h:1.77
--- src/usr.bin/xlint/lint1/externs1.h:1.76	Wed Mar 17 15:45:30 2021
+++ src/usr.bin/xlint/lint1/externs1.h	Fri Mar 19 00:55:02 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: externs1.h,v 1.76 2021/03/17 15:45:30 rillig Exp $	*/
+/*	$NetBSD: externs1.h,v 1.77 2021/03/19 00:55:02 rillig Exp $	*/
 
 /*
  * Copyright (c) 1994, 1995 Jochen Pohl
@@ -299,7 +299,7 @@ extern	void	initstack_init(void);
 extern	void	init_rbrace(void);
 extern	void	init_lbrace(void);
 extern	void	init_using_expr(tnode_t *);
-extern	void	push_member(sbuf_t *);
+extern	void	designator_push_name(sbuf_t *);
 extern	void	designator_push_subscript(range_t);
 
 /*

Index: src/usr.bin/xlint/lint1/init.c
diff -u src/usr.bin/xlint/lint1/init.c:1.102 src/usr.bin/xlint/lint1/init.c:1.103
--- src/usr.bin/xlint/lint1/init.c:1.102	Fri Mar 19 00:39:17 2021
+++ src/usr.bin/xlint/lint1/init.c	Fri Mar 19 00:55:02 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: init.c,v 1.102 2021/03/19 00:39:17 rillig Exp $	*/
+/*	$NetBSD: init.c,v 1.103 2021/03/19 00:55:02 rillig Exp $	*/
 
 /*
  * Copyright (c) 1994, 1995 Jochen Pohl
@@ -37,7 +37,7 @@
 
 #include 
 #if defined(__RCSID) && !defined(lint)
-__RCSID("$NetBSD: init.c,v 1.102 2021/03/19 00:39:17 rillig Exp $");
+__RCSID("$NetBSD: init.c,v 1.103 2021/03/19 00:55:02 rillig Exp $");
 #endif
 
 #include 
@@ -338,7 +338,7 @@ debug_initstack(void)
 #endif
 
 void
-push_member(sbuf_t *sb)
+designator_push_name(sbuf_t *sb)
 {
 	namlist_t *nam = xcalloc(1, sizeof (namlist_t));
 	nam->n_name = sb->sb_name;
@@ -378,7 +378,7 @@ designator_push_subscript(range_t range)
 }
 
 static void
-pop_member(void)
+designator_pop_name(void)
 {
 	debug_step("%s: %s %p", __func__, namedmem->n_name, namedmem);
 	if (namedmem->n_next == namedmem) {
@@ -450,7 +450,7 @@ initstack_pop_item_named_member(void)
 			/* XXX: why ++? */
 			istk->i_remaining++;
 			/* XXX: why is i_seen_named_member not set? */
-			pop_member();
+			designator_pop_name();
 			return;
 		}
 	}
@@ -458,7 +458,7 @@ initstack_pop_item_named_member(void)
 	/* undefined struct/union member: %s */
 	error(101, namedmem->n_name);
 
-	pop_member();
+	designator_pop_name();
 	istk->i_seen_named_member = true;
 }
 
@@ -650,7 +650,7 @@ initstack_push_struct_or_union(void)
 		istk->i_subt = m->s_type;
 		istk->i_seen_named_member = true;
 		debug_step("named member '%s'", namedmem->n_name);
-		pop_member();
+		designator_pop_name();
 		cnt = istk->i_type->t_tspec == STRUCT ? 2 : 1;
 	}
 	istk->i_brace = true;



CVS commit: src/tests/lib/libc/sys

2021-03-18 Thread Simon Burge
Module Name:src
Committed By:   simonb
Date:   Fri Mar 19 00:44:09 UTC 2021

Modified Files:
src/tests/lib/libc/sys: t_ptrace_signal_wait.h

Log Message:
Sprinkle a few more \n's and the end of some debug printfs.


To generate a diff of this commit:
cvs rdiff -u -r1.4 -r1.5 src/tests/lib/libc/sys/t_ptrace_signal_wait.h

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

Modified files:

Index: src/tests/lib/libc/sys/t_ptrace_signal_wait.h
diff -u src/tests/lib/libc/sys/t_ptrace_signal_wait.h:1.4 src/tests/lib/libc/sys/t_ptrace_signal_wait.h:1.5
--- src/tests/lib/libc/sys/t_ptrace_signal_wait.h:1.4	Mon Jun 22 12:21:02 2020
+++ src/tests/lib/libc/sys/t_ptrace_signal_wait.h	Fri Mar 19 00:44:09 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: t_ptrace_signal_wait.h,v 1.4 2020/06/22 12:21:02 rin Exp $	*/
+/*	$NetBSD: t_ptrace_signal_wait.h,v 1.5 2021/03/19 00:44:09 simonb Exp $	*/
 
 /*-
  * Copyright (c) 2016, 2017, 2018, 2019, 2020 The NetBSD Foundation, Inc.
@@ -90,7 +90,7 @@ traceme_raise(int sigval)
 		ATF_REQUIRE_EQ(info.psi_siginfo.si_signo, sigval);
 		ATF_REQUIRE_EQ(info.psi_siginfo.si_code, SI_LWP);
 
-		DPRINTF("Assert that PT_GET_PROCESS_STATE returns non-error");
+		DPRINTF("Assert that PT_GET_PROCESS_STATE returns non-error\n");
 		SYSCALL_REQUIRE(
 		ptrace(PT_GET_PROCESS_STATE, child, , slen) != -1);
 		ATF_REQUIRE(memcmp(, _state, slen) == 0);
@@ -401,7 +401,7 @@ traceme_crash(int sig)
 
 	validate_status_stopped(status, sig);
 
-	DPRINTF("Before calling ptrace(2) with PT_GET_SIGINFO for child");
+	DPRINTF("Before calling ptrace(2) with PT_GET_SIGINFO for child\n");
 	SYSCALL_REQUIRE(
 	ptrace(PT_GET_SIGINFO, child, , sizeof(info)) != -1);
 
@@ -567,7 +567,7 @@ traceme_signalmasked_crash(int sig)
 
 	validate_status_stopped(status, sig);
 
-	DPRINTF("Before calling ptrace(2) with PT_GET_SIGINFO for child");
+	DPRINTF("Before calling ptrace(2) with PT_GET_SIGINFO for child\n");
 	SYSCALL_REQUIRE(
 	ptrace(PT_GET_SIGINFO, child, , sizeof(info)) != -1);
 
@@ -750,7 +750,7 @@ traceme_signalignored_crash(int sig)
 
 	validate_status_stopped(status, sig);
 
-	DPRINTF("Before calling ptrace(2) with PT_GET_SIGINFO for child");
+	DPRINTF("Before calling ptrace(2) with PT_GET_SIGINFO for child\n");
 	SYSCALL_REQUIRE(
 	ptrace(PT_GET_SIGINFO, child, , sizeof(info)) != -1);
 



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

2021-03-18 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Fri Mar 19 00:39:17 UTC 2021

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

Log Message:
lint: extend documentation about initialization

No functional change.


To generate a diff of this commit:
cvs rdiff -u -r1.101 -r1.102 src/usr.bin/xlint/lint1/init.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/init.c
diff -u src/usr.bin/xlint/lint1/init.c:1.101 src/usr.bin/xlint/lint1/init.c:1.102
--- src/usr.bin/xlint/lint1/init.c:1.101	Fri Mar 19 00:19:32 2021
+++ src/usr.bin/xlint/lint1/init.c	Fri Mar 19 00:39:17 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: init.c,v 1.101 2021/03/19 00:19:32 rillig Exp $	*/
+/*	$NetBSD: init.c,v 1.102 2021/03/19 00:39:17 rillig Exp $	*/
 
 /*
  * Copyright (c) 1994, 1995 Jochen Pohl
@@ -37,7 +37,7 @@
 
 #include 
 #if defined(__RCSID) && !defined(lint)
-__RCSID("$NetBSD: init.c,v 1.101 2021/03/19 00:19:32 rillig Exp $");
+__RCSID("$NetBSD: init.c,v 1.102 2021/03/19 00:39:17 rillig Exp $");
 #endif
 
 #include 
@@ -104,15 +104,29 @@ typedef	struct initstack_element {
 
 	/*
 	 * The type to be initialized at this level.
+	 *
+	 * On the outermost element, this is always NULL since the outermost
+	 * initializer-expression may be enclosed in an optional pair of
+	 * braces.  This optional pair of braces is handled by the combination
+	 * of i_type and i_subt.
+	 *
+	 * Everywhere else it is nonnull.
 	 */
 	type_t	*i_type;
+
 	/*
-	 * The type that is initialized inside a further level of
-	 * braces.  It is completely independent from i_type->t_subt.
+	 * The type that will be initialized at the next initialization level,
+	 * usually enclosed by another pair of braces.
 	 *
-	 * For example, in 'int var = { init }', initially there is an
-	 * initstack_element with i_subt == int.  When the '{' is processed,
-	 * an element with i_type == int is pushed to the stack.  When the
+	 * For an array, it is the element type, but without 'const'.
+	 *
+	 * For a struct or union type, it is one of the member types, but
+	 * without 'const'.
+	 *
+	 * The outermost stack element has no i_type but nevertheless has
+	 * i_subt.  For example, in 'int var = { 12345 }', initially there is
+	 * an initstack_element with i_subt 'int'.  When the '{' is processed,
+	 * an element with i_type 'int' is pushed to the stack.  When the
 	 * corresponding '}' is processed, the inner element is popped again.
 	 *
 	 * During initialization, only the top 2 elements of the stack are
@@ -143,7 +157,12 @@ typedef	struct initstack_element {
 	sym_t *i_current_object;
 
 	/*
-	 * The number of remaining elements.
+	 * The number of remaining elements to be used by expressions without
+	 * designator.
+	 *
+	 * This says nothing about which members have been initialized or not
+	 * since starting with C99, members may be initialized in arbitrary
+	 * order by using designators.
 	 *
 	 * For an array of unknown size, this is always 0 and thus irrelevant.
 	 *



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

2021-03-18 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Fri Mar 19 00:19:32 UTC 2021

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

Log Message:
lint: split initstack_pop_item into separate functions

No functional change.


To generate a diff of this commit:
cvs rdiff -u -r1.100 -r1.101 src/usr.bin/xlint/lint1/init.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/init.c
diff -u src/usr.bin/xlint/lint1/init.c:1.100 src/usr.bin/xlint/lint1/init.c:1.101
--- src/usr.bin/xlint/lint1/init.c:1.100	Fri Mar 19 00:08:13 2021
+++ src/usr.bin/xlint/lint1/init.c	Fri Mar 19 00:19:32 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: init.c,v 1.100 2021/03/19 00:08:13 rillig Exp $	*/
+/*	$NetBSD: init.c,v 1.101 2021/03/19 00:19:32 rillig Exp $	*/
 
 /*
  * Copyright (c) 1994, 1995 Jochen Pohl
@@ -37,7 +37,7 @@
 
 #include 
 #if defined(__RCSID) && !defined(lint)
-__RCSID("$NetBSD: init.c,v 1.100 2021/03/19 00:08:13 rillig Exp $");
+__RCSID("$NetBSD: init.c,v 1.101 2021/03/19 00:19:32 rillig Exp $");
 #endif
 
 #include 
@@ -410,59 +410,44 @@ initstack_init(void)
 }
 
 static void
-initstack_pop_item(void)
+initstack_pop_item_named_member(void)
 {
-	initstack_element *istk;
-	sym_t	*m;
-
-	debug_enter();
-
-	istk = initstk;
-	debug_step("popping:");
-	debug_initstack_element(istk);
-
-	initstk = istk->i_enclosing;
-	free(istk);
-	istk = initstk;
-	lint_assert(istk != NULL);
-
-	istk->i_remaining--;
-	lint_assert(istk->i_remaining >= 0);
-	debug_step("%d elements remaining", istk->i_remaining);
+	initstack_element *istk = initstk;
+	sym_t *m;
 
-	if (namedmem != NULL) {
-		debug_step("initializing named member '%s'", namedmem->n_name);
+	debug_step("initializing named member '%s'", namedmem->n_name);
 
-		lint_assert(istk->i_type->t_tspec == STRUCT ||
-		istk->i_type->t_tspec == UNION);
-		for (m = istk->i_type->t_str->sou_first_member;
-		 m != NULL; m = m->s_next) {
+	lint_assert(istk->i_type->t_tspec == STRUCT ||
+	istk->i_type->t_tspec == UNION);
+	for (m = istk->i_type->t_str->sou_first_member;
+	 m != NULL; m = m->s_next) {
 
-			if (m->s_bitfield && m->s_name == unnamed)
-continue;
+		if (m->s_bitfield && m->s_name == unnamed)
+			continue;
 
-			if (strcmp(m->s_name, namedmem->n_name) == 0) {
-debug_step("found matching member");
-istk->i_subt = m->s_type;
-/* XXX: why ++? */
-istk->i_remaining++;
-/* XXX: why is i_seen_named_member not set? */
-pop_member();
-debug_initstack();
-debug_leave();
-return;
-			}
+		if (strcmp(m->s_name, namedmem->n_name) == 0) {
+			debug_step("found matching member");
+			istk->i_subt = m->s_type;
+			/* XXX: why ++? */
+			istk->i_remaining++;
+			/* XXX: why is i_seen_named_member not set? */
+			pop_member();
+			return;
 		}
+	}
 
-		/* undefined struct/union member: %s */
-		error(101, namedmem->n_name);
+	/* undefined struct/union member: %s */
+	error(101, namedmem->n_name);
 
-		pop_member();
-		istk->i_seen_named_member = true;
-		debug_initstack();
-		debug_leave();
-		return;
-	}
+	pop_member();
+	istk->i_seen_named_member = true;
+}
+
+static void
+initstack_pop_item_unnamed(void)
+{
+	initstack_element *istk = initstk;
+	sym_t *m;
 
 	/*
 	 * If the removed element was a structure member, we must go
@@ -480,6 +465,33 @@ initstack_pop_item(void)
 		/* XXX: duplicate code for skipping unnamed bit-fields */
 		istk->i_subt = m->s_type;
 	}
+}
+
+static void
+initstack_pop_item(void)
+{
+	initstack_element *istk;
+
+	debug_enter();
+
+	istk = initstk;
+	debug_step("popping:");
+	debug_initstack_element(istk);
+
+	initstk = istk->i_enclosing;
+	free(istk);
+	istk = initstk;
+	lint_assert(istk != NULL);
+
+	istk->i_remaining--;
+	lint_assert(istk->i_remaining >= 0);
+	debug_step("%d elements remaining", istk->i_remaining);
+
+	if (namedmem != NULL)
+		initstack_pop_item_named_member();
+	else
+		initstack_pop_item_unnamed();
+
 	debug_initstack();
 	debug_leave();
 }



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

2021-03-18 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Fri Mar 19 00:08:13 UTC 2021

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

Log Message:
lint: improve debug logging in initstack_push

No functional change outside debug mode.


To generate a diff of this commit:
cvs rdiff -u -r1.99 -r1.100 src/usr.bin/xlint/lint1/init.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/init.c
diff -u src/usr.bin/xlint/lint1/init.c:1.99 src/usr.bin/xlint/lint1/init.c:1.100
--- src/usr.bin/xlint/lint1/init.c:1.99	Thu Mar 18 23:45:20 2021
+++ src/usr.bin/xlint/lint1/init.c	Fri Mar 19 00:08:13 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: init.c,v 1.99 2021/03/18 23:45:20 rillig Exp $	*/
+/*	$NetBSD: init.c,v 1.100 2021/03/19 00:08:13 rillig Exp $	*/
 
 /*
  * Copyright (c) 1994, 1995 Jochen Pohl
@@ -37,7 +37,7 @@
 
 #include 
 #if defined(__RCSID) && !defined(lint)
-__RCSID("$NetBSD: init.c,v 1.99 2021/03/18 23:45:20 rillig Exp $");
+__RCSID("$NetBSD: init.c,v 1.100 2021/03/19 00:08:13 rillig Exp $");
 #endif
 
 #include 
@@ -584,17 +584,19 @@ initstack_push_struct_or_union(void)
 		initerr = true;
 		return false;
 	}
+
 	cnt = 0;
 	debug_named_member();
 	debug_step("lookup for '%s'%s",
 	type_name(istk->i_type),
 	istk->i_seen_named_member ? ", seen named member" : "");
+
 	for (m = istk->i_type->t_str->sou_first_member;
 	 m != NULL; m = m->s_next) {
 		if (m->s_bitfield && m->s_name == unnamed)
 			continue;
 		if (namedmem != NULL) {
-			debug_step("named lhs.member=%s, rhs.member=%s",
+			debug_step("have member '%s', want member '%s'",
 			m->s_name, namedmem->n_name);
 			if (strcmp(m->s_name, namedmem->n_name) == 0) {
 cnt++;
@@ -607,6 +609,7 @@ initstack_push_struct_or_union(void)
 			istk->i_subt = m->s_type;
 		}
 	}
+
 	if (namedmem != NULL) {
 		if (m == NULL) {
 			debug_step("pop struct");
@@ -658,7 +661,7 @@ again:
 	switch (istk->i_type->t_tspec) {
 	case ARRAY:
 		if (namedmem != NULL) {
-			debug_step("ARRAY %s brace=%d",
+			debug_step("pop array namedmem=%s brace=%d",
 			namedmem->n_name, istk->i_brace);
 			goto pop;
 		}
@@ -677,14 +680,14 @@ again:
 		break;
 	default:
 		if (namedmem != NULL) {
-			debug_step("pop");
+			debug_step("pop scalar");
 	pop:
 			inxt = initstk->i_enclosing;
 			free(istk);
 			initstk = inxt;
 			goto again;
 		}
-		/* XXX: Why is this set to 1 unconditionally? */
+		/* The initialization stack now expects a single scalar. */
 		istk->i_remaining = 1;
 		break;
 	}



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

2021-03-18 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Thu Mar 18 23:45:20 UTC 2021

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

Log Message:
lint: split initstack_push into smaller functions

No functional change.


To generate a diff of this commit:
cvs rdiff -u -r1.98 -r1.99 src/usr.bin/xlint/lint1/init.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/init.c
diff -u src/usr.bin/xlint/lint1/init.c:1.98 src/usr.bin/xlint/lint1/init.c:1.99
--- src/usr.bin/xlint/lint1/init.c:1.98	Thu Mar 18 23:37:31 2021
+++ src/usr.bin/xlint/lint1/init.c	Thu Mar 18 23:45:20 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: init.c,v 1.98 2021/03/18 23:37:31 rillig Exp $	*/
+/*	$NetBSD: init.c,v 1.99 2021/03/18 23:45:20 rillig Exp $	*/
 
 /*
  * Copyright (c) 1994, 1995 Jochen Pohl
@@ -37,7 +37,7 @@
 
 #include 
 #if defined(__RCSID) && !defined(lint)
-__RCSID("$NetBSD: init.c,v 1.98 2021/03/18 23:37:31 rillig Exp $");
+__RCSID("$NetBSD: init.c,v 1.99 2021/03/18 23:45:20 rillig Exp $");
 #endif
 
 #include 
@@ -545,11 +545,98 @@ extend_if_array_of_unknown_size(void)
 }
 
 static void
+initstack_push_array(void)
+{
+	initstack_element *const istk = initstk;
+
+	if (istk->i_enclosing->i_seen_named_member) {
+		istk->i_brace = true;
+		debug_step("ARRAY brace=%d, namedmem=%d",
+		istk->i_brace, istk->i_enclosing->i_seen_named_member);
+	}
+
+	if (is_incomplete(istk->i_type) &&
+	istk->i_enclosing->i_enclosing != NULL) {
+		/* initialization of an incomplete type */
+		error(175);
+		initerr = true;
+		return;
+	}
+
+	istk->i_subt = istk->i_type->t_subt;
+	istk->i_array_of_unknown_size = is_incomplete(istk->i_type);
+	istk->i_remaining = istk->i_type->t_dim;
+	debug_named_member();
+	debug_step("type '%s' remaining %d",
+	type_name(istk->i_type), istk->i_remaining);
+}
+
+static bool
+initstack_push_struct_or_union(void)
+{
+	initstack_element *const istk = initstk;
+	int cnt;
+	sym_t *m;
+
+	if (is_incomplete(istk->i_type)) {
+		/* initialization of an incomplete type */
+		error(175);
+		initerr = true;
+		return false;
+	}
+	cnt = 0;
+	debug_named_member();
+	debug_step("lookup for '%s'%s",
+	type_name(istk->i_type),
+	istk->i_seen_named_member ? ", seen named member" : "");
+	for (m = istk->i_type->t_str->sou_first_member;
+	 m != NULL; m = m->s_next) {
+		if (m->s_bitfield && m->s_name == unnamed)
+			continue;
+		if (namedmem != NULL) {
+			debug_step("named lhs.member=%s, rhs.member=%s",
+			m->s_name, namedmem->n_name);
+			if (strcmp(m->s_name, namedmem->n_name) == 0) {
+cnt++;
+break;
+			} else
+continue;
+		}
+		if (++cnt == 1) {
+			istk->i_current_object = m;
+			istk->i_subt = m->s_type;
+		}
+	}
+	if (namedmem != NULL) {
+		if (m == NULL) {
+			debug_step("pop struct");
+			return true;
+		}
+		istk->i_current_object = m;
+		istk->i_subt = m->s_type;
+		istk->i_seen_named_member = true;
+		debug_step("named member '%s'", namedmem->n_name);
+		pop_member();
+		cnt = istk->i_type->t_tspec == STRUCT ? 2 : 1;
+	}
+	istk->i_brace = true;
+	debug_step("unnamed element with type '%s'%s",
+	type_name(istk->i_type != NULL ? istk->i_type : istk->i_subt),
+	istk->i_brace ? ", needs closing brace" : "");
+	if (cnt == 0) {
+		/* cannot init. struct/union with no named member */
+		error(179);
+		initerr = true;
+		return false;
+	}
+	istk->i_remaining = istk->i_type->t_tspec == STRUCT ? cnt : 1;
+	return false;
+}
+
+static void
 initstack_push(void)
 {
 	initstack_element *istk, *inxt;
-	int	cnt;
-	sym_t	*m;
 
 	debug_enter();
 
@@ -576,86 +663,17 @@ again:
 			goto pop;
 		}
 
-		if (istk->i_enclosing->i_seen_named_member) {
-			istk->i_brace = true;
-			debug_step("ARRAY brace=%d, namedmem=%d",
-			istk->i_brace,
-			istk->i_enclosing->i_seen_named_member);
-		}
-
-		if (is_incomplete(istk->i_type) &&
-		istk->i_enclosing->i_enclosing != NULL) {
-			/* initialization of an incomplete type */
-			error(175);
-			initerr = true;
-			break;
-		}
-		istk->i_subt = istk->i_type->t_subt;
-		istk->i_array_of_unknown_size = is_incomplete(istk->i_type);
-		istk->i_remaining = istk->i_type->t_dim;
-		debug_named_member();
-		debug_step("type '%s' remaining %d",
-		type_name(istk->i_type), istk->i_remaining);
+		initstack_push_array();
 		break;
+
 	case UNION:
 		if (tflag)
 			/* initialization of union is illegal in trad. C */
 			warning(238);
 		/* FALLTHROUGH */
 	case STRUCT:
-		if (is_incomplete(istk->i_type)) {
-			/* initialization of an incomplete type */
-			error(175);
-			initerr = true;
-			break;
-		}
-		cnt = 0;
-		debug_named_member();
-		debug_step("lookup for '%s'%s",
-		type_name(istk->i_type),
-		istk->i_seen_named_member ? ", seen named member" : "");
-		for (m = istk->i_type->t_str->sou_first_member;
-		 m != NULL; m = m->s_next) {
-			if (m->s_bitfield && m->s_name == unnamed)
-continue;
-			if (namedmem != NULL) {
-	

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

2021-03-18 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Thu Mar 18 23:37:31 UTC 2021

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

Log Message:
lint: clean up control flow in initstack_push

No functional change.


To generate a diff of this commit:
cvs rdiff -u -r1.97 -r1.98 src/usr.bin/xlint/lint1/init.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/init.c
diff -u src/usr.bin/xlint/lint1/init.c:1.97 src/usr.bin/xlint/lint1/init.c:1.98
--- src/usr.bin/xlint/lint1/init.c:1.97	Thu Mar 18 23:23:40 2021
+++ src/usr.bin/xlint/lint1/init.c	Thu Mar 18 23:37:31 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: init.c,v 1.97 2021/03/18 23:23:40 rillig Exp $	*/
+/*	$NetBSD: init.c,v 1.98 2021/03/18 23:37:31 rillig Exp $	*/
 
 /*
  * Copyright (c) 1994, 1995 Jochen Pohl
@@ -37,7 +37,7 @@
 
 #include 
 #if defined(__RCSID) && !defined(lint)
-__RCSID("$NetBSD: init.c,v 1.97 2021/03/18 23:23:40 rillig Exp $");
+__RCSID("$NetBSD: init.c,v 1.98 2021/03/18 23:37:31 rillig Exp $");
 #endif
 
 #include 
@@ -574,7 +574,9 @@ again:
 			debug_step("ARRAY %s brace=%d",
 			namedmem->n_name, istk->i_brace);
 			goto pop;
-		} else if (istk->i_enclosing->i_seen_named_member) {
+		}
+
+		if (istk->i_enclosing->i_seen_named_member) {
 			istk->i_brace = true;
 			debug_step("ARRAY brace=%d, namedmem=%d",
 			istk->i_brace,
@@ -586,9 +588,7 @@ again:
 			/* initialization of an incomplete type */
 			error(175);
 			initerr = true;
-			debug_initstack();
-			debug_leave();
-			return;
+			break;
 		}
 		istk->i_subt = istk->i_type->t_subt;
 		istk->i_array_of_unknown_size = is_incomplete(istk->i_type);
@@ -607,9 +607,7 @@ again:
 			/* initialization of an incomplete type */
 			error(175);
 			initerr = true;
-			debug_initstack();
-			debug_leave();
-			return;
+			break;
 		}
 		cnt = 0;
 		debug_named_member();
@@ -655,9 +653,7 @@ again:
 			/* cannot init. struct/union with no named member */
 			error(179);
 			initerr = true;
-			debug_initstack();
-			debug_leave();
-			return;
+			break;
 		}
 		istk->i_remaining = istk->i_type->t_tspec == STRUCT ? cnt : 1;
 		break;



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

2021-03-18 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Thu Mar 18 23:23:40 UTC 2021

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

Log Message:
lint: extract extend_if_array_of_unknown_size from initstack_push

No functional change.


To generate a diff of this commit:
cvs rdiff -u -r1.96 -r1.97 src/usr.bin/xlint/lint1/init.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/init.c
diff -u src/usr.bin/xlint/lint1/init.c:1.96 src/usr.bin/xlint/lint1/init.c:1.97
--- src/usr.bin/xlint/lint1/init.c:1.96	Thu Mar 18 22:51:32 2021
+++ src/usr.bin/xlint/lint1/init.c	Thu Mar 18 23:23:40 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: init.c,v 1.96 2021/03/18 22:51:32 rillig Exp $	*/
+/*	$NetBSD: init.c,v 1.97 2021/03/18 23:23:40 rillig Exp $	*/
 
 /*
  * Copyright (c) 1994, 1995 Jochen Pohl
@@ -37,7 +37,7 @@
 
 #include 
 #if defined(__RCSID) && !defined(lint)
-__RCSID("$NetBSD: init.c,v 1.96 2021/03/18 22:51:32 rillig Exp $");
+__RCSID("$NetBSD: init.c,v 1.97 2021/03/18 23:23:40 rillig Exp $");
 #endif
 
 #include 
@@ -519,6 +519,31 @@ initstack_pop_nobrace(void)
 	debug_leave();
 }
 
+/* Extend an array of unknown size by one element */
+static void
+extend_if_array_of_unknown_size(void)
+{
+	initstack_element *istk = initstk;
+
+	if (istk->i_remaining != 0)
+		return;
+
+	/*
+	 * The only place where an incomplete array may appear is at the
+	 * outermost aggregate level of the object to be initialized.
+	 */
+	lint_assert(istk->i_enclosing->i_enclosing == NULL);
+	lint_assert(istk->i_type->t_tspec == ARRAY);
+
+	debug_step("extending array of unknown size '%s'",
+	type_name(istk->i_type));
+	istk->i_remaining = 1;
+	istk->i_type->t_dim++;
+	setcomplete(istk->i_type, true);
+
+	debug_step("extended type is '%s'", type_name(istk->i_type));
+}
+
 static void
 initstack_push(void)
 {
@@ -528,26 +553,9 @@ initstack_push(void)
 
 	debug_enter();
 
-	istk = initstk;
-
-	/* Extend an incomplete array type by one element */
-	if (istk->i_remaining == 0) {
-		/*
-		 * Inside of other aggregate types must not be an incomplete
-		 * type.
-		 */
-		lint_assert(istk->i_enclosing->i_enclosing == NULL);
-		lint_assert(istk->i_type->t_tspec == ARRAY);
-
-		debug_step("extending array of unknown size '%s'",
-		type_name(istk->i_type));
-		istk->i_remaining = 1;
-		istk->i_type->t_dim++;
-		setcomplete(istk->i_type, true);
-
-		debug_step("extended type is '%s'", type_name(istk->i_type));
-	}
+	extend_if_array_of_unknown_size();
 
+	istk = initstk;
 	lint_assert(istk->i_remaining > 0);
 	lint_assert(istk->i_type == NULL || !is_scalar(istk->i_type->t_tspec));
 



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

2021-03-18 Thread Simon Burge
Module Name:src
Committed By:   simonb
Date:   Thu Mar 18 23:18:36 UTC 2021

Modified Files:
src/sys/arch/mips/include: ptrace.h

Log Message:
Add PTRACE_ILLEGAL_ASM using the MIPS32r6/MIPS64r6 backwards and
forwards compatible "sigrie" instruction to generate a Reserved
Instruction trap.


To generate a diff of this commit:
cvs rdiff -u -r1.18 -r1.19 src/sys/arch/mips/include/ptrace.h

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

Modified files:

Index: src/sys/arch/mips/include/ptrace.h
diff -u src/sys/arch/mips/include/ptrace.h:1.18 src/sys/arch/mips/include/ptrace.h:1.19
--- src/sys/arch/mips/include/ptrace.h:1.18	Sun Jul 26 08:08:41 2020
+++ src/sys/arch/mips/include/ptrace.h	Thu Mar 18 23:18:36 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: ptrace.h,v 1.18 2020/07/26 08:08:41 simonb Exp $	*/
+/*	$NetBSD: ptrace.h,v 1.19 2021/03/18 23:18:36 simonb Exp $	*/
 
 /*
  * Copyright (c) 1992, 1993
@@ -67,6 +67,21 @@
 #define	PTRACE_REG_SP(r)	(r)->r_regs[29]
 #define	PTRACE_REG_INTRV(r)	(r)->r_regs[2]
 
+/*
+ * The sigrie is defined in the MIPS32r6 and MIPS64r6 specs to
+ * generate a Reserved Instruction trap but uses a previously
+ * reserved instruction encoding and is thus both backwards and
+ * forwards compatible.
+ */
+#define	PTRACE_ILLEGAL_ASM	do {	\
+		asm volatile(		\
+			".set	push;		"			\
+			".set	mips32r6;	"			\
+			"sigrie	0;		"			\
+			".set	pop;		"			\
+		);			\
+	} while (0);
+
 #define	PTRACE_BREAKPOINT	((const uint8_t[]) { 0x00, 0x00, 0x00, 0x0d })
 #define	PTRACE_BREAKPOINT_ASM	__asm __volatile("break")
 #define	PTRACE_BREAKPOINT_SIZE	4



CVS commit: src

2021-03-18 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Thu Mar 18 22:51:32 UTC 2021

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

Log Message:
lint: replace undefined behavior during initialization with assertion

This only affects code that is already rejected by the compiler.


To generate a diff of this commit:
cvs rdiff -u -r1.7 -r1.8 src/tests/usr.bin/xlint/lint1/d_c99_init.c
cvs rdiff -u -r1.95 -r1.96 src/usr.bin/xlint/lint1/init.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/d_c99_init.c
diff -u src/tests/usr.bin/xlint/lint1/d_c99_init.c:1.7 src/tests/usr.bin/xlint/lint1/d_c99_init.c:1.8
--- src/tests/usr.bin/xlint/lint1/d_c99_init.c:1.7	Thu Mar 18 20:20:55 2021
+++ src/tests/usr.bin/xlint/lint1/d_c99_init.c	Thu Mar 18 22:51:32 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: d_c99_init.c,v 1.7 2021/03/18 20:20:55 rillig Exp $	*/
+/*	$NetBSD: d_c99_init.c,v 1.8 2021/03/18 22:51:32 rillig Exp $	*/
 # 3 "d_c99_init.c"
 
 /*
@@ -126,4 +126,11 @@ struct point point_with_mixed_designator
 	.x = 3,
 };
 
+int array_with_designator[] = {
+	111,
+	// FIXME: assertion failure '== STRUCT'
+	// .member = 222,
+	333,
+};
+
 // See d_struct_init_nested.c for a more complicated example.

Index: src/usr.bin/xlint/lint1/init.c
diff -u src/usr.bin/xlint/lint1/init.c:1.95 src/usr.bin/xlint/lint1/init.c:1.96
--- src/usr.bin/xlint/lint1/init.c:1.95	Thu Mar 18 22:08:05 2021
+++ src/usr.bin/xlint/lint1/init.c	Thu Mar 18 22:51:32 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: init.c,v 1.95 2021/03/18 22:08:05 rillig Exp $	*/
+/*	$NetBSD: init.c,v 1.96 2021/03/18 22:51:32 rillig Exp $	*/
 
 /*
  * Copyright (c) 1994, 1995 Jochen Pohl
@@ -37,7 +37,7 @@
 
 #include 
 #if defined(__RCSID) && !defined(lint)
-__RCSID("$NetBSD: init.c,v 1.95 2021/03/18 22:08:05 rillig Exp $");
+__RCSID("$NetBSD: init.c,v 1.96 2021/03/18 22:51:32 rillig Exp $");
 #endif
 
 #include 
@@ -428,14 +428,13 @@ initstack_pop_item(void)
 
 	istk->i_remaining--;
 	lint_assert(istk->i_remaining >= 0);
-
-	debug_step("new stack with updated remaining:");
-	debug_initstack_element(istk);
+	debug_step("%d elements remaining", istk->i_remaining);
 
 	if (namedmem != NULL) {
 		debug_step("initializing named member '%s'", namedmem->n_name);
 
-		/* XXX: undefined behavior if this is reached with an array? */
+		lint_assert(istk->i_type->t_tspec == STRUCT ||
+		istk->i_type->t_tspec == UNION);
 		for (m = istk->i_type->t_str->sou_first_member;
 		 m != NULL; m = m->s_next) {
 



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

2021-03-18 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Thu Mar 18 22:08:05 UTC 2021

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

Log Message:
lint: improve debug logging during initialization

No functional change outside debug mode.


To generate a diff of this commit:
cvs rdiff -u -r1.94 -r1.95 src/usr.bin/xlint/lint1/init.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/init.c
diff -u src/usr.bin/xlint/lint1/init.c:1.94 src/usr.bin/xlint/lint1/init.c:1.95
--- src/usr.bin/xlint/lint1/init.c:1.94	Thu Mar 18 20:55:58 2021
+++ src/usr.bin/xlint/lint1/init.c	Thu Mar 18 22:08:05 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: init.c,v 1.94 2021/03/18 20:55:58 rillig Exp $	*/
+/*	$NetBSD: init.c,v 1.95 2021/03/18 22:08:05 rillig Exp $	*/
 
 /*
  * Copyright (c) 1994, 1995 Jochen Pohl
@@ -37,7 +37,7 @@
 
 #include 
 #if defined(__RCSID) && !defined(lint)
-__RCSID("$NetBSD: init.c,v 1.94 2021/03/18 20:55:58 rillig Exp $");
+__RCSID("$NetBSD: init.c,v 1.95 2021/03/18 22:08:05 rillig Exp $");
 #endif
 
 #include 
@@ -635,15 +635,15 @@ again:
 			istk->i_current_object = m;
 			istk->i_subt = m->s_type;
 			istk->i_seen_named_member = true;
-			debug_step("named name=%s", namedmem->n_name);
+			debug_step("named member '%s'", namedmem->n_name);
 			pop_member();
 			cnt = istk->i_type->t_tspec == STRUCT ? 2 : 1;
 		}
 		istk->i_brace = true;
-		debug_step("unnamed type=%s, brace=%d",
+		debug_step("unnamed element with type '%s'%s",
 		type_name(
 			istk->i_type != NULL ? istk->i_type : istk->i_subt),
-		istk->i_brace);
+		istk->i_brace ? ", needs closing brace" : "");
 		if (cnt == 0) {
 			/* cannot init. struct/union with no named member */
 			error(179);
@@ -849,7 +849,8 @@ init_using_expr(tnode_t *tn)
 	debug_enter();
 	debug_initstack();
 	debug_named_member();
-	debug_node(tn, debug_ind);
+	debug_step("expr:");
+	debug_node(tn, debug_ind + 1);
 
 	if (initerr || tn == NULL) {
 		debug_leave();



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

2021-03-18 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Thu Mar 18 22:05:33 UTC 2021

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

Log Message:
lint: make the debug log for nodes more readable

The operator NAME has the name 'name', therefore no special case is
needed.

Having the words 'with type' in the message makes the message easier to
find from the debug log.  Given that the operator name is used unquoted,
the log message 'name: int value=111' was nearly impossible to find in
the code.

Replace the '()' with an actual word, to avoid any confusion about
whether the type name might be a function type without prototype.

Reduce the amount of '=' signs, instead use commas to separate the
properties of the node.

No functional change outside debug mode.


To generate a diff of this commit:
cvs rdiff -u -r1.234 -r1.235 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.234 src/usr.bin/xlint/lint1/tree.c:1.235
--- src/usr.bin/xlint/lint1/tree.c:1.234	Thu Mar 18 21:26:56 2021
+++ src/usr.bin/xlint/lint1/tree.c	Thu Mar 18 22:05:33 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: tree.c,v 1.234 2021/03/18 21:26:56 rillig Exp $	*/
+/*	$NetBSD: tree.c,v 1.235 2021/03/18 22:05:33 rillig Exp $	*/
 
 /*
  * Copyright (c) 1994, 1995 Jochen Pohl
@@ -37,7 +37,7 @@
 
 #include 
 #if defined(__RCSID) && !defined(lint)
-__RCSID("$NetBSD: tree.c,v 1.234 2021/03/18 21:26:56 rillig Exp $");
+__RCSID("$NetBSD: tree.c,v 1.235 2021/03/18 22:05:33 rillig Exp $");
 #endif
 
 #include 
@@ -109,25 +109,24 @@ debug_node(const tnode_t *tn, int indent
 	}
 
 	op = tn->tn_op;
-	printf("%*s%s: %s%s%s",
+	printf("%*s%s with type '%s'%s%s",
 	2 * indent, "",
-	op == CVT && !tn->tn_cast ? "convert" :
-		op == NAME ? "name" : getopname(op),
-	type_name(tn->tn_type), tn->tn_lvalue ? " lvalue" : "",
-	tn->tn_parenthesized ? " ()" : "");
+	op == CVT && !tn->tn_cast ? "convert" : getopname(op),
+	type_name(tn->tn_type), tn->tn_lvalue ? ", lvalue" : "",
+	tn->tn_parenthesized ? ", parenthesized" : "");
 
 	if (op == NAME)
 		printf(" %s\n", tn->tn_sym->s_name);
 	else if (op == CON && is_floating(tn->tn_type->t_tspec))
-		printf(" value=%Lg", tn->tn_val->v_ldbl);
+		printf(", value %Lg", tn->tn_val->v_ldbl);
 	else if (op == CON && is_uinteger(tn->tn_type->t_tspec))
-		printf(" value=%llu\n", (unsigned long long)tn->tn_val->v_quad);
+		printf(", value %llu\n", (unsigned long long)tn->tn_val->v_quad);
 	else if (op == CON && is_integer(tn->tn_type->t_tspec))
-		printf(" value=%lld\n", (long long)tn->tn_val->v_quad);
+		printf(", value %lld\n", (long long)tn->tn_val->v_quad);
 	else if (op == CON)
-		printf(" value=?\n");
+		printf(", unknown value\n");
 	else if (op == STRING)
-		printf(" length=%zu\n", tn->tn_string->st_len);
+		printf(", length %zu\n", tn->tn_string->st_len);
 	else {
 		printf("\n");
 



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

2021-03-18 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Thu Mar 18 21:56:35 UTC 2021

Modified Files:
src/usr.bin/xlint/lint1: ops.def

Log Message:
lint: rename operator 'const' to 'constant'

The previous name could be too easily confused with the type qualifier
'const'.  The operator name is mainly used in the debug log, only
occasionally in the output.  Since 'constant' is not a "real" operator,
it probably doesn't occur in messages at all.


To generate a diff of this commit:
cvs rdiff -u -r1.16 -r1.17 src/usr.bin/xlint/lint1/ops.def

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/ops.def
diff -u src/usr.bin/xlint/lint1/ops.def:1.16 src/usr.bin/xlint/lint1/ops.def:1.17
--- src/usr.bin/xlint/lint1/ops.def:1.16	Sat Feb 20 18:02:58 2021
+++ src/usr.bin/xlint/lint1/ops.def	Thu Mar 18 21:56:34 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: ops.def,v 1.16 2021/02/20 18:02:58 rillig Exp $ */
+/*	$NetBSD: ops.def,v 1.17 2021/03/18 21:56:34 rillig Exp $ */
 
 begin_ops()
 
@@ -63,7 +63,7 @@ op(	ORASS,	"|=",		1, ,1, ,1, , , , , , ,
 
 /*	name	repr		b l b o i c a s f v t b s l r p c e e =	act */
 op(	NAME,	"name",		 , , , , , , , , , , , , , , , , , , , ,1)
-op(	CON,	"const",	 , , , , , , , , , , , , , , , , , , , ,1)
+op(	CON,	"constant",	 , , , , , , , , , , , , , , , , , , , ,1)
 op(	STRING,	"string",	 , , , , , , , , , , , , , , , , , , , ,1)
 op(	FSEL,	"fsel",		 , , , , , , , , , , , , , , , , , , , ,1)
 op(	CALL,	"call",		1, , , , , , , , , , , ,1, , , , , , , ,1)



CVS commit: src

2021-03-18 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Thu Mar 18 21:26:56 UTC 2021

Modified Files:
src/tests/usr.bin/xlint/lint1: d_c99_init.exp d_struct_init_nested.exp
msg_185.c msg_185.exp
src/usr.bin/xlint/lint1: err.c tree.c

Log Message:
lint: reword message about type mismatch in initialization

Using parentheses for quotes is unusual, furthermore the previous
message didn't follow proper grammar rules, sacrificing clarity for
brevity.


To generate a diff of this commit:
cvs rdiff -u -r1.6 -r1.7 src/tests/usr.bin/xlint/lint1/d_c99_init.exp
cvs rdiff -u -r1.5 -r1.6 \
src/tests/usr.bin/xlint/lint1/d_struct_init_nested.exp
cvs rdiff -u -r1.4 -r1.5 src/tests/usr.bin/xlint/lint1/msg_185.c
cvs rdiff -u -r1.2 -r1.3 src/tests/usr.bin/xlint/lint1/msg_185.exp
cvs rdiff -u -r1.87 -r1.88 src/usr.bin/xlint/lint1/err.c
cvs rdiff -u -r1.233 -r1.234 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/d_c99_init.exp
diff -u src/tests/usr.bin/xlint/lint1/d_c99_init.exp:1.6 src/tests/usr.bin/xlint/lint1/d_c99_init.exp:1.7
--- src/tests/usr.bin/xlint/lint1/d_c99_init.exp:1.6	Thu Mar 18 20:20:55 2021
+++ src/tests/usr.bin/xlint/lint1/d_c99_init.exp	Thu Mar 18 21:26:56 2021
@@ -1,4 +1,4 @@
 d_c99_init.c(22): invalid initializer type int [176]
 d_c99_init.c(23): too many initializers [174]
-d_c99_init.c(49): initialization type mismatch (pointer to const void) and (struct any) [185]
+d_c99_init.c(49): cannot initialize 'pointer to const void' from 'struct any' [185]
 d_c99_init.c(66): too many array initializers, expected 3 [173]

Index: src/tests/usr.bin/xlint/lint1/d_struct_init_nested.exp
diff -u src/tests/usr.bin/xlint/lint1/d_struct_init_nested.exp:1.5 src/tests/usr.bin/xlint/lint1/d_struct_init_nested.exp:1.6
--- src/tests/usr.bin/xlint/lint1/d_struct_init_nested.exp:1.5	Mon Feb 22 15:09:50 2021
+++ src/tests/usr.bin/xlint/lint1/d_struct_init_nested.exp	Thu Mar 18 21:26:56 2021
@@ -1,4 +1,4 @@
-d_struct_init_nested.c(35): initialization type mismatch (enum I1) and (struct Inner1) [185]
+d_struct_init_nested.c(35): cannot initialize 'enum I1' from 'struct Inner1' [185]
 d_struct_init_nested.c(37): too many struct/union initializers [172]
-d_struct_init_nested.c(62): initialization type mismatch (enum I1) and (struct Inner2) [185]
+d_struct_init_nested.c(62): cannot initialize 'enum I1' from 'struct Inner2' [185]
 d_struct_init_nested.c(64): warning: enum type mismatch between 'enum I2' and 'enum O3' in initialization [210]

Index: src/tests/usr.bin/xlint/lint1/msg_185.c
diff -u src/tests/usr.bin/xlint/lint1/msg_185.c:1.4 src/tests/usr.bin/xlint/lint1/msg_185.c:1.5
--- src/tests/usr.bin/xlint/lint1/msg_185.c:1.4	Thu Mar 18 21:20:21 2021
+++ src/tests/usr.bin/xlint/lint1/msg_185.c	Thu Mar 18 21:26:56 2021
@@ -1,7 +1,7 @@
-/*	$NetBSD: msg_185.c,v 1.4 2021/03/18 21:20:21 rillig Exp $	*/
+/*	$NetBSD: msg_185.c,v 1.5 2021/03/18 21:26:56 rillig Exp $	*/
 # 3 "msg_185.c"
 
-// Test for message: initialization type mismatch (%s) and (%s) [185]
+// Test for message: cannot initialize '%s' from '%s' [185]
 
 typedef struct any {
 	const void *value;
@@ -15,5 +15,3 @@ initialization_with_redundant_braces(any
 	any local = { 3.0 };	/* expect: 185 */
 	use();
 }
-
-// TODO: message 185 needs to be reworded to "cannot initialize '%s' from '%s'".

Index: src/tests/usr.bin/xlint/lint1/msg_185.exp
diff -u src/tests/usr.bin/xlint/lint1/msg_185.exp:1.2 src/tests/usr.bin/xlint/lint1/msg_185.exp:1.3
--- src/tests/usr.bin/xlint/lint1/msg_185.exp:1.2	Thu Mar 18 21:20:21 2021
+++ src/tests/usr.bin/xlint/lint1/msg_185.exp	Thu Mar 18 21:26:56 2021
@@ -1 +1 @@
-msg_185.c(15): initialization type mismatch (pointer to const void) and (double) [185]
+msg_185.c(15): cannot initialize 'pointer to const void' from 'double' [185]

Index: src/usr.bin/xlint/lint1/err.c
diff -u src/usr.bin/xlint/lint1/err.c:1.87 src/usr.bin/xlint/lint1/err.c:1.88
--- src/usr.bin/xlint/lint1/err.c:1.87	Sun Mar  7 19:42:54 2021
+++ src/usr.bin/xlint/lint1/err.c	Thu Mar 18 21:26:56 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: err.c,v 1.87 2021/03/07 19:42:54 rillig Exp $	*/
+/*	$NetBSD: err.c,v 1.88 2021/03/18 21:26:56 rillig Exp $	*/
 
 /*
  * Copyright (c) 1994, 1995 Jochen Pohl
@@ -37,7 +37,7 @@
 
 #include 
 #if defined(__RCSID) && !defined(lint)
-__RCSID("$NetBSD: err.c,v 1.87 2021/03/07 19:42:54 rillig Exp $");
+__RCSID("$NetBSD: err.c,v 1.88 2021/03/18 21:26:56 rillig Exp $");
 #endif
 
 #include 
@@ -244,7 +244,7 @@ const	char *msgs[] = {
 	"incompatible pointer types (%s != %s)",		  /* 182 */
 	"illegal combination of %s (%s) and %s (%s)",		  /* 183 */
 	"illegal pointer combination",  /* 184 */
-	"initialization type mismatch (%s) and (%s)",		  /* 185 */
+	"cannot initialize '%s' from '%s'",			  /* 185 */
 	"bit-field initialization is illegal in traditional C",	  

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

2021-03-18 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Thu Mar 18 21:20:21 UTC 2021

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

Log Message:
tests/lint: add test for type mismatch in initialization

Copied and adapted from d_c99_init.c.


To generate a diff of this commit:
cvs rdiff -u -r1.3 -r1.4 src/tests/usr.bin/xlint/lint1/msg_185.c
cvs rdiff -u -r1.1 -r1.2 src/tests/usr.bin/xlint/lint1/msg_185.exp

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_185.c
diff -u src/tests/usr.bin/xlint/lint1/msg_185.c:1.3 src/tests/usr.bin/xlint/lint1/msg_185.c:1.4
--- src/tests/usr.bin/xlint/lint1/msg_185.c:1.3	Mon Feb 22 15:09:50 2021
+++ src/tests/usr.bin/xlint/lint1/msg_185.c	Thu Mar 18 21:20:21 2021
@@ -1,7 +1,19 @@
-/*	$NetBSD: msg_185.c,v 1.3 2021/02/22 15:09:50 rillig Exp $	*/
+/*	$NetBSD: msg_185.c,v 1.4 2021/03/18 21:20:21 rillig Exp $	*/
 # 3 "msg_185.c"
 
 // Test for message: initialization type mismatch (%s) and (%s) [185]
 
-TODO: "Add example code that triggers the above message." /* expect: 249 */
-TODO: "Add example code that almost triggers the above message."
+typedef struct any {
+	const void *value;
+} any;
+
+void use(const void *);
+
+void
+initialization_with_redundant_braces(any arg)
+{
+	any local = { 3.0 };	/* expect: 185 */
+	use();
+}
+
+// TODO: message 185 needs to be reworded to "cannot initialize '%s' from '%s'".

Index: src/tests/usr.bin/xlint/lint1/msg_185.exp
diff -u src/tests/usr.bin/xlint/lint1/msg_185.exp:1.1 src/tests/usr.bin/xlint/lint1/msg_185.exp:1.2
--- src/tests/usr.bin/xlint/lint1/msg_185.exp:1.1	Sat Jan  2 10:22:43 2021
+++ src/tests/usr.bin/xlint/lint1/msg_185.exp	Thu Mar 18 21:20:21 2021
@@ -1 +1 @@
-msg_185.c(6): syntax error ':' [249]
+msg_185.c(15): initialization type mismatch (pointer to const void) and (double) [185]



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

2021-03-18 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Thu Mar 18 20:58:02 UTC 2021

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

Log Message:
tests/lint: warning 210 has type information by now


To generate a diff of this commit:
cvs rdiff -u -r1.4 -r1.5 src/tests/usr.bin/xlint/lint1/d_struct_init_nested.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/d_struct_init_nested.c
diff -u src/tests/usr.bin/xlint/lint1/d_struct_init_nested.c:1.4 src/tests/usr.bin/xlint/lint1/d_struct_init_nested.c:1.5
--- src/tests/usr.bin/xlint/lint1/d_struct_init_nested.c:1.4	Sun Feb 21 09:07:58 2021
+++ src/tests/usr.bin/xlint/lint1/d_struct_init_nested.c	Thu Mar 18 20:58:02 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: d_struct_init_nested.c,v 1.4 2021/02/21 09:07:58 rillig Exp $	*/
+/*	$NetBSD: d_struct_init_nested.c,v 1.5 2021/03/18 20:58:02 rillig Exp $	*/
 # 3 "d_struct_init_nested.c"
 
 /*
@@ -62,6 +62,5 @@ funcOuter3Inner2(void)
 	inner,		/*FIXME*//* expect: 185 */
 	O3C
 	};			/*FIXME*//* expect: 210 */
-/* FIXME: warning 210 must print the type names to be any useful */
 	return o3i2.o1;
 }



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

2021-03-18 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Thu Mar 18 20:55:58 UTC 2021

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

Log Message:
lint: reduce debug logging for initialization, update documentation

No functional change outside debug mode.


To generate a diff of this commit:
cvs rdiff -u -r1.93 -r1.94 src/usr.bin/xlint/lint1/init.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/init.c
diff -u src/usr.bin/xlint/lint1/init.c:1.93 src/usr.bin/xlint/lint1/init.c:1.94
--- src/usr.bin/xlint/lint1/init.c:1.93	Thu Mar 18 20:22:50 2021
+++ src/usr.bin/xlint/lint1/init.c	Thu Mar 18 20:55:58 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: init.c,v 1.93 2021/03/18 20:22:50 rillig Exp $	*/
+/*	$NetBSD: init.c,v 1.94 2021/03/18 20:55:58 rillig Exp $	*/
 
 /*
  * Copyright (c) 1994, 1995 Jochen Pohl
@@ -37,7 +37,7 @@
 
 #include 
 #if defined(__RCSID) && !defined(lint)
-__RCSID("$NetBSD: init.c,v 1.93 2021/03/18 20:22:50 rillig Exp $");
+__RCSID("$NetBSD: init.c,v 1.94 2021/03/18 20:55:58 rillig Exp $");
 #endif
 
 #include 
@@ -61,24 +61,22 @@ __RCSID("$NetBSD: init.c,v 1.93 2021/03/
  *	struct { int x, y; } point = { 3, 4 };
  *	struct { int x, y; } point = { .y = 3, .x = 4 };
  *
- * An initializer may be surrounded by an extra pair of braces, like in the
- * example 'number_with_braces'.  For multi-dimensional arrays, the inner
- * braces may be omitted like in array_flat or spelled out like in
- * array_nested.
+ * The initializer that follows the '=' may be surrounded by an extra pair of
+ * braces, like in the example 'number_with_braces'.  For multi-dimensional
+ * arrays, the inner braces may be omitted like in array_flat or spelled out
+ * like in array_nested.
  *
  * For the initializer, the grammar parser calls these functions:
  *
- *	init_lbrace	for a '{'
- *	init_using_expr	for a value
- *	init_rbrace	for a '}'
+ *	init_lbrace	for each '{'
+ *	init_using_expr	for each value
+ *	init_rbrace	for each '}'
  *
  * The state of the current initialization is stored in initstk, a stack of
- * initstack_element, one element per level of braces.
- * (TODO: It might be more complicated for multi-dimensional arrays.)
+ * initstack_element, one element per type aggregate level.
  *
- * In initstk, when initializing an array, there is an additional level where
- * the number of remaining elements toggles between 1 and 0.
- * (TODO: Why is this extra level actually needed?  It seems redundant.)
+ * Most of the time, the topmost level of initstk contains a scalar type, and
+ * its remaining count toggles between 1 and 0.
  *
  * See also:
  *	C99 6.7.8 "Initialization"
@@ -431,7 +429,7 @@ initstack_pop_item(void)
 	istk->i_remaining--;
 	lint_assert(istk->i_remaining >= 0);
 
-	debug_step("new top element with updated remaining:");
+	debug_step("new stack with updated remaining:");
 	debug_initstack_element(istk);
 
 	if (namedmem != NULL) {
@@ -530,7 +528,6 @@ initstack_push(void)
 	sym_t	*m;
 
 	debug_enter();
-	debug_initstack();
 
 	istk = initstk;
 
@@ -736,7 +733,6 @@ static void
 initstack_next_nobrace(void)
 {
 	debug_enter();
-	debug_initstack();
 
 	if (initstk->i_type == NULL && !is_scalar(initstk->i_subt->t_tspec)) {
 		/* {}-enclosed initializer required */



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

2021-03-18 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Thu Mar 18 20:22:50 UTC 2021

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

Log Message:
lint: document how initialization works, improve debug logging

No functional change outside debug mode.


To generate a diff of this commit:
cvs rdiff -u -r1.92 -r1.93 src/usr.bin/xlint/lint1/init.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/init.c
diff -u src/usr.bin/xlint/lint1/init.c:1.92 src/usr.bin/xlint/lint1/init.c:1.93
--- src/usr.bin/xlint/lint1/init.c:1.92	Thu Mar 18 14:58:44 2021
+++ src/usr.bin/xlint/lint1/init.c	Thu Mar 18 20:22:50 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: init.c,v 1.92 2021/03/18 14:58:44 rillig Exp $	*/
+/*	$NetBSD: init.c,v 1.93 2021/03/18 20:22:50 rillig Exp $	*/
 
 /*
  * Copyright (c) 1994, 1995 Jochen Pohl
@@ -37,7 +37,7 @@
 
 #include 
 #if defined(__RCSID) && !defined(lint)
-__RCSID("$NetBSD: init.c,v 1.92 2021/03/18 14:58:44 rillig Exp $");
+__RCSID("$NetBSD: init.c,v 1.93 2021/03/18 20:22:50 rillig Exp $");
 #endif
 
 #include 
@@ -47,6 +47,46 @@ __RCSID("$NetBSD: init.c,v 1.92 2021/03/
 
 
 /*
+ * Initialization
+ *
+ * Handles initializations of global or local objects, like in:
+ *
+ *	int number = 12345;
+ *	int number_with_braces = { 12345 };
+ *
+ *	int array_of_unknown_size[] = { 111, 222, 333 };
+ *	int array_flat[2][2] = { 11, 12, 21, 22 };
+ *	int array_nested[2][2] = { { 11, 12 }, { 21, 22 } };
+ *
+ *	struct { int x, y; } point = { 3, 4 };
+ *	struct { int x, y; } point = { .y = 3, .x = 4 };
+ *
+ * An initializer may be surrounded by an extra pair of braces, like in the
+ * example 'number_with_braces'.  For multi-dimensional arrays, the inner
+ * braces may be omitted like in array_flat or spelled out like in
+ * array_nested.
+ *
+ * For the initializer, the grammar parser calls these functions:
+ *
+ *	init_lbrace	for a '{'
+ *	init_using_expr	for a value
+ *	init_rbrace	for a '}'
+ *
+ * The state of the current initialization is stored in initstk, a stack of
+ * initstack_element, one element per level of braces.
+ * (TODO: It might be more complicated for multi-dimensional arrays.)
+ *
+ * In initstk, when initializing an array, there is an additional level where
+ * the number of remaining elements toggles between 1 and 0.
+ * (TODO: Why is this extra level actually needed?  It seems redundant.)
+ *
+ * See also:
+ *	C99 6.7.8 "Initialization"
+ *	d_c99_init.c for more examples
+ */
+
+
+/*
  * Type of stack which is used for initialization of aggregate types.
  *
  * XXX: Since C99, a stack is an inappropriate data structure for modelling
@@ -94,6 +134,7 @@ typedef	struct initstack_element {
 	 */
 	bool i_brace: 1;
 
+	/* Whether i_type is an array of unknown size. */
 	bool i_array_of_unknown_size: 1;
 	bool i_seen_named_member: 1;
 
@@ -106,6 +147,8 @@ typedef	struct initstack_element {
 	/*
 	 * The number of remaining elements.
 	 *
+	 * For an array of unknown size, this is always 0 and thus irrelevant.
+	 *
 	 * XXX: for scalars?
 	 * XXX: for structs?
 	 * XXX: for unions?
@@ -499,11 +542,13 @@ initstack_push(void)
 		 */
 		lint_assert(istk->i_enclosing->i_enclosing == NULL);
 		lint_assert(istk->i_type->t_tspec == ARRAY);
+
 		debug_step("extending array of unknown size '%s'",
 		type_name(istk->i_type));
 		istk->i_remaining = 1;
 		istk->i_type->t_dim++;
 		setcomplete(istk->i_type, true);
+
 		debug_step("extended type is '%s'", type_name(istk->i_type));
 	}
 
@@ -544,9 +589,9 @@ again:
 		istk->i_subt = istk->i_type->t_subt;
 		istk->i_array_of_unknown_size = is_incomplete(istk->i_type);
 		istk->i_remaining = istk->i_type->t_dim;
-		debug_step("elements array %s[%d] %s",
-		type_name(istk->i_subt), istk->i_remaining,
-		namedmem != NULL ? namedmem->n_name : "*none*");
+		debug_named_member();
+		debug_step("type '%s' remaining %d",
+		type_name(istk->i_type), istk->i_remaining);
 		break;
 	case UNION:
 		if (tflag)
@@ -563,10 +608,10 @@ again:
 			return;
 		}
 		cnt = 0;
-		debug_step("lookup type=%s, name=%s named=%d",
+		debug_named_member();
+		debug_step("lookup for '%s'%s",
 		type_name(istk->i_type),
-		namedmem != NULL ? namedmem->n_name : "*none*",
-		istk->i_seen_named_member);
+		istk->i_seen_named_member ? ", seen named member" : "");
 		for (m = istk->i_type->t_str->sou_first_member;
 		 m != NULL; m = m->s_next) {
 			if (m->s_bitfield && m->s_name == unnamed)
@@ -876,6 +921,8 @@ init_using_expr(tnode_t *tn)
 
 	lint_assert(is_scalar(lt));	/* at least before C99 */
 
+	debug_step("typeok '%s', '%s'",
+	type_name(ln->tn_type), type_name(tn->tn_type));
 	if (!typeok(INIT, 0, ln, tn)) {
 		debug_initstack();
 		debug_leave();
@@ -892,6 +939,9 @@ init_using_expr(tnode_t *tn)
 
 	check_bit_field_init(ln, lt, rt);
 
+	/*
+	 * XXX: Is it correct to do this conversion _after_ the typeok above?
+	 */
 	if (lt != rt || 

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

2021-03-18 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Thu Mar 18 20:20:55 UTC 2021

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

Log Message:
tests/lint: add more examples for initialization


To generate a diff of this commit:
cvs rdiff -u -r1.6 -r1.7 src/tests/usr.bin/xlint/lint1/d_c99_init.c
cvs rdiff -u -r1.5 -r1.6 src/tests/usr.bin/xlint/lint1/d_c99_init.exp

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/d_c99_init.c
diff -u src/tests/usr.bin/xlint/lint1/d_c99_init.c:1.6 src/tests/usr.bin/xlint/lint1/d_c99_init.c:1.7
--- src/tests/usr.bin/xlint/lint1/d_c99_init.c:1.6	Sun Feb 21 14:19:27 2021
+++ src/tests/usr.bin/xlint/lint1/d_c99_init.c	Thu Mar 18 20:20:55 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: d_c99_init.c,v 1.6 2021/02/21 14:19:27 rillig Exp $	*/
+/*	$NetBSD: d_c99_init.c,v 1.7 2021/03/18 20:20:55 rillig Exp $	*/
 # 3 "d_c99_init.c"
 
 /*
@@ -47,9 +47,83 @@ void
 initialization_with_redundant_braces(any arg)
 {
 	any local = { arg };	/* expect: 185 */
-	// FIXME: message 185 needs to be reworded to "cannot initialize '%s' from '%s'".
+	// TODO: message 185 needs to be reworded to "cannot initialize '%s' from '%s'".
 	use();
 }
 
+// Some of the following examples are mentioned in init.c.
+
+int number = 12345;
+
+int number_with_braces_and_comma = {
+	12345,
+};
+
+int array_with_fixed_size[3] = {
+	111,
+	222,
+	333,
+	444,			/* expect: too many array initializers */
+};
+
 // See initstack_push, 'extending array of unknown size'.
-const int primes[] = { 2, 3, 5, 7, 9 };
+int array_of_unknown_size[] = {
+	111,
+	222,
+	333,
+};
+
+int array_flat[2][2] = {
+	11,
+	12,
+	21,
+	22
+};
+
+int array_nested[2][2] = {
+	{
+		11,
+		12
+	},
+	{
+		21,
+		22
+	}
+};
+
+int array_with_designators[] = {
+	['1'] = 111,
+	['5'] = 555,
+	['9'] = 999
+};
+
+int array_with_some_designators[] = {
+	['1'] = 111,
+	222,
+	['9'] = 999
+};
+
+struct point {
+	int x;
+	int y;
+};
+
+struct point point = {
+	3,
+	4
+};
+
+struct point point_with_designators = {
+	.y = 4,
+	.x = 3,
+};
+
+struct point point_with_mixed_designators = {
+	.x = 3,
+	4,
+	// FIXME: assertion failure '== ARRAY'
+	// 5,
+	.x = 3,
+};
+
+// See d_struct_init_nested.c for a more complicated example.

Index: src/tests/usr.bin/xlint/lint1/d_c99_init.exp
diff -u src/tests/usr.bin/xlint/lint1/d_c99_init.exp:1.5 src/tests/usr.bin/xlint/lint1/d_c99_init.exp:1.6
--- src/tests/usr.bin/xlint/lint1/d_c99_init.exp:1.5	Mon Feb 22 15:09:50 2021
+++ src/tests/usr.bin/xlint/lint1/d_c99_init.exp	Thu Mar 18 20:20:55 2021
@@ -1,3 +1,4 @@
 d_c99_init.c(22): invalid initializer type int [176]
 d_c99_init.c(23): too many initializers [174]
 d_c99_init.c(49): initialization type mismatch (pointer to const void) and (struct any) [185]
+d_c99_init.c(66): too many array initializers, expected 3 [173]



CVS commit: src/usr.sbin/mtree

2021-03-18 Thread Aleksey Cheusov
Module Name:src
Committed By:   cheusov
Date:   Thu Mar 18 20:02:19 UTC 2021

Modified Files:
src/usr.sbin/mtree: compare.c crc.c extern.h verify.c

Log Message:
mtree: use POSIX type uint32_t instead of u_int32_t


To generate a diff of this commit:
cvs rdiff -u -r1.58 -r1.59 src/usr.sbin/mtree/compare.c
cvs rdiff -u -r1.9 -r1.10 src/usr.sbin/mtree/crc.c
cvs rdiff -u -r1.39 -r1.40 src/usr.sbin/mtree/extern.h
cvs rdiff -u -r1.46 -r1.47 src/usr.sbin/mtree/verify.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.sbin/mtree/compare.c
diff -u src/usr.sbin/mtree/compare.c:1.58 src/usr.sbin/mtree/compare.c:1.59
--- src/usr.sbin/mtree/compare.c:1.58	Thu Nov 21 18:39:50 2013
+++ src/usr.sbin/mtree/compare.c	Thu Mar 18 20:02:18 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: compare.c,v 1.58 2013/11/21 18:39:50 christos Exp $	*/
+/*	$NetBSD: compare.c,v 1.59 2021/03/18 20:02:18 cheusov Exp $	*/
 
 /*-
  * Copyright (c) 1989, 1993
@@ -38,7 +38,7 @@
 #if 0
 static char sccsid[] = "@(#)compare.c	8.1 (Berkeley) 6/6/93";
 #else
-__RCSID("$NetBSD: compare.c,v 1.58 2013/11/21 18:39:50 christos Exp $");
+__RCSID("$NetBSD: compare.c,v 1.59 2021/03/18 20:02:18 cheusov Exp $");
 #endif
 #endif /* not lint */
 
@@ -135,7 +135,7 @@ do {	\
 int
 compare(NODE *s, FTSENT *p)
 {
-	u_int32_t len, val, flags;
+	uint32_t len, val, flags;
 	int fd, label;
 	const char *cp, *tab;
 #if !defined(NO_MD5) || !defined(NO_RMD160) || !defined(NO_SHA1) || !defined(NO_SHA2)

Index: src/usr.sbin/mtree/crc.c
diff -u src/usr.sbin/mtree/crc.c:1.9 src/usr.sbin/mtree/crc.c:1.10
--- src/usr.sbin/mtree/crc.c:1.9	Fri Oct  5 00:40:51 2012
+++ src/usr.sbin/mtree/crc.c	Thu Mar 18 20:02:18 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: crc.c,v 1.9 2012/10/05 00:40:51 christos Exp $	*/
+/*	$NetBSD: crc.c,v 1.10 2021/03/18 20:02:18 cheusov Exp $	*/
 
 /*-
  * Copyright (c) 1991, 1993
@@ -41,7 +41,7 @@
 #if 0
 static char sccsid[] = "@(#)crc.c	8.1 (Berkeley) 6/17/93";
 #else
-__RCSID("$NetBSD: crc.c,v 1.9 2012/10/05 00:40:51 christos Exp $");
+__RCSID("$NetBSD: crc.c,v 1.10 2021/03/18 20:02:18 cheusov Exp $");
 #endif
 #endif /* not lint */
 
@@ -53,7 +53,7 @@ __RCSID("$NetBSD: crc.c,v 1.9 2012/10/05
 
 #include "extern.h"
 
-static const u_int32_t crctab[] = {
+static const uint32_t crctab[] = {
 	0x0,
 	0x04c11db7, 0x09823b6e, 0x0d4326d9, 0x130476dc, 0x17c56b6b,
 	0x1a864db2, 0x1e475005, 0x2608edb8, 0x22c9f00f, 0x2f8ad6d6,
@@ -114,15 +114,15 @@ static const u_int32_t crctab[] = {
  * locations to store the crc and the number of bytes read.  It returns 0 on
  * success and 1 on failure.  Errno is set on failure.
  */
-u_int32_t crc_total = ~0;		/* The crc over a number of files. */
+uint32_t crc_total = ~0;		/* The crc over a number of files. */
 
 int
-crc(int fd, u_int32_t *cval, u_int32_t *clen)
+crc(int fd, uint32_t *cval, uint32_t *clen)
 {
 	u_char *p;
 	int nr;
-	u_int32_t thecrc, len;
-	u_int32_t crctot;
+	uint32_t thecrc, len;
+	uint32_t crctot;
 	u_char buf[16 * 1024];
 
 #define	COMPUTE(var, ch)	(var) = (var) << 8 ^ crctab[(var) >> 24 ^ (ch)]

Index: src/usr.sbin/mtree/extern.h
diff -u src/usr.sbin/mtree/extern.h:1.39 src/usr.sbin/mtree/extern.h:1.40
--- src/usr.sbin/mtree/extern.h:1.39	Thu Apr 24 17:22:41 2014
+++ src/usr.sbin/mtree/extern.h	Thu Mar 18 20:02:18 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: extern.h,v 1.39 2014/04/24 17:22:41 christos Exp $	*/
+/*	$NetBSD: extern.h,v 1.40 2021/03/18 20:02:18 cheusov Exp $	*/
 
 /*-
  * Copyright (c) 1991, 1993
@@ -62,7 +62,7 @@ enum flavor {
 void	 addtag(slist_t *, char *);
 int	 check_excludes(const char *, const char *);
 int	 compare(NODE *, FTSENT *);
-int	 crc(int, u_int32_t *, u_int32_t *);
+int	 crc(int, uint32_t *, uint32_t *);
 void	 cwalk(FILE *);
 void	 dump_nodes(FILE *, const char *, NODE *, int);
 void	 init_excludes(void);
@@ -83,7 +83,7 @@ extern int	bflag, dflag, eflag, iflag, j
 extern int	mtree_Mflag, mtree_Sflag, mtree_Wflag;
 extern size_t	mtree_lineno;
 extern enum flavor	flavor;
-extern u_int32_t crc_total;
+extern uint32_t crc_total;
 extern int	ftsoptions, keys;
 extern char	fullpath[];
 extern slist_t	includetags, excludetags;

Index: src/usr.sbin/mtree/verify.c
diff -u src/usr.sbin/mtree/verify.c:1.46 src/usr.sbin/mtree/verify.c:1.47
--- src/usr.sbin/mtree/verify.c:1.46	Fri Jan 23 20:28:24 2015
+++ src/usr.sbin/mtree/verify.c	Thu Mar 18 20:02:18 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: verify.c,v 1.46 2015/01/23 20:28:24 christos Exp $	*/
+/*	$NetBSD: verify.c,v 1.47 2021/03/18 20:02:18 cheusov Exp $	*/
 
 /*-
  * Copyright (c) 1990, 1993
@@ -38,7 +38,7 @@
 #if 0
 static char sccsid[] = "@(#)verify.c	8.1 (Berkeley) 6/6/93";
 #else
-__RCSID("$NetBSD: verify.c,v 1.46 2015/01/23 20:28:24 christos Exp $");
+__RCSID("$NetBSD: verify.c,v 1.47 2021/03/18 20:02:18 cheusov Exp $");
 #endif
 #endif /* not lint */
 
@@ -178,7 +178,7 @@ miss(NODE *p, char *tail)
 	int create;
 	char *tp;
 	const char 

CVS commit: src/usr.bin/join

2021-03-18 Thread Aleksey Cheusov
Module Name:src
Committed By:   cheusov
Date:   Thu Mar 18 19:47:41 UTC 2021

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

Log Message:
join.c: print usage after warning "illegal option..." as it was originally 
intended


To generate a diff of this commit:
cvs rdiff -u -r1.32 -r1.33 src/usr.bin/join/join.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/join/join.c
diff -u src/usr.bin/join/join.c:1.32 src/usr.bin/join/join.c:1.33
--- src/usr.bin/join/join.c:1.32	Thu Mar 18 19:41:54 2021
+++ src/usr.bin/join/join.c	Thu Mar 18 19:47:41 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: join.c,v 1.32 2021/03/18 19:41:54 cheusov Exp $	*/
+/*	$NetBSD: join.c,v 1.33 2021/03/18 19:47:41 cheusov Exp $	*/
 
 /*-
  * Copyright (c) 1991 The Regents of the University of California.
@@ -47,7 +47,7 @@ __COPYRIGHT("@(#) Copyright (c) 1991\
 #if 0
 static char sccsid[] = "from: @(#)join.c	5.1 (Berkeley) 11/18/91";
 #else
-__RCSID("$NetBSD: join.c,v 1.32 2021/03/18 19:41:54 cheusov Exp $");
+__RCSID("$NetBSD: join.c,v 1.33 2021/03/18 19:47:41 cheusov Exp $");
 #endif
 #endif /* not lint */
 
@@ -589,8 +589,9 @@ obsolete(char **argv)
 			case '\0':
 break;
 			default:
-jbad:errx(1, "illegal option -- %s", ap);
+jbad:warnx("illegal option -- %s", ap);
 usage();
+exit(1);
 			}
 			break;
 		case 'o':



CVS commit: src/usr.bin/join

2021-03-18 Thread Aleksey Cheusov
Module Name:src
Committed By:   cheusov
Date:   Thu Mar 18 19:41:54 UTC 2021

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

Log Message:
join.c: explicitly convert -1 to u_long in order to fix compiler warnings


To generate a diff of this commit:
cvs rdiff -u -r1.31 -r1.32 src/usr.bin/join/join.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/join/join.c
diff -u src/usr.bin/join/join.c:1.31 src/usr.bin/join/join.c:1.32
--- src/usr.bin/join/join.c:1.31	Sun Sep  4 20:27:52 2011
+++ src/usr.bin/join/join.c	Thu Mar 18 19:41:54 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: join.c,v 1.31 2011/09/04 20:27:52 joerg Exp $	*/
+/*	$NetBSD: join.c,v 1.32 2021/03/18 19:41:54 cheusov Exp $	*/
 
 /*-
  * Copyright (c) 1991 The Regents of the University of California.
@@ -47,7 +47,7 @@ __COPYRIGHT("@(#) Copyright (c) 1991\
 #if 0
 static char sccsid[] = "from: @(#)join.c	5.1 (Berkeley) 11/18/91";
 #else
-__RCSID("$NetBSD: join.c,v 1.31 2011/09/04 20:27:52 joerg Exp $");
+__RCSID("$NetBSD: join.c,v 1.32 2021/03/18 19:41:54 cheusov Exp $");
 #endif
 #endif /* not lint */
 
@@ -89,8 +89,8 @@ typedef struct {
 	u_long setalloc;	/* set allocated count */
 } INPUT;
 
-static INPUT input1 = { NULL, 0, 0, 1, NULL, -1, 0, 0, },
-  input2 = { NULL, 0, 0, 2, NULL, -1, 0, 0, };
+static INPUT input1 = { NULL, 0, 0, 1, NULL, (u_long)-1, 0, 0, };
+static INPUT input2 = { NULL, 0, 0, 2, NULL, (u_long)-1, 0, 0, };
 
 typedef struct {
 	u_long	fileno;		/* file number */



CVS commit: src/usr.bin/ipcs

2021-03-18 Thread Aleksey Cheusov
Module Name:src
Committed By:   cheusov
Date:   Thu Mar 18 19:34:05 UTC 2021

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

Log Message:
ipcs.c: do not #include sys/inttypes.h header which is not necessary


To generate a diff of this commit:
cvs rdiff -u -r1.43 -r1.44 src/usr.bin/ipcs/ipcs.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/ipcs/ipcs.c
diff -u src/usr.bin/ipcs/ipcs.c:1.43 src/usr.bin/ipcs/ipcs.c:1.44
--- src/usr.bin/ipcs/ipcs.c:1.43	Wed Jun 11 14:57:55 2014
+++ src/usr.bin/ipcs/ipcs.c	Thu Mar 18 19:34:05 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: ipcs.c,v 1.43 2014/06/11 14:57:55 joerg Exp $	*/
+/*	$NetBSD: ipcs.c,v 1.44 2021/03/18 19:34:05 cheusov Exp $	*/
 
 /*-
  * Copyright (c) 2000 The NetBSD Foundation, Inc.
@@ -57,7 +57,6 @@
 #include 
 #include 
 #include 
-#include 
 #include 
 #include 
 #include 



CVS commit: src/usr.bin/find

2021-03-18 Thread Aleksey Cheusov
Module Name:src
Committed By:   cheusov
Date:   Thu Mar 18 18:24:14 UTC 2021

Modified Files:
src/usr.bin/find: function.c

Log Message:
find: use POSIX strtoll(3) instead of legacy strtoq(3)


To generate a diff of this commit:
cvs rdiff -u -r1.78 -r1.79 src/usr.bin/find/function.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/find/function.c
diff -u src/usr.bin/find/function.c:1.78 src/usr.bin/find/function.c:1.79
--- src/usr.bin/find/function.c:1.78	Thu Mar 18 18:21:18 2021
+++ src/usr.bin/find/function.c	Thu Mar 18 18:24:14 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: function.c,v 1.78 2021/03/18 18:21:18 cheusov Exp $	*/
+/*	$NetBSD: function.c,v 1.79 2021/03/18 18:24:14 cheusov Exp $	*/
 
 /*-
  * Copyright (c) 1990, 1993
@@ -37,7 +37,7 @@
 #if 0
 static char sccsid[] = "from: @(#)function.c	8.10 (Berkeley) 5/4/95";
 #else
-__RCSID("$NetBSD: function.c,v 1.78 2021/03/18 18:21:18 cheusov Exp $");
+__RCSID("$NetBSD: function.c,v 1.79 2021/03/18 18:24:14 cheusov Exp $");
 #endif
 #endif /* not lint */
 
@@ -181,7 +181,7 @@ find_parsenum(PLAN *plan, const char *op
 	 * and endchar points to the beginning of the string we know we have
 	 * a syntax error.
 	 */
-	value = strtoq(str, , 10);
+	value = strtoll(str, , 10);
 	if (value == 0 && endchar == str)
 		errx(1, "%s: %s: illegal numeric value", option, vp);
 	if (endchar[0] && (endch == NULL || endchar[0] != *endch))



CVS commit: src/usr.bin/find

2021-03-18 Thread Aleksey Cheusov
Module Name:src
Committed By:   cheusov
Date:   Thu Mar 18 18:21:18 UTC 2021

Modified Files:
src/usr.bin/find: find.h function.c

Log Message:
find: use POSIX type uint32_t instead of u_int32_t


To generate a diff of this commit:
cvs rdiff -u -r1.26 -r1.27 src/usr.bin/find/find.h
cvs rdiff -u -r1.77 -r1.78 src/usr.bin/find/function.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/find/find.h
diff -u src/usr.bin/find/find.h:1.26 src/usr.bin/find/find.h:1.27
--- src/usr.bin/find/find.h:1.26	Mon Jun 13 00:04:40 2016
+++ src/usr.bin/find/find.h	Thu Mar 18 18:21:18 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: find.h,v 1.26 2016/06/13 00:04:40 pgoyette Exp $	*/
+/*	$NetBSD: find.h,v 1.27 2021/03/18 18:21:18 cheusov Exp $	*/
 
 /*-
  * Copyright (c) 1990, 1993
@@ -65,7 +65,7 @@ typedef struct _plandata {
 	int flags;/* private flags */
 	enum ntype type;			/* plan node type */
 	union {
-		u_int32_t _f_data;		/* flags */
+		uint32_t _f_data;		/* flags */
 		gid_t _g_data;			/* gid */
 		ino_t _i_data;			/* inode */
 		mode_t _m_data;			/* mode mask */

Index: src/usr.bin/find/function.c
diff -u src/usr.bin/find/function.c:1.77 src/usr.bin/find/function.c:1.78
--- src/usr.bin/find/function.c:1.77	Tue Sep  4 15:16:15 2018
+++ src/usr.bin/find/function.c	Thu Mar 18 18:21:18 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: function.c,v 1.77 2018/09/04 15:16:15 kre Exp $	*/
+/*	$NetBSD: function.c,v 1.78 2021/03/18 18:21:18 cheusov Exp $	*/
 
 /*-
  * Copyright (c) 1990, 1993
@@ -37,7 +37,7 @@
 #if 0
 static char sccsid[] = "from: @(#)function.c	8.10 (Berkeley) 5/4/95";
 #else
-__RCSID("$NetBSD: function.c,v 1.77 2018/09/04 15:16:15 kre Exp $");
+__RCSID("$NetBSD: function.c,v 1.78 2021/03/18 18:21:18 cheusov Exp $");
 #endif
 #endif /* not lint */
 
@@ -960,7 +960,7 @@ c_false(char ***argvp, int isok, char *o
 int
 f_flags(PLAN *plan, FTSENT *entry)
 {
-	u_int32_t flags;
+	uint32_t flags;
 
 	flags = entry->fts_statp->st_flags;
 	if (plan->flags == F_ATLEAST)



CVS commit: src/usr.bin/cksum

2021-03-18 Thread Aleksey Cheusov
Module Name:src
Committed By:   cheusov
Date:   Thu Mar 18 18:12:35 UTC 2021

Modified Files:
src/usr.bin/cksum: cksum.c crc.c crc_extern.h extern.h print.c sum1.c
sum2.c

Log Message:
cksum: use POSIX type uint32_t instead of u_int32_t


To generate a diff of this commit:
cvs rdiff -u -r1.48 -r1.49 src/usr.bin/cksum/cksum.c
cvs rdiff -u -r1.21 -r1.22 src/usr.bin/cksum/crc.c
cvs rdiff -u -r1.1 -r1.2 src/usr.bin/cksum/crc_extern.h
cvs rdiff -u -r1.19 -r1.20 src/usr.bin/cksum/extern.h
cvs rdiff -u -r1.11 -r1.12 src/usr.bin/cksum/print.c
cvs rdiff -u -r1.13 -r1.14 src/usr.bin/cksum/sum1.c src/usr.bin/cksum/sum2.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/cksum/cksum.c
diff -u src/usr.bin/cksum/cksum.c:1.48 src/usr.bin/cksum/cksum.c:1.49
--- src/usr.bin/cksum/cksum.c:1.48	Tue Jun 16 22:54:10 2015
+++ src/usr.bin/cksum/cksum.c	Thu Mar 18 18:12:35 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: cksum.c,v 1.48 2015/06/16 22:54:10 christos Exp $	*/
+/*	$NetBSD: cksum.c,v 1.49 2021/03/18 18:12:35 cheusov Exp $	*/
 
 /*-
  * Copyright (c) 1991, 1993
@@ -81,7 +81,7 @@ __COPYRIGHT("@(#) Copyright (c) 1991, 19
 #if 0
 static char sccsid[] = "@(#)cksum.c	8.2 (Berkeley) 4/28/95";
 #endif
-__RCSID("$NetBSD: cksum.c,v 1.48 2015/06/16 22:54:10 christos Exp $");
+__RCSID("$NetBSD: cksum.c,v 1.49 2021/03/18 18:12:35 cheusov Exp $");
 #endif /* not lint */
 
 #include 
@@ -153,12 +153,12 @@ int
 main(int argc, char **argv)
 {
 	int ch, fd, rval, pflag, nohashstdin;
-	u_int32_t val;
+	uint32_t val;
 	off_t len;
 	char *fn;
 	const char *progname;
-	int (*cfncn) (int, u_int32_t *, off_t *);
-	void (*pfncn) (char *, u_int32_t, off_t);
+	int (*cfncn) (int, uint32_t *, off_t *);
+	void (*pfncn) (char *, uint32_t, off_t);
 	const struct hash *hash;
 	int i, check_warn, do_check;
 	int print_flags;
@@ -436,7 +436,7 @@ main(int argc, char **argv)
 	if (cfncn(fd, , )) 
 		ok = 0;
 	else {
-		u_int32_t should_val;
+		uint32_t should_val;
 		
 		should_val =
 		  strtoul(cksum, NULL, 10);

Index: src/usr.bin/cksum/crc.c
diff -u src/usr.bin/cksum/crc.c:1.21 src/usr.bin/cksum/crc.c:1.22
--- src/usr.bin/cksum/crc.c:1.21	Mon Apr 27 07:30:54 2020
+++ src/usr.bin/cksum/crc.c	Thu Mar 18 18:12:35 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: crc.c,v 1.21 2020/04/27 07:30:54 martin Exp $	*/
+/*	$NetBSD: crc.c,v 1.22 2021/03/18 18:12:35 cheusov Exp $	*/
 
 /*-
  * Copyright (c) 1991, 1993
@@ -41,7 +41,7 @@
 #if 0
 static char sccsid[] = "@(#)crc.c	8.1 (Berkeley) 6/17/93";
 #else
-__RCSID("$NetBSD: crc.c,v 1.21 2020/04/27 07:30:54 martin Exp $");
+__RCSID("$NetBSD: crc.c,v 1.22 2021/03/18 18:12:35 cheusov Exp $");
 #endif
 #endif /* not lint */
 
@@ -52,7 +52,7 @@ __RCSID("$NetBSD: crc.c,v 1.21 2020/04/2
 
 #include "extern.h"
 
-static const u_int32_t crctab[] = {
+static const uint32_t crctab[] = {
 	0x0,
 	0x04c11db7, 0x09823b6e, 0x0d4326d9, 0x130476dc, 0x17c56b6b,
 	0x1a864db2, 0x1e475005, 0x2608edb8, 0x22c9f00f, 0x2f8ad6d6,
@@ -114,10 +114,10 @@ static const u_int32_t crctab[] = {
  * success and 1 on failure.  Errno is set on failure.
  */
 int
-crc(int fd, u_int32_t *cval, off_t *clen)
+crc(int fd, uint32_t *cval, off_t *clen)
 {
 	ssize_t nr;
-	u_int32_t thecrc;
+	uint32_t thecrc;
 	off_t len;
 	u_char buf[16 * 1024];
 

Index: src/usr.bin/cksum/crc_extern.h
diff -u src/usr.bin/cksum/crc_extern.h:1.1 src/usr.bin/cksum/crc_extern.h:1.2
--- src/usr.bin/cksum/crc_extern.h:1.1	Mon Sep  4 20:01:10 2006
+++ src/usr.bin/cksum/crc_extern.h	Thu Mar 18 18:12:35 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: crc_extern.h,v 1.1 2006/09/04 20:01:10 dsl Exp $	*/
+/*	$NetBSD: crc_extern.h,v 1.2 2021/03/18 18:12:35 cheusov Exp $	*/
 
 /*-
  * Copyright (c) 1991, 1993
@@ -32,7 +32,7 @@
  */
 
 __BEGIN_DECLS
-int	 crc(int, u_int32_t *, off_t *);
+int	 crc(int, uint32_t *, off_t *);
 uint32_t crc_buf(uint32_t, const void *, size_t);
 uint32_t crc_byte(uint32_t, unsigned int);
 __END_DECLS

Index: src/usr.bin/cksum/extern.h
diff -u src/usr.bin/cksum/extern.h:1.19 src/usr.bin/cksum/extern.h:1.20
--- src/usr.bin/cksum/extern.h:1.19	Mon Sep  4 20:01:10 2006
+++ src/usr.bin/cksum/extern.h	Thu Mar 18 18:12:35 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: extern.h,v 1.19 2006/09/04 20:01:10 dsl Exp $	*/
+/*	$NetBSD: extern.h,v 1.20 2021/03/18 18:12:35 cheusov Exp $	*/
 
 /*-
  * Copyright (c) 1991, 1993
@@ -39,12 +39,12 @@
 #include "crc_extern.h"
 
 __BEGIN_DECLS
-void	pcrc(char *, u_int32_t, off_t);
-void	psum1(char *, u_int32_t, off_t);
-void	psum2(char *, u_int32_t, off_t);
-int	csum1(int, u_int32_t *, off_t *);
-int	csum2(int, u_int32_t *, off_t *);
-int	md5(int, u_int32_t *, u_int32_t *);
+void	pcrc(char *, uint32_t, off_t);
+void	psum1(char *, uint32_t, off_t);
+void	psum2(char *, uint32_t, off_t);
+int	csum1(int, uint32_t *, off_t *);
+int	csum2(int, uint32_t *, off_t *);
+int	md5(int, uint32_t *, uint32_t *);
 
 void	MD2String(const char 

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

2021-03-18 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Thu Mar 18 14:58:44 UTC 2021

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

Log Message:
lint: document the initialization of an object in more detail

This will help fixing the bugs that are currently demonstrated in
msg_168.c and d_struct_init_nested.c.


To generate a diff of this commit:
cvs rdiff -u -r1.91 -r1.92 src/usr.bin/xlint/lint1/init.c
cvs rdiff -u -r1.73 -r1.74 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/init.c
diff -u src/usr.bin/xlint/lint1/init.c:1.91 src/usr.bin/xlint/lint1/init.c:1.92
--- src/usr.bin/xlint/lint1/init.c:1.91	Wed Mar 17 15:45:30 2021
+++ src/usr.bin/xlint/lint1/init.c	Thu Mar 18 14:58:44 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: init.c,v 1.91 2021/03/17 15:45:30 rillig Exp $	*/
+/*	$NetBSD: init.c,v 1.92 2021/03/18 14:58:44 rillig Exp $	*/
 
 /*
  * Copyright (c) 1994, 1995 Jochen Pohl
@@ -37,7 +37,7 @@
 
 #include 
 #if defined(__RCSID) && !defined(lint)
-__RCSID("$NetBSD: init.c,v 1.91 2021/03/17 15:45:30 rillig Exp $");
+__RCSID("$NetBSD: init.c,v 1.92 2021/03/18 14:58:44 rillig Exp $");
 #endif
 
 #include 
@@ -64,9 +64,23 @@ __RCSID("$NetBSD: init.c,v 1.91 2021/03/
  */
 typedef	struct initstack_element {
 
-	/* XXX: Why is i_type often null? */
-	type_t	*i_type;		/* type of initialization */
-	type_t	*i_subt;		/* type of next level */
+	/*
+	 * The type to be initialized at this level.
+	 */
+	type_t	*i_type;
+	/*
+	 * The type that is initialized inside a further level of
+	 * braces.  It is completely independent from i_type->t_subt.
+	 *
+	 * For example, in 'int var = { init }', initially there is an
+	 * initstack_element with i_subt == int.  When the '{' is processed,
+	 * an element with i_type == int is pushed to the stack.  When the
+	 * corresponding '}' is processed, the inner element is popped again.
+	 *
+	 * During initialization, only the top 2 elements of the stack are
+	 * looked at.
+	 */
+	type_t	*i_subt;
 
 	/*
 	 * This level of the initializer requires a '}' to be completed.
@@ -607,6 +621,7 @@ again:
 			initstk = inxt;
 			goto again;
 		}
+		/* XXX: Why is this set to 1 unconditionally? */
 		istk->i_remaining = 1;
 		break;
 	}
@@ -639,6 +654,11 @@ check_too_many_initializers(void)
 	initerr = true;
 }
 
+/*
+ * Process a '{' in an initializer by starting the initialization of the
+ * nested data structure, with i_type being the i_subt of the outer
+ * initialization level.
+ */
 static void
 initstack_next_brace(void)
 {
@@ -657,8 +677,9 @@ initstack_next_brace(void)
 		initstack_push();
 	if (!initerr) {
 		initstk->i_brace = true;
-		debug_step("%p %s", namedmem, type_name(
-		initstk->i_type != NULL ? initstk->i_type
+		debug_named_member();
+		debug_step("expecting type '%s'",
+		type_name(initstk->i_type != NULL ? initstk->i_type
 			: initstk->i_subt));
 	}
 
@@ -675,6 +696,7 @@ initstack_next_nobrace(void)
 	if (initstk->i_type == NULL && !is_scalar(initstk->i_subt->t_tspec)) {
 		/* {}-enclosed initializer required */
 		error(181);
+		/* XXX: maybe set initerr here */
 	}
 
 	if (!initerr)
@@ -683,7 +705,7 @@ initstack_next_nobrace(void)
 	/*
 	 * Make sure an entry with a scalar type is at the top of the stack.
 	 *
-	 * FIXME: Since C99 an initializer for an object with automatic
+	 * FIXME: Since C99, an initializer for an object with automatic
 	 *  storage need not be a constant expression anymore.  It is
 	 *  perfectly fine to initialize a struct with a struct expression,
 	 *  see d_struct_init_nested.c for a demonstration.
@@ -727,6 +749,10 @@ init_lbrace(void)
 	debug_leave();
 }
 
+/*
+ * Process a '}' in an initializer by finishing the current level of the
+ * initialization stack.
+ */
 void
 init_rbrace(void)
 {
@@ -734,11 +760,7 @@ init_rbrace(void)
 		return;
 
 	debug_enter();
-	debug_initstack();
-
 	initstack_pop_brace();
-
-	debug_initstack();
 	debug_leave();
 }
 
@@ -784,9 +806,9 @@ init_using_expr(tnode_t *tn)
 	scl_t	sclass;
 
 	debug_enter();
+	debug_initstack();
 	debug_named_member();
 	debug_node(tn, debug_ind);
-	debug_initstack();
 
 	if (initerr || tn == NULL) {
 		debug_leave();
@@ -852,7 +874,7 @@ init_using_expr(tnode_t *tn)
 	lt = ln->tn_type->t_tspec;
 	rt = tn->tn_type->t_tspec;
 
-	lint_assert(is_scalar(lt));
+	lint_assert(is_scalar(lt));	/* at least before C99 */
 
 	if (!typeok(INIT, 0, ln, tn)) {
 		debug_initstack();

Index: src/usr.bin/xlint/lint1/lint1.h
diff -u src/usr.bin/xlint/lint1/lint1.h:1.73 src/usr.bin/xlint/lint1/lint1.h:1.74
--- src/usr.bin/xlint/lint1/lint1.h:1.73	Wed Mar 17 02:24:06 2021
+++ src/usr.bin/xlint/lint1/lint1.h	Thu Mar 18 14:58:44 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: lint1.h,v 1.73 2021/03/17 02:24:06 rillig Exp $ */
+/* $NetBSD: lint1.h,v 1.74 2021/03/18 14:58:44 rillig Exp $ */
 
 /*
  * Copyright (c) 1996 Christopher G. Demetriou.  All 

CVS commit: src/sys/kern

2021-03-18 Thread Nia Alarie
Module Name:src
Committed By:   nia
Date:   Thu Mar 18 14:05:38 UTC 2021

Modified Files:
src/sys/kern: subr_time.c

Log Message:
restore flags-as-bitmask, just in case another function is passing its
flags here.


To generate a diff of this commit:
cvs rdiff -u -r1.29 -r1.30 src/sys/kern/subr_time.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/kern/subr_time.c
diff -u src/sys/kern/subr_time.c:1.29 src/sys/kern/subr_time.c:1.30
--- src/sys/kern/subr_time.c:1.29	Thu Mar 18 14:01:18 2021
+++ src/sys/kern/subr_time.c	Thu Mar 18 14:05:37 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: subr_time.c,v 1.29 2021/03/18 14:01:18 nia Exp $	*/
+/*	$NetBSD: subr_time.c,v 1.30 2021/03/18 14:05:37 nia Exp $	*/
 
 /*
  * Copyright (c) 1982, 1986, 1989, 1993
@@ -33,7 +33,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: subr_time.c,v 1.29 2021/03/18 14:01:18 nia Exp $");
+__KERNEL_RCSID(0, "$NetBSD: subr_time.c,v 1.30 2021/03/18 14:05:37 nia Exp $");
 
 #include 
 #include 
@@ -332,7 +332,7 @@ ts2timo(clockid_t clock_id, int flags, s
 	if (ts->tv_nsec < 0 || ts->tv_nsec >= 10L)
 		return EINVAL;
 
-	if (flags == TIMER_ABSTIME || start != NULL) {
+	if ((flags & TIMER_ABSTIME) != 0 || start != NULL) {
 		error = clock_gettime1(clock_id, );
 		if (error != 0)
 			return error;
@@ -340,7 +340,7 @@ ts2timo(clockid_t clock_id, int flags, s
 			*start = tsd;
 	}
 
-	if (flags == TIMER_ABSTIME) {
+	if ((flags & TIMER_ABSTIME) != 0) {
 		if ((tsd.tv_sec > 0 && ts->tv_sec < LLONG_MIN + tsd.tv_sec) ||
 		(tsd.tv_sec < 0 && ts->tv_sec > LLONG_MAX + tsd.tv_sec))
 			return EINVAL;



CVS commit: src/sys/kern

2021-03-18 Thread Nia Alarie
Module Name:src
Committed By:   nia
Date:   Thu Mar 18 14:01:18 UTC 2021

Modified Files:
src/sys/kern: subr_time.c

Log Message:
ts2timo(9): refactor TIMER_ABSTIME handling

- only use *start for output of the original time.
  for clarity purposes, use the temporary variable for everything else.
- add a check for integer underflow

Reported-by: syzbot+17b5072d5ed262a96...@syzkaller.appspotmail.com


To generate a diff of this commit:
cvs rdiff -u -r1.28 -r1.29 src/sys/kern/subr_time.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/kern/subr_time.c
diff -u src/sys/kern/subr_time.c:1.28 src/sys/kern/subr_time.c:1.29
--- src/sys/kern/subr_time.c:1.28	Thu Mar 18 13:45:15 2021
+++ src/sys/kern/subr_time.c	Thu Mar 18 14:01:18 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: subr_time.c,v 1.28 2021/03/18 13:45:15 nia Exp $	*/
+/*	$NetBSD: subr_time.c,v 1.29 2021/03/18 14:01:18 nia Exp $	*/
 
 /*
  * Copyright (c) 1982, 1986, 1989, 1993
@@ -33,7 +33,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: subr_time.c,v 1.28 2021/03/18 13:45:15 nia Exp $");
+__KERNEL_RCSID(0, "$NetBSD: subr_time.c,v 1.29 2021/03/18 14:01:18 nia Exp $");
 
 #include 
 #include 
@@ -332,17 +332,20 @@ ts2timo(clockid_t clock_id, int flags, s
 	if (ts->tv_nsec < 0 || ts->tv_nsec >= 10L)
 		return EINVAL;
 
-	if (start == NULL)
-		start = 
-
-	if (flags != TIMER_RELTIME || start != ) {
-		error = clock_gettime1(clock_id, start);
+	if (flags == TIMER_ABSTIME || start != NULL) {
+		error = clock_gettime1(clock_id, );
 		if (error != 0)
 			return error;
+		if (start != NULL)
+			*start = tsd;
 	}
 
-	if (flags != TIMER_RELTIME)
-		timespecsub(ts, start, ts);
+	if (flags == TIMER_ABSTIME) {
+		if ((tsd.tv_sec > 0 && ts->tv_sec < LLONG_MIN + tsd.tv_sec) ||
+		(tsd.tv_sec < 0 && ts->tv_sec > LLONG_MAX + tsd.tv_sec))
+			return EINVAL;
+		timespecsub(ts, , ts);
+	}
 
 	error = itimespecfix(ts);
 	if (error != 0)



CVS commit: src/sys/kern

2021-03-18 Thread Nia Alarie
Module Name:src
Committed By:   nia
Date:   Thu Mar 18 13:45:15 UTC 2021

Modified Files:
src/sys/kern: subr_time.c

Log Message:
revert previous


To generate a diff of this commit:
cvs rdiff -u -r1.27 -r1.28 src/sys/kern/subr_time.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/kern/subr_time.c
diff -u src/sys/kern/subr_time.c:1.27 src/sys/kern/subr_time.c:1.28
--- src/sys/kern/subr_time.c:1.27	Thu Mar 18 12:37:51 2021
+++ src/sys/kern/subr_time.c	Thu Mar 18 13:45:15 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: subr_time.c,v 1.27 2021/03/18 12:37:51 nia Exp $	*/
+/*	$NetBSD: subr_time.c,v 1.28 2021/03/18 13:45:15 nia Exp $	*/
 
 /*
  * Copyright (c) 1982, 1986, 1989, 1993
@@ -33,7 +33,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: subr_time.c,v 1.27 2021/03/18 12:37:51 nia Exp $");
+__KERNEL_RCSID(0, "$NetBSD: subr_time.c,v 1.28 2021/03/18 13:45:15 nia Exp $");
 
 #include 
 #include 
@@ -327,11 +327,15 @@ ts2timo(clockid_t clock_id, int flags, s
 int *timo, struct timespec *start)
 {
 	int error;
+	struct timespec tsd;
 
 	if (ts->tv_nsec < 0 || ts->tv_nsec >= 10L)
 		return EINVAL;
 
-	if (flags != TIMER_RELTIME || start != NULL) {
+	if (start == NULL)
+		start = 
+
+	if (flags != TIMER_RELTIME || start != ) {
 		error = clock_gettime1(clock_id, start);
 		if (error != 0)
 			return error;



CVS commit: src/sys/kern

2021-03-18 Thread Nia Alarie
Module Name:src
Committed By:   nia
Date:   Thu Mar 18 12:37:51 UTC 2021

Modified Files:
src/sys/kern: subr_time.c

Log Message:
ts2timo(9): further deobfuscation.

we want to check against NULL, so use it, rather than some random value on
the stack


To generate a diff of this commit:
cvs rdiff -u -r1.26 -r1.27 src/sys/kern/subr_time.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/kern/subr_time.c
diff -u src/sys/kern/subr_time.c:1.26 src/sys/kern/subr_time.c:1.27
--- src/sys/kern/subr_time.c:1.26	Thu Mar 18 11:53:16 2021
+++ src/sys/kern/subr_time.c	Thu Mar 18 12:37:51 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: subr_time.c,v 1.26 2021/03/18 11:53:16 nia Exp $	*/
+/*	$NetBSD: subr_time.c,v 1.27 2021/03/18 12:37:51 nia Exp $	*/
 
 /*
  * Copyright (c) 1982, 1986, 1989, 1993
@@ -33,7 +33,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: subr_time.c,v 1.26 2021/03/18 11:53:16 nia Exp $");
+__KERNEL_RCSID(0, "$NetBSD: subr_time.c,v 1.27 2021/03/18 12:37:51 nia Exp $");
 
 #include 
 #include 
@@ -327,15 +327,11 @@ ts2timo(clockid_t clock_id, int flags, s
 int *timo, struct timespec *start)
 {
 	int error;
-	struct timespec tsd;
 
 	if (ts->tv_nsec < 0 || ts->tv_nsec >= 10L)
 		return EINVAL;
 
-	if (start == NULL)
-		start = 
-
-	if (flags != TIMER_RELTIME || start != ) {
+	if (flags != TIMER_RELTIME || start != NULL) {
 		error = clock_gettime1(clock_id, start);
 		if (error != 0)
 			return error;



CVS commit: src/sys/kern

2021-03-18 Thread Nia Alarie
Module Name:src
Committed By:   nia
Date:   Thu Mar 18 11:53:16 UTC 2021

Modified Files:
src/sys/kern: subr_time.c

Log Message:
ts2timo(9): refactor for clarity

- 'flags' is not a boolean...
- actually, it is, but it should simply be named "absolute".
- convert tests for if (flags) to if (flags != TIMER_RELTIME)
- hoist function calls out of if expressions (requested by uwe)

still needs fixing:

- need to check for overflow before timespecsub.


To generate a diff of this commit:
cvs rdiff -u -r1.25 -r1.26 src/sys/kern/subr_time.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/kern/subr_time.c
diff -u src/sys/kern/subr_time.c:1.25 src/sys/kern/subr_time.c:1.26
--- src/sys/kern/subr_time.c:1.25	Sat May 23 23:42:43 2020
+++ src/sys/kern/subr_time.c	Thu Mar 18 11:53:16 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: subr_time.c,v 1.25 2020/05/23 23:42:43 ad Exp $	*/
+/*	$NetBSD: subr_time.c,v 1.26 2021/03/18 11:53:16 nia Exp $	*/
 
 /*
  * Copyright (c) 1982, 1986, 1989, 1993
@@ -33,7 +33,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: subr_time.c,v 1.25 2020/05/23 23:42:43 ad Exp $");
+__KERNEL_RCSID(0, "$NetBSD: subr_time.c,v 1.26 2021/03/18 11:53:16 nia Exp $");
 
 #include 
 #include 
@@ -332,18 +332,20 @@ ts2timo(clockid_t clock_id, int flags, s
 	if (ts->tv_nsec < 0 || ts->tv_nsec >= 10L)
 		return EINVAL;
 
-	flags &= TIMER_ABSTIME;
 	if (start == NULL)
 		start = 
 
-	if (flags || start != )
-		if ((error = clock_gettime1(clock_id, start)) != 0)
+	if (flags != TIMER_RELTIME || start != ) {
+		error = clock_gettime1(clock_id, start);
+		if (error != 0)
 			return error;
+	}
 
-	if (flags)
+	if (flags != TIMER_RELTIME)
 		timespecsub(ts, start, ts);
 
-	if ((error = itimespecfix(ts)) != 0)
+	error = itimespecfix(ts);
+	if (error != 0)
 		return error;
 
 	if (ts->tv_sec == 0 && ts->tv_nsec == 0)