Module Name:    src
Committed By:   rillig
Date:           Sun Jan 15 21:46:15 UTC 2023

Modified Files:
        src/usr.bin/xlint/xlint: xlint.c

Log Message:
lint: reduce number of local variables in lbasename

No functional change.


To generate a diff of this commit:
cvs rdiff -u -r1.100 -r1.101 src/usr.bin/xlint/xlint/xlint.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/xlint/xlint.c
diff -u src/usr.bin/xlint/xlint/xlint.c:1.100 src/usr.bin/xlint/xlint/xlint.c:1.101
--- src/usr.bin/xlint/xlint/xlint.c:1.100	Sun Jan 15 21:27:36 2023
+++ src/usr.bin/xlint/xlint/xlint.c	Sun Jan 15 21:46:15 2023
@@ -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 @@ concat2(const char *s1, const char *s2)
 	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 @@ terminate(int signo)
 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)))

Reply via email to