From nobody Mon Jan 31 17:04:32 2022 X-Original-To: dev-commits-src-all@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 7A9EE199B2E4; Mon, 31 Jan 2022 17:04:33 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4JnZDK1Wpqz3n8p; Mon, 31 Jan 2022 17:04:33 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1643648673; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=vVp26rlqrhYbhNq4hS64f9TwdtUO4WW8wehr9hYuoSE=; b=UUs/Hobxqj3yYsCNooq3SimvP7M9ak5aVr+AGovCCvnUWb54GMojFfAYT/9jjpXP0HJ0Tt TtcN4t2ZWvTdm3O89vpWtIHgWotEZsBwWn8CoyIq8KMqGFschho1OI5RkXGsjMwcG/lfUV SFr1rld+aaVuOXjZ5YihbOuOu7/nmPJkZRimeq2qoTTxhGzXbn6X0Nn/Y6VHM3KQVryY5E O6wpxzzKd+wsYi2LkCzVCRgCjTZYe/cx0qe1GTUDB6hjcrLmEw0Cj6DCuiXiXKusGqoDHZ qwk+OjXLzXs11F2CZigBKx9g0w5V1EQ5059SqSopR/T2Pc/rJupaYvSooPumtA== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id F20A01FEF5; Mon, 31 Jan 2022 17:04:32 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 20VH4WVh056285; Mon, 31 Jan 2022 17:04:32 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 20VH4WCc056284; Mon, 31 Jan 2022 17:04:32 GMT (envelope-from git) Date: Mon, 31 Jan 2022 17:04:32 GMT Message-Id: <202201311704.20VH4WCc056284@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Wolfram Schneider Subject: git: 8d35ca86c570 - main - Fix statistics for empty databases List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-all@freebsd.org X-BeenThere: dev-commits-src-all@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: wosch X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 8d35ca86c570cd2eb727b439c1b5567897990048 Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1643648673; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=vVp26rlqrhYbhNq4hS64f9TwdtUO4WW8wehr9hYuoSE=; b=SYU1VvZqYPInrOxtADo3QLYorD8LUOB9z308RwR7723xp/8hd1EDDZh/iKk4LCcsdmMRRb JsvKyk1/M+yK7SfTJdxycZKWWBKLToLPvfgq+Ha4ytHlFEZ2Kygblcr+cKZSV9ynzxHIBp budRMnSk3iJHLzFxt9nKurZ8E3OMIjZ34V7WXYdGGPTh8QH0xZac7nPAXMcbeHkZojXw+w bKU8AIPgBSB0nMbaZKPVnZxQgnMMrPr1bVcATtAqAGEDtxSxEwn0YPrpZF7GuMdZBd4mnd Iz/jZlXS1QfV0vtmWEygZCw1hMRBuEZCri63ezUuo/2dG3JpcpsH89fZZCFcSw== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1643648673; a=rsa-sha256; cv=none; b=sUWWR59ce0esrdokogVEXu0kX52OBl5h583k5hdtGBHoVZGEC4iUbOu9vjjAGBjkB1tlv0 mAxgTLzue3M2MLabw0eqttRJ3cdhMn/K/unNT5qN0IKdLqkfhlC2c9Zma6+HQuJLvXkvZz 7wSGgvHqdOt0/RFWXTgC1z1X1IV/JHTvQBooY8npgsvYVrX9od8hgrM71Lr1o6RegH4XSE OqC8tq/WcVJBITJU7zboa9ySNEZVT/qYY852Gola5F5WC0fSgQLYiaj+swgJxw8+mzO1AN ZQozm3XvfJ2mcN1WXvUAESY6BOzDqOOtaEFZ2TnXxCS36vxw/J3AlnbGtUlZow== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by wosch: URL: https://cgit.FreeBSD.org/src/commit/?id=8d35ca86c570cd2eb727b439c1b5567897990048 commit 8d35ca86c570cd2eb727b439c1b5567897990048 Author: Wolfram Schneider AuthorDate: 2022-01-31 17:03:08 +0000 Commit: Wolfram Schneider CommitDate: 2022-01-31 17:03:08 +0000 Fix statistics for empty databases An empty database is a database which does not contain any filenames. It should not occur in practice but maybe in the case of an error. echo | /usr/libexec/locate.mklocatedb > empty.db; locate -d empty.db -S --- usr.bin/locate/locate/fastfind.c | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/usr.bin/locate/locate/fastfind.c b/usr.bin/locate/locate/fastfind.c index 1fe611186e68..9a3324e20e44 100644 --- a/usr.bin/locate/locate/fastfind.c +++ b/usr.bin/locate/locate/fastfind.c @@ -44,7 +44,7 @@ statistic (fp, path_fcodes) FILE *fp; /* open database */ char *path_fcodes; /* for error message */ { - long lines, chars, size, big, zwerg, umlaut; + long lines, chars, size, size_nbg, big, zwerg, umlaut; u_char *p, *s; int c; int count, longest_path; @@ -95,19 +95,21 @@ statistic (fp, path_fcodes) longest_path = p - path; } + /* size without bigram db */ + size_nbg = size - (2 * NBG); + (void)printf("\nDatabase: %s\n", path_fcodes); - (void)printf("Compression: Front: %2.2f%%, ", - (size + big - (2 * NBG)) / (chars / (float)100)); - (void)printf("Bigram: %2.2f%%, ", (size - big) / (size / (float)100)); - (void)printf("Total: %2.2f%%\n", - (size - (2 * NBG)) / (chars / (float)100)); + (void)printf("Compression: Front: %2.2f%%, ", chars > 0 ? (size_nbg + big) / (chars / (float)100) : 0); + (void)printf("Bigram: %2.2f%%, ", big > 0 ? (size_nbg - big) / (size_nbg / (float)100) : 0); + /* incl. bigram db overhead */ + (void)printf("Total: %2.2f%%\n", chars > 0 ? size / (chars / (float)100) : 0); (void)printf("Filenames: %ld, ", lines); (void)printf("Characters: %ld, ", chars); (void)printf("Database size: %ld\n", size); (void)printf("Bigram characters: %ld, ", big); (void)printf("Integers: %ld, ", zwerg); (void)printf("8-Bit characters: %ld\n", umlaut); - printf("Longest path: %d\n", longest_path - 1); + printf("Longest path: %d\n", longest_path > 0 ? longest_path - 1 : 0); /* non zero exit on corrupt database */ if (error)