Module Name: src Committed By: rillig Date: Wed Jun 30 11:29:29 UTC 2021
Modified Files: src/usr.bin/xlint/lint1: func.c Log Message: lint: invert condition in control flow analysis of switch statements The condition previously contained many negations, which was hard to understand. No functional change. To generate a diff of this commit: cvs rdiff -u -r1.111 -r1.112 src/usr.bin/xlint/lint1/func.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/usr.bin/xlint/lint1/func.c diff -u src/usr.bin/xlint/lint1/func.c:1.111 src/usr.bin/xlint/lint1/func.c:1.112 --- src/usr.bin/xlint/lint1/func.c:1.111 Sat Jun 19 19:59:02 2021 +++ src/usr.bin/xlint/lint1/func.c Wed Jun 30 11:29:29 2021 @@ -1,4 +1,4 @@ -/* $NetBSD: func.c,v 1.111 2021/06/19 19:59:02 rillig Exp $ */ +/* $NetBSD: func.c,v 1.112 2021/06/30 11:29:29 rillig Exp $ */ /* * Copyright (c) 1994, 1995 Jochen Pohl @@ -37,7 +37,7 @@ #include <sys/cdefs.h> #if defined(__RCSID) && !defined(lint) -__RCSID("$NetBSD: func.c,v 1.111 2021/06/19 19:59:02 rillig Exp $"); +__RCSID("$NetBSD: func.c,v 1.112 2021/06/30 11:29:29 rillig Exp $"); #endif #include <stdlib.h> @@ -747,12 +747,11 @@ switch2(void) lint_assert(cstmt->c_switch_type != NULL); - /* - * If the switch expression was of type enumeration, count the case - * labels and the number of enumerators. If both counts are not - * equal print a warning. - */ if (cstmt->c_switch_type->t_is_enum) { + /* + * Warn if the number of case labels is different from the + * number of enumerators. + */ nenum = nclab = 0; lint_assert(cstmt->c_switch_type->t_enum != NULL); for (esym = cstmt->c_switch_type->t_enum->en_first_enumerator; @@ -771,22 +770,25 @@ switch2(void) if (cstmt->c_break) { /* - * end of switch always reached (c_break is only set if the - * break statement can be reached). + * The end of the switch statement is always reached since + * c_break is only set if a break statement can actually + * be reached. */ set_reached(true); - } else if (!cstmt->c_default && - (!hflag || !cstmt->c_switch_type->t_is_enum || - nenum != nclab)) { + } else if (cstmt->c_default || + (hflag && cstmt->c_switch_type->t_is_enum && + nenum == nclab)) { /* - * there are possible values which are not handled in - * switch + * The end of the switch statement is reached if the end + * of the last statement inside it is reached. */ - set_reached(true); - } /* - * otherwise the end of the switch expression is reached - * if the end of the last statement inside it is reached. + } else { + /* + * There are possible values that are not handled in the + * switch statement. */ + set_reached(true); + } end_control_statement(CS_SWITCH); }