Source-Changes-HG archive

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

[src/trunk]: src/usr.bin/xlint/xlint lint: reduce number of local variables i...



details:   https://anonhg.NetBSD.org/src/rev/b73ead082f26
branches:  trunk
changeset: 373068:b73ead082f26
user:      rillig <rillig%NetBSD.org@localhost>
date:      Sun Jan 15 21:46:15 2023 +0000

description:
lint: reduce number of local variables in lbasename

No functional change.

diffstat:

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

diffs (51 lines):

diff -r 971431766c6a -r b73ead082f26 usr.bin/xlint/xlint/xlint.c
--- a/usr.bin/xlint/xlint/xlint.c       Sun Jan 15 21:27:36 2023 +0000
+++ b/usr.bin/xlint/xlint/xlint.c       Sun Jan 15 21:46:15 2023 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: xlint.c,v 1.100 2023/01/15 21:27:36 rillig Exp $ */
+/* $NetBSD: xlint.c,v 1.101 2023/01/15 21:46:15 rillig Exp $ */
 
 /*
  * Copyright (c) 1996 Christopher G. Demetriou.  All Rights Reserved.
@@ -38,7 +38,7 @@
 
 #include <sys/cdefs.h>
 #if defined(__RCSID)
-__RCSID("$NetBSD: xlint.c,v 1.100 2023/01/15 21:27:36 rillig Exp $");
+__RCSID("$NetBSD: xlint.c,v 1.101 2023/01/15 21:46:15 rillig Exp $");
 #endif
 
 #include <sys/param.h>
@@ -226,9 +226,7 @@
        return s;
 }
 
-/*
- * Clean up after a signal.
- */
+/* Clean up after a signal or at the regular end. */
 static void __attribute__((__noreturn__))
 terminate(int signo)
 {
@@ -264,16 +262,13 @@
 static const char *
 lbasename(const char *strg, int delim)
 {
-       const   char *cp, *cp1, *cp2;
 
-       cp = cp1 = cp2 = strg;
-       while (*cp != '\0') {
-               if (*cp++ == delim) {
-                       cp2 = cp1;
-                       cp1 = cp;
-               }
+       const char *base = strg;
+       for (const char *p = strg; *p != '\0'; p++) {
+               if (p[0] == delim && p[1] != '\0')
+                       base = p + 1;
        }
-       return *cp1 == '\0' ? cp2 : cp1;
+       return base;
 }
 
 static void __attribute__((__noreturn__, __format__(__printf__, 1, 2)))



Home | Main Index | Thread Index | Old Index