Skip to content

Commit ee213de

Browse files
avargitster
authored andcommitted
object API users + docs: check <0, not !0 with check_object_signature()
Change those users of the object API that misused check_object_signature() by assuming it returned any non-zero when the OID didn't match the expected value to check <0 instead. In practice all of this code worked before, but it wasn't consistent with rest of the users of the API. Let's also clarify what the <0 return value means in API docs. Signed-off-by: Ævar Arnfjörð Bjarmason <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent cdcaaec commit ee213de

File tree

5 files changed

+8
-6
lines changed

5 files changed

+8
-6
lines changed

builtin/index-pack.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1412,9 +1412,8 @@ static void fix_unresolved_deltas(struct hashfile *f)
14121412
if (!data)
14131413
continue;
14141414

1415-
if (check_object_signature(the_repository, &d->oid,
1416-
data, size,
1417-
type_name(type), NULL))
1415+
if (check_object_signature(the_repository, &d->oid, data, size,
1416+
type_name(type), NULL) < 0)
14181417
die(_("local object %s is corrupt"), oid_to_hex(&d->oid));
14191418

14201419
/*

builtin/mktag.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ int cmd_mktag(int argc, const char **argv, const char *prefix)
9797
&tagged_oid, &tagged_type))
9898
die(_("tag on stdin did not pass our strict fsck check"));
9999

100-
if (verify_object_in_tag(&tagged_oid, &tagged_type))
100+
if (verify_object_in_tag(&tagged_oid, &tagged_type) < 0)
101101
die(_("tag on stdin did not refer to a valid object"));
102102

103103
if (write_object_file(buf.buf, buf.len, OBJ_TAG, &result) < 0)

cache.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1324,6 +1324,9 @@ int parse_loose_header(const char *hdr, struct object_info *oi);
13241324
* object name actually matches "oid" to detect object corruption.
13251325
* With "buf" == NULL, try reading the object named with "oid" using
13261326
* the streaming interface and rehash it to do the same.
1327+
*
1328+
* A negative value indicates an error, usually that the OID is not
1329+
* what we expected, but it might also indicate another error.
13271330
*/
13281331
int check_object_signature(struct repository *r, const struct object_id *oid,
13291332
void *buf, unsigned long size, const char *type,

object-file.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2613,7 +2613,7 @@ int read_loose_object(const char *path,
26132613
}
26142614
if (check_object_signature(the_repository, expected_oid,
26152615
*contents, *size,
2616-
oi->type_name->buf, real_oid))
2616+
oi->type_name->buf, real_oid) < 0)
26172617
goto out;
26182618
}
26192619

pack-check.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ static int verify_packfile(struct repository *r,
143143
oid_to_hex(&oid), p->pack_name,
144144
(uintmax_t)entries[i].offset);
145145
else if (check_object_signature(r, &oid, data, size,
146-
type_name(type), NULL))
146+
type_name(type), NULL) < 0)
147147
err = error("packed %s from %s is corrupt",
148148
oid_to_hex(&oid), p->pack_name);
149149
else if (fn) {

0 commit comments

Comments
 (0)