tree-diff: don't access hash of NULL object_id pointer
[gitweb.git] / tree-diff.c
index 6a960f569cc1ae59f0b48009cee93449a02ebc97..7f7ddda4ea51e32f67ded46d73f5c0b1c8adb6d6 100644 (file)
@@ -132,7 +132,7 @@ static int emit_diff_first_parent_only(struct diff_options *opt, struct combine_
  */
 static struct combine_diff_path *path_appendnew(struct combine_diff_path *last,
        int nparent, const struct strbuf *base, const char *path, int pathlen,
-       unsigned mode, const unsigned char *sha1)
+       unsigned mode, const struct object_id *oid)
 {
        struct combine_diff_path *p;
        size_t len = st_add(base->len, pathlen);
@@ -162,7 +162,7 @@ static struct combine_diff_path *path_appendnew(struct combine_diff_path *last,
        memcpy(p->path + base->len, path, pathlen);
        p->path[len] = 0;
        p->mode = mode;
-       hashcpy(p->oid.hash, sha1 ? sha1 : null_sha1);
+       oidcpy(&p->oid, oid ? oid : &null_oid);
 
        return p;
 }
@@ -221,7 +221,7 @@ static struct combine_diff_path *emit_path(struct combine_diff_path *p,
        if (emitthis) {
                int keep;
                struct combine_diff_path *pprev = p;
-               p = path_appendnew(p, nparent, base, path, pathlen, mode, oid ? oid->hash : NULL);
+               p = path_appendnew(p, nparent, base, path, pathlen, mode, oid);
 
                for (i = 0; i < nparent; ++i) {
                        /*
@@ -422,8 +422,9 @@ static struct combine_diff_path *ll_diff_tree_paths(
         *   diff_tree_oid(parent, commit) )
         */
        for (i = 0; i < nparent; ++i)
-               tptree[i] = fill_tree_descriptor(&tp[i], parents_oid[i]->hash);
-       ttree = fill_tree_descriptor(&t, oid->hash);
+               tptree[i] = fill_tree_descriptor(&tp[i],
+                               parents_oid[i] ? parents_oid[i]->hash : NULL);
+       ttree = fill_tree_descriptor(&t, oid ? oid->hash : NULL);
 
        /* Enable recursion indefinitely */
        opt->pathspec.recursive = DIFF_OPT_TST(opt, RECURSIVE);