Module Name:    src
Committed By:   lukem
Date:           Mon May 14 05:17:11 UTC 2018

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

Log Message:
locate: fix support for multiple databases

Ensure that the first database is correctly added when
more than one database is provided.

Fixes problem I introduced in rev 1.17 on 2009-04-12,
and noticed recently by Simon.


To generate a diff of this commit:
cvs rdiff -u -r1.18 -r1.19 src/usr.bin/locate/locate/locate.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/locate/locate/locate.c
diff -u src/usr.bin/locate/locate/locate.c:1.18 src/usr.bin/locate/locate/locate.c:1.19
--- src/usr.bin/locate/locate/locate.c:1.18	Mon Sep  5 00:40:29 2016
+++ src/usr.bin/locate/locate/locate.c	Mon May 14 05:17:10 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: locate.c,v 1.18 2016/09/05 00:40:29 sevan Exp $	*/
+/*	$NetBSD: locate.c,v 1.19 2018/05/14 05:17:10 lukem Exp $	*/
 
 /*
  * Copyright (c) 1989, 1993
@@ -42,7 +42,7 @@ __COPYRIGHT("@(#) Copyright (c) 1989, 19
 #if 0
 static char sccsid[] = "@(#)locate.c	8.1 (Berkeley) 6/6/93";
 #endif
-__RCSID("$NetBSD: locate.c,v 1.18 2016/09/05 00:40:29 sevan Exp $");
+__RCSID("$NetBSD: locate.c,v 1.19 2018/05/14 05:17:10 lukem Exp $");
 #endif /* not lint */
 
 /*
@@ -153,15 +153,15 @@ main(int argc, char *argv[])
 	}
 	if (!locate_path)
 		locate_path = _PATH_FCODES;
-	if ((cp = strrchr(locate_path, ':'))) {
-		char *lp = strdup(locate_path);
-		while ((cp = strrchr(lp, ':'))) {
-			*cp++ = '\0';
-			add_db(cp);
-		}
-		free(lp);
+
+	char *lp = strdup(locate_path);
+	while ((cp = strrchr(lp, ':'))) {
+		*cp++ = '\0';
+		add_db(cp);
 	}
-	add_db(locate_path);
+	add_db(lp);
+	free(lp);
+
 	if (LIST_EMPTY(&db_list))
 		exit(1);
 	for (; optind < argc; ++optind) {

Reply via email to