Module Name:    src
Committed By:   rillig
Date:           Fri Jan  1 01:07:08 UTC 2021

Modified Files:
        src/distrib/sets/lists/tests: mi
        src/tests/usr.bin/xlint/lint1: Makefile t_integration.sh
        src/usr.bin/xlint/lint1: tree.c
Added Files:
        src/tests/usr.bin/xlint/lint1: d_return_type.c d_return_type.exp

Log Message:
lint: fix segmentation fault when checking returned enum types (211)


To generate a diff of this commit:
cvs rdiff -u -r1.1004 -r1.1005 src/distrib/sets/lists/tests/mi
cvs rdiff -u -r1.22 -r1.23 src/tests/usr.bin/xlint/lint1/Makefile
cvs rdiff -u -r0 -r1.1 src/tests/usr.bin/xlint/lint1/d_return_type.c \
    src/tests/usr.bin/xlint/lint1/d_return_type.exp
cvs rdiff -u -r1.15 -r1.16 src/tests/usr.bin/xlint/lint1/t_integration.sh
cvs rdiff -u -r1.108 -r1.109 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/distrib/sets/lists/tests/mi
diff -u src/distrib/sets/lists/tests/mi:1.1004 src/distrib/sets/lists/tests/mi:1.1005
--- src/distrib/sets/lists/tests/mi:1.1004	Thu Dec 31 18:51:28 2020
+++ src/distrib/sets/lists/tests/mi	Fri Jan  1 01:07:07 2021
@@ -1,4 +1,4 @@
-# $NetBSD: mi,v 1.1004 2020/12/31 18:51:28 rillig Exp $
+# $NetBSD: mi,v 1.1005 2021/01/01 01:07:07 rillig Exp $
 #
 # Note: don't delete entries from here - mark them as "obsolete" instead.
 #
@@ -5798,6 +5798,8 @@
 ./usr/tests/usr.bin/xlint/lint1/d_nested_structs.c		tests-usr.bin-tests	compattestfile,atf
 ./usr/tests/usr.bin/xlint/lint1/d_nolimit_init.c		tests-usr.bin-tests	compattestfile,atf
 ./usr/tests/usr.bin/xlint/lint1/d_packed_structs.c		tests-usr.bin-tests	compattestfile,atf
+./usr/tests/usr.bin/xlint/lint1/d_return_type.c			tests-usr.bin-tests	compattestfile,atf
+./usr/tests/usr.bin/xlint/lint1/d_return_type.exp		tests-usr.bin-tests	compattestfile,atf
 ./usr/tests/usr.bin/xlint/lint1/d_shift_to_narrower_type.c	tests-usr.bin-tests	compattestfile,atf
 ./usr/tests/usr.bin/xlint/lint1/d_struct_init_nested.c		tests-usr.bin-tests	compattestfile,atf
 ./usr/tests/usr.bin/xlint/lint1/d_struct_init_nested.exp	tests-usr.bin-tests	compattestfile,atf

Index: src/tests/usr.bin/xlint/lint1/Makefile
diff -u src/tests/usr.bin/xlint/lint1/Makefile:1.22 src/tests/usr.bin/xlint/lint1/Makefile:1.23
--- src/tests/usr.bin/xlint/lint1/Makefile:1.22	Thu Dec 31 18:51:28 2020
+++ src/tests/usr.bin/xlint/lint1/Makefile	Fri Jan  1 01:07:08 2021
@@ -1,4 +1,4 @@
-# $NetBSD: Makefile,v 1.22 2020/12/31 18:51:28 rillig Exp $
+# $NetBSD: Makefile,v 1.23 2021/01/01 01:07:08 rillig Exp $
 
 NOMAN=		# defined
 
@@ -66,6 +66,8 @@ FILES+=		d_long_double_int.exp
 FILES+=		d_nested_structs.c
 FILES+=		d_nolimit_init.c
 FILES+=		d_packed_structs.c
+FILES+=		d_return_type.c
+FILES+=		d_return_type.exp
 FILES+=		d_shift_to_narrower_type.c
 FILES+=		d_struct_init_nested.c
 FILES+=		d_struct_init_nested.exp

