8000 Fixes NRE issues found by Covertity in ObjectDatabase.cs · leoniDEV/libgit2sharp@fba0a73 · GitHub
[go: up one dir, main page]

Skip to content

Commit fba0a73

Browse files
author
J Wyman
committed
Fixes NRE issues found by Covertity in ObjectDatabase.cs
1 parent 129d703 commit fba0a73

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

LibGit2Sharp/ObjectDatabase.cs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -365,7 +365,9 @@ public virtual Commit CreateCommit(Signature author, Signature committer, string
365365

366366
ObjectId commitId = Proxy.git_commit_create(repo.Handle, null, author, committer, message, tree, parentIds);
367367

368-
return repo.Lookup<Commit>(commitId);
368+
Commit commit = repo.Lookup<Commit>(commitId);
369+
Ensure.GitObjectIsNotNull(commit, commitId.Sha);
370+
return commit;
369371
}
370372

371373
/// <summary>
@@ -454,6 +456,8 @@ public virtual string ShortenObjectId(GitObject gitObject)
454456
/// <returns>A short string representation of the <see cref="ObjectId"/>.</returns>
455457
public virtual string ShortenObjectId(GitObject gitObject, int minLength)
456458
{
459+
Ensure.ArgumentNotNull(gitObject, "gitObject");
460+
457461
if (minLength <= 0 || minLength > ObjectId.HexSize)
458462
{
459463
throw new ArgumentOutOfRangeException("minLen 7DC9 gth", minLength,
@@ -462,6 +466,11 @@ public virtual string ShortenObjectId(GitObject gitObject, int minLength)
462466

463467
string shortSha = Proxy.git_object_short_id(repo.Handle, gitObject.Id);
464468

469+
if (shortSha == null)
470+
{
471+
throw new LibGit2SharpException("Unable to abbreviate SHA-1 value for GitObject " + gitObject.Id);
472+
}
473+
465474
if (minLength <= shortSha.Length)
466475
{
467476
return shortSha;

0 commit comments

Comments
 (0)
0