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: fix segmentation fault when checki...



details:   https://anonhg.NetBSD.org/src/rev/d232f9a83db2
branches:  trunk
changeset: 948788:d232f9a83db2
user:      rillig <rillig%NetBSD.org@localhost>
date:      Fri Jan 01 01:07:07 2021 +0000

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

diffstat:

 distrib/sets/lists/tests/mi                 |   4 +++-
 tests/usr.bin/xlint/lint1/Makefile          |   4 +++-
 tests/usr.bin/xlint/lint1/d_return_type.c   |  15 +++++++++++++++
 tests/usr.bin/xlint/lint1/d_return_type.exp |   1 +
 tests/usr.bin/xlint/lint1/t_integration.sh  |   3 ++-
 usr.bin/xlint/lint1/tree.c                  |   8 +++++---
 6 files changed, 29 insertions(+), 6 deletions(-)

diffs (113 lines):

diff -r 59fd30016277 -r d232f9a83db2 distrib/sets/lists/tests/mi
--- a/distrib/sets/lists/tests/mi       Fri Jan 01 00:00:24 2021 +0000
+++ b/distrib/sets/lists/tests/mi       Fri Jan 01 01:07:07 2021 +0000
@@ -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
diff -r 59fd30016277 -r d232f9a83db2 tests/usr.bin/xlint/lint1/Makefile
--- a/tests/usr.bin/xlint/lint1/Makefile        Fri Jan 01 00:00:24 2021 +0000
+++ b/tests/usr.bin/xlint/lint1/Makefile        Fri Jan 01 01:07:07 2021 +0000
@@ -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_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
diff -r 59fd30016277 -r d232f9a83db2 tests/usr.bin/xlint/lint1/d_return_type.c
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/usr.bin/xlint/lint1/d_return_type.c Fri Jan 01 01:07:07 2021 +0000
@@ -0,0 +1,15 @@
+# 2
+
+enum A {
+       A
+};
+
+enum B {
+       B
+};
+
+enum A
+func(enum B arg)
+{
+       return arg;
+}
diff -r 59fd30016277 -r d232f9a83db2 tests/usr.bin/xlint/lint1/d_return_type.exp
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/usr.bin/xlint/lint1/d_return_type.exp       Fri Jan 01 01:07:07 2021 +0000
@@ -0,0 +1,1 @@
+(14): warning: return value type mismatch (enum A) and (enum B) [211]
diff -r 59fd30016277 -r d232f9a83db2 tests/usr.bin/xlint/lint1/t_integration.sh
--- a/tests/usr.bin/xlint/lint1/t_integration.sh        Fri Jan 01 00:00:24 2021 +0000
+++ b/tests/usr.bin/xlint/lint1/t_integration.sh        Fri Jan 01 01:07:07 2021 +0000
@@ -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 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
diff -r 59fd30016277 -r d232f9a83db2 usr.bin/xlint/lint1/tree.c
--- a/usr.bin/xlint/lint1/tree.c        Fri Jan 01 00:00:24 2021 +0000
+++ b/usr.bin/xlint/lint1/tree.c        Fri Jan 01 01:07:07 2021 +0000
@@ -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 @@
 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 @@
                        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 */



Home | Main Index | Thread Index | Old Index