Index: src/tests/usr.bin/xlint/lint1/t_integration.sh
diff -u src/tests/usr.bin/xlint/lint1/t_integration.sh:1.15 src/tests/usr.bin/xlint/lint1/t_integration.sh:1.16
--- src/tests/usr.bin/xlint/lint1/t_integration.sh:1.15	Thu Dec 31 18:51:28 2020
+++ src/tests/usr.bin/xlint/lint1/t_integration.sh	Fri Jan  1 01:07:08 2021
@@ -1,4 +1,4 @@
-# $NetBSD: t_integration.sh,v 1.15 2020/12/31 18:51:28 rillig Exp $
+# $NetBSD: t_integration.sh,v 1.16 2021/01/01 01:07:08 rillig Exp $
 #
 # Copyright (c) 2008, 2010 The NetBSD Foundation, Inc.
 # All rights reserved.
@@ -76,6 +76,7 @@ test_case cast_typeof
 test_case decl_old_style_arguments
 test_case fold_test
 test_case gcc_extension
+test_case return_type
 test_case type_question_colon
 test_case typefun
 test_case typename_as_var

Index: src/usr.bin/xlint/lint1/tree.c
diff -u src/usr.bin/xlint/lint1/tree.c:1.108 src/usr.bin/xlint/lint1/tree.c:1.109
--- src/usr.bin/xlint/lint1/tree.c:1.108	Fri Jan  1 00:00:24 2021
+++ src/usr.bin/xlint/lint1/tree.c	Fri Jan  1 01:07:08 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: tree.c,v 1.108 2021/01/01 00:00:24 rillig Exp $	*/
+/*	$NetBSD: tree.c,v 1.109 2021/01/01 01:07:08 rillig Exp $	*/
 
 /*
  * Copyright (c) 1994, 1995 Jochen Pohl
@@ -37,7 +37,7 @@
 
 #include <sys/cdefs.h>
 #if defined(__RCSID) && !defined(lint)
-__RCSID("$NetBSD: tree.c,v 1.108 2021/01/01 00:00:24 rillig Exp $");
+__RCSID("$NetBSD: tree.c,v 1.109 2021/01/01 01:07:08 rillig Exp $");
 #endif
 
 #include <float.h>
@@ -1369,6 +1369,7 @@ static void
 check_enum_type_mismatch(op_t op, int arg, tnode_t *ln, tnode_t *rn)
 {
 	mod_t	*mp;
+	char lbuf[128], rbuf[128];
 
 	mp = &modtab[op];
 
@@ -1384,7 +1385,8 @@ check_enum_type_mismatch(op_t op, int ar
 			break;
 		case RETURN:
 			/* return value type mismatch (%s) and (%s) */
-			warning(211);
+			warning(211, tyname(lbuf, sizeof(lbuf), ln->tn_type),
+			    tyname(rbuf, sizeof(rbuf), rn->tn_type));
 			break;
 		default:
 			/* enum type mismatch, op %s */

Added files:

Index: src/tests/usr.bin/xlint/lint1/d_return_type.c
diff -u /dev/null src/tests/usr.bin/xlint/lint1/d_return_type.c:1.1
--- /dev/null	Fri Jan  1 01:07:08 2021
+++ src/tests/usr.bin/xlint/lint1/d_return_type.c	Fri Jan  1 01:07:08 2021
@@ -0,0 +1,15 @@
+# 2
+
+enum A {
+	A
+};
+
+enum B {
+	B
+};
+
+enum A
+func(enum B arg)
+{
+	return arg;
+}
Index: src/tests/usr.bin/xlint/lint1/d_return_type.exp
diff -u /dev/null src/tests/usr.bin/xlint/lint1/d_return_type.exp:1.1
--- /dev/null	Fri Jan  1 01:07:08 2021
+++ src/tests/usr.bin/xlint/lint1/d_return_type.exp	Fri Jan  1 01:07:08 2021
@@ -0,0 +1 @@
+(14): warning: return value type mismatch (enum A) and (enum B) [211]

Reply via email to