Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/usr.bin/xlint/lint2 lint: remove redundant call to strchr in...



details:   https://anonhg.NetBSD.org/src/rev/765f91873f2e
branches:  trunk
changeset: 1023248:765f91873f2e
user:      rillig <rillig%NetBSD.org@localhost>
date:      Mon Aug 30 20:20:20 2021 +0000

description:
lint: remove redundant call to strchr in decldef

This time, the branches for varargs, printflike and scanflike in the big
switch statement are covered by unit tests.  These tests would have
caught the previous "cleanup" that broke parsing of these function
attributes.  Furthermore, this second cleanup is closer to the original
code and conceptually simpler since it avoids having many 'continue'
statements in a 'switch' statement, which would have been unusual.

The branches for inline functions and used functions are still not
covered by the tests, but they are structurally equal to several other
branches.

No functional change.

diffstat:

 usr.bin/xlint/lint2/read.c |  13 ++++++++-----
 1 files changed, 8 insertions(+), 5 deletions(-)

diffs (44 lines):

diff -r 28cb403f70a6 -r 765f91873f2e usr.bin/xlint/lint2/read.c
--- a/usr.bin/xlint/lint2/read.c        Mon Aug 30 20:11:56 2021 +0000
+++ b/usr.bin/xlint/lint2/read.c        Mon Aug 30 20:20:20 2021 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: read.c,v 1.61 2021/08/30 19:07:57 rillig Exp $ */
+/* $NetBSD: read.c,v 1.62 2021/08/30 20:20:20 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: read.c,v 1.61 2021/08/30 19:07:57 rillig Exp $");
+__RCSID("$NetBSD: read.c,v 1.62 2021/08/30 20:20:20 rillig Exp $");
 #endif
 
 #include <ctype.h>
@@ -387,9 +387,8 @@
 
        used = false;
 
-       while (strchr("deiorstuvPS", (c = *cp)) != NULL) {
-               cp++;
-               switch (c) {
+       for (;;) {
+               switch (c = *cp++) {
                case 'd':
                        if (sym.s_def != NODECL)
                                inperr("def");
@@ -448,9 +447,13 @@
                        sym.s_scanflike = true;
                        sym.s_scanflike_arg = parse_short(&cp);
                        break;
+               default:
+                       cp--;
+                       goto done_function_attributes;
                }
        }
 
+done_function_attributes:
        /* read symbol name, doing renaming if necessary */
        name = inpname(cp, &cp);
        renamed = false;



Home | Main Index | Thread Index | Old Index