"GOT", but the "O" is a cute, smiling pufferfish. Index | Thread | Search

From:
Omar Polo <op@omarpolo.com>
Subject:
some memcmp -> got_object_id_cmp in object_parse.c
To:
gameoftrees@openbsd.org
Date:
Thu, 02 Feb 2023 17:27:42 +0100

Download raw body.

Thread
avoids some assumption about the hash size ;-)

yeah, the error message is still generated with
got_sha1_digest_to_str.  we can add a function like got_object_id_str
that serialize an id to a static buffer in a second moment i think.

ok?

diff /tmp/got
commit - c4d35c5bb4f936d0f96bb62d234001b68dc33089
path + /tmp/got
blob - 9731ce78ee76e120a9a9747158089178ac3758e7
file + lib/object_parse.c
--- lib/object_parse.c
+++ lib/object_parse.c
@@ -759,7 +759,7 @@ got_object_read_commit(struct got_commit_object **comm
 		return err;
 
 	SHA1Final(id.sha1, &sha1_ctx);
-	if (memcmp(expected_id->sha1, id.sha1, SHA1_DIGEST_LENGTH) != 0) {
+	if (got_object_id_cmp(expected_id, &id) != 0) {
 		char buf[SHA1_DIGEST_STRING_LENGTH];
 		err = got_error_fmt(GOT_ERR_OBJ_CSUM,
 		    "checksum failure for object %s",
@@ -932,7 +932,7 @@ got_object_read_tree(struct got_parsed_tree_entry **en
 		return err;
 
 	SHA1Final(id.sha1, &sha1_ctx);
-	if (memcmp(expected_id->sha1, id.sha1, SHA1_DIGEST_LENGTH) != 0) {
+	if (got_object_id_cmp(expected_id, &id) != 0) {
 		char buf[SHA1_DIGEST_STRING_LENGTH];
 		err = got_error_fmt(GOT_ERR_OBJ_CSUM,
 		    "checksum failure for object %s",
@@ -1176,7 +1176,7 @@ got_object_read_tag(struct got_tag_object **tag, int f
 		return err;
 
 	SHA1Final(id.sha1, &sha1_ctx);
-	if (memcmp(expected_id->sha1, id.sha1, SHA1_DIGEST_LENGTH) != 0) {
+	if (got_object_id_cmp(expected_id, &id) != 0) {
 		char buf[SHA1_DIGEST_STRING_LENGTH];
 		err = got_error_fmt(GOT_ERR_OBJ_CSUM,
 		    "checksum failure for object %s",