From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: X-Spam-Status: No, score=-4.2 required=3.0 tests=ALL_TRUSTED,AWL,BAYES_00, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF shortcircuit=no autolearn=ham autolearn_force=no version=3.4.6 Received: from localhost (dcvr.yhbt.net [127.0.0.1]) by dcvr.yhbt.net (Postfix) with ESMTP id 7EFC51F51B for ; Mon, 25 Mar 2024 23:03:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=80x24.org; s=selector1; t=1711407820; bh=lzOP+ucr4p+PyTQgRs/NmEzhnCR2dluI1XxwF4qKPjE=; h=From:To:Subject:Date:In-Reply-To:References:From; b=yVxXhLwks5T9Dn4ddGZIyecbRb1K44X3Wivc82pFJ4gg9TW6B0+EjyOKlxOdSfJf2 B6hqpTywpgXgLS/2URPdIg0t5Cr7a8zrMDY34MRgm1XZn/7ZyLOUzKcCHq0JJXPc5j RJ5Ae7MDZOoYc5ldKAhhPI+x8tSD0iYUTNfevF/A= From: Eric Wong To: spew@80x24.org Subject: [PATCH 3/3] khashl: fix ensemble lookups on empty table Date: Mon, 25 Mar 2024 23:03:38 +0000 Message-ID: <20240325230339.262200-4-e@80x24.org> In-Reply-To: <20240325230339.262200-1-e@80x24.org> References: <20240325230339.262200-1-e@80x24.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit List-Id: The ->bits field of regular khashl structs is invalid when the ->keys array is NULL. Thus the ensemble *_getp implementation must follow existing *_get and *_getp usage conventions and check the iterator against kh_end(). This fixes a fast-import crash on t3427-rebase-subtree.sh in an abandoned commit to use the ensemble implementation for oid_map and oid_pos. I've abandoned the aforementioned commit for now since it was more intrusive, more expensive for small tables, and realloc(3) on glibc is already optimized using mremap(2) for large hash resizes. Signed-off-by: Eric Wong --- khashl.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/khashl.h b/khashl.h index 3660fd2ce4..8ffe80fbb2 100644 --- a/khashl.h +++ b/khashl.h @@ -265,7 +265,7 @@ typedef struct { low = hash & ((1U<bits) - 1); \ h = &g->sub[low]; \ ret = prefix##_sub_getp_core(h, key, hash); \ - if (ret == 1U<bits) r.sub = low, r.pos = (khint_t)-1; \ + if (ret >= kh_end(h)) r.sub = low, r.pos = (khint_t)-1; \ else r.sub = low, r.pos = ret; \ return r; \ } \