Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/usr.bin/xlint/lint1 lint: turn null pointer dereference into...
details: https://anonhg.NetBSD.org/src/rev/9e285c36e8a7
branches: trunk
changeset: 379947:9e285c36e8a7
user: rillig <rillig%NetBSD.org@localhost>
date: Mon Jun 28 10:07:43 2021 +0000
description:
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.
diffstat:
tests/usr.bin/xlint/lint1/msg_155.c | 46 ++++++++++++++++++++++++++++++++--
tests/usr.bin/xlint/lint1/msg_155.exp | 8 +++++-
usr.bin/xlint/lint1/decl.c | 5 ++-
3 files changed, 53 insertions(+), 6 deletions(-)
diffs (92 lines):
diff -r f34c83b4cf07 -r 9e285c36e8a7 tests/usr.bin/xlint/lint1/msg_155.c
--- a/tests/usr.bin/xlint/lint1/msg_155.c Mon Jun 28 09:40:52 2021 +0000
+++ b/tests/usr.bin/xlint/lint1/msg_155.c Mon Jun 28 10:07:43 2021 +0000
@@ -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);
+}
diff -r f34c83b4cf07 -r 9e285c36e8a7 tests/usr.bin/xlint/lint1/msg_155.exp
--- a/tests/usr.bin/xlint/lint1/msg_155.exp Mon Jun 28 09:40:52 2021 +0000
+++ b/tests/usr.bin/xlint/lint1/msg_155.exp Mon Jun 28 10:07:43 2021 +0000
@@ -1,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]
diff -r f34c83b4cf07 -r 9e285c36e8a7 usr.bin/xlint/lint1/decl.c
--- a/usr.bin/xlint/lint1/decl.c Mon Jun 28 09:40:52 2021 +0000
+++ b/usr.bin/xlint/lint1/decl.c Mon Jun 28 10:07:43 2021 +0000
@@ -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) {
Home |
Main Index |
Thread Index |
Old Index