[PATCH] show-index: fix uninitialized hash function
- From
Abhijeet Sonar <abhijeet.nkt@gmail.com>
- Date
- Jul 12, 2024, 14:23 UTC
- Message-ID
- <20240712142326.266533-1-abhijeet.nkt@gmail.com>
As stated in the docs, show-index should use SHA1 as the default hash algorithm when run outsize of a repository. However, 'the_hash_algo' is currently left uninitialized if we are not in a repository and no explicit hash funciton is specified, causing a crash. Fix it by falling back to SHA1 when it is found uninitialized.
Signed-off-by: Abhijeet Sonar <abhijeet.nkt@gmail.com> --- builtin/show-index.c | 3 +++ 1 file changed, 3 insertions(+)
diff --git a/builtin/show-index.c b/builtin/show-index.c index 540dc3dad1..bb6d9e3c40 100644 --- a/builtin/show-index.c +++ b/builtin/show-index.c @@ -35,6 +35,9 @@ int cmd_show_index(int argc, const char **argv, const char *prefix) repo_set_hash_algo(the_repository, hash_algo); } + if (!the_hash_algo) + repo_set_hash_algo(the_repository, GIT_HASH_SHA1); + hashsz = the_hash_algo->rawsz; if (fread(top_index, 2 * 4, 1, stdin) != 1)
-- 2.45.2.827.g557ae147e6