Module Name:    src
Committed By:   rillig
Date:           Mon Jun 28 10:07:43 UTC 2021

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

Log Message:
lint: turn null pointer dereference into assertion failure

Originally I only needed a message that would output the type name from
an abstract-declarator (C99 6.7.6), to see whether lint interprets the
types correctly.

Message 155 looked like a good candidate, but it only revealed more
incomplete and untested code in lint.


To generate a diff of this commit:
cvs rdiff -u -r1.2 -r1.3 src/tests/usr.bin/xlint/lint1/msg_155.c \
    src/tests/usr.bin/xlint/lint1/msg_155.exp
cvs rdiff -u -r1.191 -r1.192 src/usr.bin/xlint/lint1/decl.c

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

Modified files:

Index: src/tests/usr.bin/xlint/lint1/msg_155.c
diff -u src/tests/usr.bin/xlint/lint1/msg_155.c:1.2 src/tests/usr.bin/xlint/lint1/msg_155.c:1.3
--- src/tests/usr.bin/xlint/lint1/msg_155.c:1.2	Sun Feb 21 09:07:58 2021
+++ src/tests/usr.bin/xlint/lint1/msg_155.c	Mon Jun 28 10:07:43 2021
@@ -1,7 +1,47 @@
-/*	$NetBSD: msg_155.c,v 1.2 2021/02/21 09:07:58 rillig Exp $	*/
+/*	$NetBSD: msg_155.c,v 1.3 2021/06/28 10:07:43 rillig Exp $	*/
 # 3 "msg_155.c"
 
 // Test for message: argument is incompatible with prototype, arg #%d [155]
+// TODO: Add type information to the message
 
-TODO: "Add example code that triggers the above message." /* expect: 249 */
-TODO: "Add example code that almost triggers the above message."
+void c99_6_7_6_example_a(int);
+void c99_6_7_6_example_b(int *);
+void c99_6_7_6_example_c(int *[3]);
+void c99_6_7_6_example_d(int (*)[3]);
+void c99_6_7_6_example_e(int (*)[*]);	/* expect: syntax error ']' *//* FIXME */
+// FIXME: assertion "sym->s_type != NULL" failed in declare_argument at decl.c:2436
+// void c99_6_7_6_example_f(int *());
+void c99_6_7_6_example_g(int (*)(void));
+void c99_6_7_6_example_h(int (*const[])(unsigned int, ...));
+
+struct incompatible {
+	int member;
+};
+
+void
+provoke_error_messages(struct incompatible arg)
+{
+	/* expect+1: argument is incompatible with prototype, arg #1 */
+	c99_6_7_6_example_a(arg);
+
+	/* expect+1: argument is incompatible with prototype, arg #1 */
+	c99_6_7_6_example_b(arg);
+
+	/* expect+1: argument is incompatible with prototype, arg #1 */
+	c99_6_7_6_example_c(arg);
+
+	/* expect+1: argument is incompatible with prototype, arg #1 */
+	c99_6_7_6_example_d(arg);
+
+	/* FIXME: no warning or error at all for an undefined function? */
+	c99_6_7_6_example_e(arg);
+
+	/* FIXME: no warning or error at all for an undefined function? */
+	c99_6_7_6_example_f(arg);
+
+	/* expect+1: argument is incompatible with prototype, arg #1 */
+	c99_6_7_6_example_g(arg);
+
+	/* expect+1: argument is incompatible with prototype, arg #1 */
+	c99_6_7_6_example_h(arg);
+}
Index: src/tests/usr.bin/xlint/lint1/msg_155.exp
diff -u src/tests/usr.bin/xlint/lint1/msg_155.exp:1.2 src/tests/usr.bin/xlint/lint1/msg_155.exp:1.3
--- src/tests/usr.bin/xlint/lint1/msg_155.exp:1.2	Sun Mar 21 20:45:00 2021
+++ src/tests/usr.bin/xlint/lint1/msg_155.exp	Mon Jun 28 10:07:43 2021
@@ -1 +1,7 @@
-msg_155.c(6): error: syntax error ':' [249]
+msg_155.c(11): error: syntax error ']' [249]
+msg_155.c(25): warning: argument is incompatible with prototype, arg #1 [155]
+msg_155.c(28): warning: argument is incompatible with prototype, arg #1 [155]
+msg_155.c(31): warning: argument is incompatible with prototype, arg #1 [155]
+msg_155.c(34): warning: argument is incompatible with prototype, arg #1 [155]
+msg_155.c(43): warning: argument is incompatible with prototype, arg #1 [155]
+msg_155.c(46): warning: argument is incompatible with prototype, arg #1 [155]

Index: src/usr.bin/xlint/lint1/decl.c
diff -u src/usr.bin/xlint/lint1/decl.c:1.191 src/usr.bin/xlint/lint1/decl.c:1.192
--- src/usr.bin/xlint/lint1/decl.c:1.191	Mon Jun 28 09:14:42 2021
+++ src/usr.bin/xlint/lint1/decl.c	Mon Jun 28 10:07:43 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: decl.c,v 1.191 2021/06/28 09:14:42 rillig Exp $ */
+/* $NetBSD: decl.c,v 1.192 2021/06/28 10:07:43 rillig Exp $ */
 
 /*
  * Copyright (c) 1996 Christopher G. Demetriou.  All Rights Reserved.
@@ -38,7 +38,7 @@
 
 #include <sys/cdefs.h>
 #if defined(__RCSID) && !defined(lint)
-__RCSID("$NetBSD: decl.c,v 1.191 2021/06/28 09:14:42 rillig Exp $");
+__RCSID("$NetBSD: decl.c,v 1.192 2021/06/28 10:07:43 rillig Exp $");
 #endif
 
 #include <sys/param.h>
@@ -2433,6 +2433,7 @@ declare_argument(sym_t *sym, bool initfl
 		error(52, sym->s_name);
 	}
 
+	lint_assert(sym->s_type != NULL);
 	if ((t = sym->s_type->t_tspec) == ARRAY) {
 		sym->s_type = derive_type(sym->s_type->t_subt, PTR);
 	} else if (t == FUNC) {

Reply via email to