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.
This commit is contained in:
rillig 2021-06-28 10:07:43 +00:00
parent 72ed3a7a7b
commit 3ce5ae23e6
3 changed files with 53 additions and 6 deletions

View File

@ -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);
}

View File

@ -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]

View File

@ -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 initflg)
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) {