]> git.ipfire.org Git - thirdparty/git.git/blobdiff - object-file.c
reftable: fix resource warning
[thirdparty/git.git] / object-file.c
index 02b79702748d1f163bb84f925fde45e49c3bd4b6..8d5a5b8afbec0c61466a5485b8c8623442c89db0 100644 (file)
@@ -165,7 +165,6 @@ static void git_hash_unknown_final_oid(struct object_id *oid, git_hash_ctx *ctx)
        BUG("trying to finalize unknown hash");
 }
 
-
 const struct git_hash_algo hash_algos[GIT_HASH_NALGOS] = {
        {
                NULL,
@@ -184,8 +183,7 @@ const struct git_hash_algo hash_algos[GIT_HASH_NALGOS] = {
        },
        {
                "sha1",
-               /* "sha1", big-endian */
-               0x73686131,
+               GIT_SHA1_FORMAT_ID,
                GIT_SHA1_RAWSZ,
                GIT_SHA1_HEXSZ,
                GIT_SHA1_BLKSZ,
@@ -200,8 +198,7 @@ const struct git_hash_algo hash_algos[GIT_HASH_NALGOS] = {
        },
        {
                "sha256",
-               /* "s256", big-endian */
-               0x73323536,
+               GIT_SHA256_FORMAT_ID,
                GIT_SHA256_RAWSZ,
                GIT_SHA256_HEXSZ,
                GIT_SHA256_BLKSZ,
@@ -1306,7 +1303,7 @@ static void *unpack_loose_rest(git_zstream *stream,
 int parse_loose_header(const char *hdr, struct object_info *oi)
 {
        const char *type_buf = hdr;
-       unsigned long size;
+       size_t size;
        int type, type_len = 0;
 
        /*
@@ -1341,12 +1338,12 @@ int parse_loose_header(const char *hdr, struct object_info *oi)
                        if (c > 9)
                                break;
                        hdr++;
-                       size = size * 10 + c;
+                       size = st_add(st_mult(size, 10), c);
                }
        }
 
        if (oi->sizep)
-               *oi->sizep = size;
+               *oi->sizep = cast_size_t_to_ulong(size);
 
        /*
         * The length must be followed by a zero byte
@@ -2557,10 +2554,9 @@ int read_loose_object(const char *path,
                        goto out;
                }
                if (check_object_signature(the_repository, expected_oid,
-                                          *contents, *size, oi->type_name->buf, real_oid)) {
-                       free(*contents);
+                                          *contents, *size,
+                                          oi->type_name->buf, real_oid))
                        goto out;
-               }
        }
 
        ret = 0; /* everything checks out */