git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: Eric Wong <e@80x24.org>
To: git@vger.kernel.org
Subject: [PATCH 3/3] khashl: fix ensemble lookups on empty table
Date: Mon, 25 Mar 2024 23:07:03 +0000	[thread overview]
Message-ID: <20240325230704.262272-4-e@80x24.org> (raw)
In-Reply-To: <20240325230704.262272-1-e@80x24.org>

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 <e@80x24.org>
---
 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<<g->bits) - 1); \
 		h = &g->sub[low]; \
 		ret = prefix##_sub_getp_core(h, key, hash); \
-		if (ret == 1U<<h->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; \
 	} \


  parent reply	other threads:[~2024-03-25 23:07 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-03-25 23:07 [PATCH 0/3] switch to tombstone-free khashl table Eric Wong
2024-03-25 23:07 ` [PATCH 1/3] list-objects-filter: use kh_size API Eric Wong
2024-03-25 23:07 ` [PATCH 2/3] treewide: switch to khashl for memory savings Eric Wong
2024-03-26 17:48   ` Junio C Hamano
2024-03-27  9:37     ` Jeff King
2024-03-27 21:54       ` Junio C Hamano
2024-03-25 23:07 ` Eric Wong [this message]
2024-03-25 23:07 ` [REJECT 4/3] switch to khashl ensemble Eric Wong
2024-03-26 17:40 ` [PATCH 0/3] switch to tombstone-free khashl table Junio C Hamano
2024-04-19 21:31   ` Junio C Hamano
2024-04-19 21:46     ` Eric Wong
  -- strict thread matches above, loose matches on Subject: below --
2024-03-28 10:13 Eric Wong
2024-03-28 10:13 ` [PATCH 3/3] khashl: fix ensemble lookups on empty table Eric Wong

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: http://vger.kernel.org/majordomo-info.html

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20240325230704.262272-4-e@80x24.org \
    --to=e@80x24.org \
    --cc=git@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).