Commit Diff


commit - a8a244dd9f028cb4a3a7f05a51ec1bdcb96f3195
commit + 404bde06df84f6c5521c237cd1f57373e69fe5b7
blob - b23b1379d56dac2d5b31ae48e64080a8c5cb768f
blob + a0306114c68e819c0550e81661abc0b5fc91994d
--- lib/pack.c
+++ lib/pack.c
@@ -523,7 +523,7 @@ got_packidx_match_id_str_prefix(struct got_object_id_q
 	char hex[3];
 	size_t prefix_len = strlen(id_str_prefix);
 	struct got_packidx_object_id *oid;
-	uint32_t i;
+	uint32_t i = 0;
 
 	STAILQ_INIT(matched_ids);
 
@@ -536,7 +536,8 @@ got_packidx_match_id_str_prefix(struct got_object_id_q
 	if (!got_parse_xdigit(&id0, hex))
 		return got_error_path(id_str_prefix, GOT_ERR_BAD_OBJ_ID_STR);
 
-	i = be32toh(packidx->hdr.fanout_table[id0 - 1]);
+	if (id0 > 0)
+		i = be32toh(packidx->hdr.fanout_table[id0 - 1]);
 	oid = &packidx->hdr.sorted_ids[i];
 	while (i < totobj && oid->sha1[0] == id0) {
 		char id_str[SHA1_DIGEST_STRING_LENGTH];