diff options
| author | rillig <rillig@NetBSD.org> | 2023-06-30 08:45:22 +0000 |
|---|---|---|
| committer | rillig <rillig@NetBSD.org> | 2023-06-30 08:45:22 +0000 |
| commit | 4648fa324118d00e3e517238e35bad12241b3e53 (patch) | |
| tree | e37ebba1d9400d437d77f8059ba3ccbb5cc99f6d | |
| parent | ee47fe31e7ca4755fed8e26228522a93f3e59333 (diff) | |
lint: add query for assigning an integer 0 to a pointer
| -rw-r--r-- | tests/usr.bin/xlint/lint1/queries.c | 22 | ||||
| -rw-r--r-- | tests/usr.bin/xlint/lint1/t_usage.sh | 8 | ||||
| -rw-r--r-- | usr.bin/xlint/lint1/err.c | 5 | ||||
| -rw-r--r-- | usr.bin/xlint/lint1/tree.c | 10 |
4 files changed, 34 insertions, 11 deletions
diff --git a/tests/usr.bin/xlint/lint1/queries.c b/tests/usr.bin/xlint/lint1/queries.c index 4f3a609b082..767a4afc27b 100644 --- a/tests/usr.bin/xlint/lint1/queries.c +++ b/tests/usr.bin/xlint/lint1/queries.c @@ -1,4 +1,4 @@ -/* $NetBSD: queries.c,v 1.17 2023/06/24 08:11:12 rillig Exp $ */ +/* $NetBSD: queries.c,v 1.18 2023/06/30 08:45:22 rillig Exp $ */ # 3 "queries.c" /* @@ -15,7 +15,7 @@ * such as casts between arithmetic types. */ -/* lint1-extra-flags: -q 1,2,3,4,5,6,7,8,9,10,11,12,13,14 -X 351 */ +/* lint1-extra-flags: -q 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15 -X 351 */ typedef unsigned char u8_t; typedef unsigned short u16_t; @@ -423,6 +423,24 @@ Q14(char c, signed char sc, unsigned char uc, int wc) return 5; } +void * +Q15(void) +{ + /* expect+1: implicit conversion from integer 0 to pointer 'pointer to void' [Q15] */ + void *ptr_from_int = 0; + /* expect+1: implicit conversion from integer 0 to pointer 'pointer to void' [Q15] */ + void *ptr_from_uint = 0U; + /* expect+1: implicit conversion from integer 0 to pointer 'pointer to void' [Q15] */ + void *ptr_from_long = 0L; + + ptr_from_int = &ptr_from_int; + ptr_from_uint = &ptr_from_uint; + ptr_from_long = &ptr_from_long; + + /* expect+1: implicit conversion from integer 0 to pointer 'pointer to void' [Q15] */ + return 0; +} + /* * Since queries do not affect the exit status, force a warning to make this * test conform to the general expectation that a test that produces output diff --git a/tests/usr.bin/xlint/lint1/t_usage.sh b/tests/usr.bin/xlint/lint1/t_usage.sh index 597c9c7b7b3..873d950eed8 100644 --- a/tests/usr.bin/xlint/lint1/t_usage.sh +++ b/tests/usr.bin/xlint/lint1/t_usage.sh @@ -1,4 +1,4 @@ -# $NetBSD: t_usage.sh,v 1.8 2023/06/28 09:35:42 rillig Exp $ +# $NetBSD: t_usage.sh,v 1.9 2023/06/30 08:45:22 rillig Exp $ # # Copyright (c) 2023 The NetBSD Foundation, Inc. # All rights reserved. @@ -89,13 +89,13 @@ enable_queries_body() # The largest known query. atf_check \ - "$lint1" -q 14 code.c /dev/null + "$lint1" -q 15 code.c /dev/null # Larger than the largest known query. atf_check \ -s 'exit:1' \ - -e "inline:lint1: invalid query ID '15'\n" \ - "$lint1" -q 15 code.c /dev/null + -e "inline:lint1: invalid query ID '16'\n" \ + "$lint1" -q 16 code.c /dev/null # Whitespace is not allowed before a query ID. atf_check \ diff --git a/usr.bin/xlint/lint1/err.c b/usr.bin/xlint/lint1/err.c index d5da0ec3cac..21786a21d2b 100644 --- a/usr.bin/xlint/lint1/err.c +++ b/usr.bin/xlint/lint1/err.c @@ -1,4 +1,4 @@ -/* $NetBSD: err.c,v 1.202 2023/06/24 08:11:12 rillig Exp $ */ +/* $NetBSD: err.c,v 1.203 2023/06/30 08:45:22 rillig Exp $ */ /* * Copyright (c) 1994, 1995 Jochen Pohl @@ -37,7 +37,7 @@ #include <sys/cdefs.h> #if defined(__RCSID) -__RCSID("$NetBSD: err.c,v 1.202 2023/06/24 08:11:12 rillig Exp $"); +__RCSID("$NetBSD: err.c,v 1.203 2023/06/30 08:45:22 rillig Exp $"); #endif #include <limits.h> @@ -710,6 +710,7 @@ static const char *queries[] = { "comma operator with types '%s' and '%s'", /* Q12 */ "redundant 'extern' in function declaration of '%s'", /* Q13 */ "comparison '%s' of 'char' with plain integer %d", /* Q14 */ + "implicit conversion from integer 0 to pointer '%s'", /* Q15 */ }; bool any_query_enabled; /* for optimizing non-query scenarios */ diff --git a/usr.bin/xlint/lint1/tree.c b/usr.bin/xlint/lint1/tree.c index 9c5689d33c3..9fc049c38e3 100644 --- a/usr.bin/xlint/lint1/tree.c +++ b/usr.bin/xlint/lint1/tree.c @@ -1,4 +1,4 @@ -/* $NetBSD: tree.c,v 1.532 2023/06/29 12:52:06 rillig Exp $ */ +/* $NetBSD: tree.c,v 1.533 2023/06/30 08:45:22 rillig Exp $ */ /* * Copyright (c) 1994, 1995 Jochen Pohl @@ -37,7 +37,7 @@ #include <sys/cdefs.h> #if defined(__RCSID) -__RCSID("$NetBSD: tree.c,v 1.532 2023/06/29 12:52:06 rillig Exp $"); +__RCSID("$NetBSD: tree.c,v 1.533 2023/06/30 08:45:22 rillig Exp $"); #endif #include <float.h> @@ -2912,8 +2912,12 @@ check_assign_types_compatible(op_t op, int arg, return ltp->t_sou == rtp->t_sou; /* a null pointer may be assigned to any pointer */ - if (lt == PTR && is_null_pointer(rn)) + if (lt == PTR && is_null_pointer(rn)) { + if (is_integer(rn->tn_type->t_tspec)) + /* implicit conversion from integer 0 to pointer ... */ + query_message(15, type_name(ltp)); return true; + } check_assign_void_pointer(op, arg, lt, lst, rt, rst); |
