git: e48156828f07 - main - switch to 64 bit integers for counting bigrams
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Wed, 26 Jan 2022 16:14:02 UTC
The branch main has been updated by wosch:
URL: https://cgit.FreeBSD.org/src/commit/?id=e48156828f07fa172adb05776356d2b043544a05
commit e48156828f07fa172adb05776356d2b043544a05
Author: Wolfram Schneider <wosch@FreeBSD.org>
AuthorDate: 2022-01-26 16:11:51 +0000
Commit: Wolfram Schneider <wosch@FreeBSD.org>
CommitDate: 2022-01-26 16:11:51 +0000
switch to 64 bit integers for counting bigrams
This fixes an integer overflow for very large partitions around 35 billion
filenames (>2PB). However, in an artificially worst case it may occurs
by only 17 mio filenames on a partition.
---
usr.bin/locate/bigram/locate.bigram.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/usr.bin/locate/bigram/locate.bigram.c b/usr.bin/locate/bigram/locate.bigram.c
index 0868a5f89070..d15f8ce170e8 100644
--- a/usr.bin/locate/bigram/locate.bigram.c
+++ b/usr.bin/locate/bigram/locate.bigram.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.
*
@@ -64,7 +64,7 @@ static char sccsid[] = "@(#)locate.bigram.c 8.1 (Berkeley) 6/6/93";
u_char buf1[MAXPATHLEN] = " ";
u_char buf2[MAXPATHLEN];
-u_int bigram[UCHAR_MAX + 1][UCHAR_MAX + 1];
+unsigned long bigram[UCHAR_MAX + 1][UCHAR_MAX + 1];
int
main(void)
@@ -109,7 +109,7 @@ main(void)
for (i = ASCII_MIN; i <= ASCII_MAX; i++)
for (j = ASCII_MIN; j <= ASCII_MAX; j++)
if (bigram[i][j] != 0)
- (void)printf("%4u %c%c\n", bigram[i][j], i, j);
+ printf("%lu %c%c\n", bigram[i][j], i, j);
exit(0);
}