Skip to content

Commit ff8d2eb

Browse files
committed
blame_git: check return value of object lookup
The function `pass_whole_blame` performs an object lookup but does not check if the lookup actually succeeds. Convert the function to return an error code and check for it in the calling function.
1 parent dd0b1e8 commit ff8d2eb

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

src/blame_git.c

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -478,21 +478,24 @@ static git_blame__origin* find_origin(
478478
* The blobs of origin and porigin exactly match, so everything origin is
479479
* suspected for can be blamed on the parent.
480480
*/
481-
static void pass_whole_blame(git_blame *blame,
481+
static int pass_whole_blame(git_blame *blame,
482482
git_blame__origin *origin, git_blame__origin *porigin)
483483
{
484484
git_blame__entry *e;
485485

486-
if (!porigin->blob)
487-
git_object_lookup((git_object**)&porigin->blob, blame->repository,
488-
git_blob_id(origin->blob), GIT_OBJ_BLOB);
486+
if (!porigin->blob &&
487+
git_object_lookup((git_object**)&porigin->blob, blame->repository,
488+
git_blob_id(origin->blob), GIT_OBJ_BLOB) < 0)
489+
return -1;
489490
for (e=blame->ent; e; e=e->next) {
490491
if (!same_suspect(e->suspect, origin))
491492
continue;
492493
origin_incref(porigin);
493494
origin_decref(e->suspect);
494495
e->suspect = porigin;
495496
}
497+
498+
return 0;
496499
}
497500

498501
static int pass_blame(git_blame *blame, git_blame__origin *origin, uint32_t opt)
@@ -543,7 +546,8 @@ static int pass_blame(git_blame *blame, git_blame__origin *origin, uint32_t opt)
543546
}
544547
if (porigin->blob && origin->blob &&
545548
!git_oid_cmp(git_blob_id(porigin->blob), git_blob_id(origin->blob))) {
546-
pass_whole_blame(blame, origin, porigin);
549+
error = pass_whole_blame(blame, origin, porigin);
550+
goto finish;
547551
origin_decref(porigin);
548552
goto finish;
549553
}

0 commit comments

Comments
 (0)