git: 0c178a2a645d - main - support more than 2 billion file names for counting (-c) or limits (-l limit)
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Wed, 26 Jan 2022 16:17:26 UTC
The branch main has been updated by wosch: URL: https://cgit.FreeBSD.org/src/commit/?id=0c178a2a645d8b0cd311cc872af1fd184c6e6663 commit 0c178a2a645d8b0cd311cc872af1fd184c6e6663 Author: Wolfram Schneider <wosch@FreeBSD.org> AuthorDate: 2022-01-26 16:15:23 +0000 Commit: Wolfram Schneider <wosch@FreeBSD.org> CommitDate: 2022-01-26 16:15:23 +0000 support more than 2 billion file names for counting (-c) or limits (-l limit) - this fix (harmless) integer overflows for very large partitions (>1PB) - code cleanup --- usr.bin/locate/locate/fastfind.c | 2 +- usr.bin/locate/locate/locate.c | 11 ++++++----- usr.bin/locate/locate/util.c | 11 +---------- 3 files changed, 8 insertions(+), 16 deletions(-) diff --git a/usr.bin/locate/locate/fastfind.c b/usr.bin/locate/locate/fastfind.c index 7340ce156675..fdbbb1c3db18 100644 --- a/usr.bin/locate/locate/fastfind.c +++ b/usr.bin/locate/locate/fastfind.c @@ -326,7 +326,7 @@ fastfind if (f_limit >= counter) (void)printf("%s%c",path,separator); else - errx(0, "[show only %d lines]", counter - 1); + errx(0, "[show only %ld lines]", counter - 1); } else (void)printf("%s%c",path,separator); } diff --git a/usr.bin/locate/locate/locate.c b/usr.bin/locate/locate/locate.c index d339037c2003..40e183f8d45a 100644 --- a/usr.bin/locate/locate/locate.c +++ b/usr.bin/locate/locate/locate.c @@ -102,8 +102,8 @@ int f_icase; /* ignore case */ int f_stdin; /* read database from stdin */ int f_statistic; /* print statistic */ int f_silent; /* suppress output, show only count of matches */ -int f_limit; /* limit number of output lines, 0 == infinite */ -u_int counter; /* counter for matches [-c] */ +long f_limit; /* limit number of output lines, 0 == infinite */ +long counter; /* counter for matches [-c] */ char separator='\n'; /* line separator */ u_char myctype[UCHAR_MAX + 1]; @@ -119,7 +119,6 @@ void search_fopen(char *, char **); unsigned long cputime(void); extern char **colon(char **, char*, char*); -extern void print_matches(u_int); extern int getwm(caddr_t); extern int getwf(FILE *); extern u_char *tolower_word(u_char *); @@ -146,7 +145,9 @@ main(int argc, char **argv) f_statistic = 1; break; case 'l': /* limit number of output lines, 0 == infinite */ - f_limit = atoi(optarg); + f_limit = atol(optarg); + if (f_limit < 0 ) + errx(1, "invalid argument for -l: '%s'", optarg); break; case 'd': /* database */ dbv = colon(dbv, optarg, _PATH_FCODES); @@ -211,7 +212,7 @@ main(int argc, char **argv) } if (f_silent) - print_matches(counter); + printf("%ld\n", counter); exit(0); } diff --git a/usr.bin/locate/locate/util.c b/usr.bin/locate/locate/util.c index 42710de9490a..ff64b5a952d3 100644 --- a/usr.bin/locate/locate/util.c +++ b/usr.bin/locate/locate/util.c @@ -1,7 +1,7 @@ /* * SPDX-License-Identifier: BSD-3-Clause * - * Copyright (c) 1995 Wolfram Schneider <wosch@FreeBSD.org>. Berlin. + * Copyright (c) 1995-2022 Wolfram Schneider <wosch@FreeBSD.org> * Copyright (c) 1989, 1993 * The Regents of the University of California. All rights reserved. * @@ -47,7 +47,6 @@ char **colon(char **, char*, char*); char *patprep(char *); -void print_matches(u_int); u_char *tolower_word(u_char *); int getwm(caddr_t); int getwf(FILE *); @@ -131,14 +130,6 @@ colon(char **dbv, char *path, char *dot) return (dbv); } -void -print_matches(counter) - u_int counter; -{ - (void)printf("%d\n", counter); -} - - /* * extract last glob-free subpattern in name for fast pre-match; prepend * '\0' for backwards match; return end of new pattern