Commit Diff


commit - 68c4d269f664e2f1f2d4a0c15910799c5fbdd529
commit + ec138a87e1d71bea746b7d4586ac24aa476e825d
blob - 8df1c53608fd376ac03180c1b6606c3ae9e4dcf3
blob + 6ec34f370067855ed6e758430e10de7930e72729
--- lib/pack.c
+++ lib/pack.c
@@ -519,7 +519,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);
 
@@ -532,7 +532,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];