summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEdward Thomson <ethomson@edwardthomson.com>2017-06-08 13:56:22 +0200
committerGitHub <noreply@github.com>2017-06-08 13:56:22 +0200
commit90500d81dcb04ae3bdaf0f6211ca8754d9425b70 (patch)
tree8928121e4649bd960bd33c0a5fad1a7c7d38fbcb
parent3a8801aeb7160b3059ab9f2cee643c75fd0cab27 (diff)
parent90388aa836fc463f87cc9dfd41823022055a40fa (diff)
downloadlibgit2-90500d81dcb04ae3bdaf0f6211ca8754d9425b70.tar.gz
Merge pull request #4253 from pks-t/pks/cov-fixes
Coverity fixes
-rw-r--r--src/fileops.c8
-rw-r--r--src/path.c9
-rw-r--r--src/refdb_fs.c5
-rw-r--r--src/refs.c22
-rw-r--r--src/worktree.c2
5 files changed, 31 insertions, 15 deletions
diff --git a/src/fileops.c b/src/fileops.c
index a0a2795c6..bda17f02d 100644
--- a/src/fileops.c
+++ b/src/fileops.c
@@ -1155,9 +1155,13 @@ int git_futils_fsync_dir(const char *path)
int git_futils_fsync_parent(const char *path)
{
- char *parent = git_path_dirname(path);
- int error = git_futils_fsync_dir(parent);
+ char *parent;
+ int error;
+
+ if ((parent = git_path_dirname(path)) == NULL)
+ return -1;
+ error = git_futils_fsync_dir(parent);
git__free(parent);
return error;
}
diff --git a/src/path.c b/src/path.c
index b7205a646..5fc7a055b 100644
--- a/src/path.c
+++ b/src/path.c
@@ -1708,6 +1708,7 @@ GIT_INLINE(unsigned int) dotgit_flags(
unsigned int flags)
{
int protectHFS = 0, protectNTFS = 0;
+ int error = 0;
flags |= GIT_PATH_REJECT_DOT_GIT_LITERAL;
@@ -1720,13 +1721,13 @@ GIT_INLINE(unsigned int) dotgit_flags(
#endif
if (repo && !protectHFS)
- git_repository__cvar(&protectHFS, repo, GIT_CVAR_PROTECTHFS);
- if (protectHFS)
+ error = git_repository__cvar(&protectHFS, repo, GIT_CVAR_PROTECTHFS);
+ if (!error && protectHFS)
flags |= GIT_PATH_REJECT_DOT_GIT_HFS;
if (repo && !protectNTFS)
- git_repository__cvar(&protectNTFS, repo, GIT_CVAR_PROTECTNTFS);
- if (protectNTFS)
+ error = git_repository__cvar(&protectNTFS, repo, GIT_CVAR_PROTECTNTFS);
+ if (!error && protectNTFS)
flags |= GIT_PATH_REJECT_DOT_GIT_NTFS;
return flags;
diff --git a/src/refdb_fs.c b/src/refdb_fs.c
index b325d2763..988a14b85 100644
--- a/src/refdb_fs.c
+++ b/src/refdb_fs.c
@@ -1140,7 +1140,7 @@ out:
static int maybe_append_head(refdb_fs_backend *backend, const git_reference *ref, const git_signature *who, const char *message)
{
int error;
- git_oid old_id = {{0}};
+ git_oid old_id;
git_reference *tmp = NULL, *head = NULL, *peeled = NULL;
const char *name;
@@ -1148,7 +1148,8 @@ static int maybe_append_head(refdb_fs_backend *backend, const git_reference *ref
return 0;
/* if we can't resolve, we use {0}*40 as old id */
- git_reference_name_to_id(&old_id, backend->repo, ref->name);
+ if (git_reference_name_to_id(&old_id, backend->repo, ref->name) < 0)
+ memset(&old_id, 0, sizeof(old_id));
if ((error = git_reference_lookup(&head, backend->repo, GIT_HEAD_FILE)) < 0)
return error;
diff --git a/src/refs.c b/src/refs.c
index 632a5299c..f7120d9ee 100644
--- a/src/refs.c
+++ b/src/refs.c
@@ -622,15 +622,25 @@ typedef struct {
static int update_wt_heads(git_repository *repo, const char *path, void *payload)
{
rename_cb_data *data = (rename_cb_data *) payload;
- git_reference *head;
+ git_reference *head = NULL;
char *gitdir = NULL;
- int error = 0;
+ int error;
+
+ if ((error = git_reference__read_head(&head, repo, path)) < 0) {
+ giterr_set(GITERR_REFERENCE, "could not read HEAD when renaming references");
+ goto out;
+ }
- if (git_reference__read_head(&head, repo, path) < 0 ||
- git_reference_type(head) != GIT_REF_SYMBOLIC ||
- git__strcmp(head->target.symbolic, data->old_name) != 0 ||
- (gitdir = git_path_dirname(path)) == NULL)
+ if ((gitdir = git_path_dirname(path)) == NULL) {
+ error = -1;
goto out;
+ }
+
+ if (git_reference_type(head) != GIT_REF_SYMBOLIC ||
+ git__strcmp(head->target.symbolic, data->old_name) != 0) {
+ error = 0;
+ goto out;
+ }
/* Update HEAD it was pointing to the reference being renamed */
if ((error = git_repository_create_head(gitdir, data->new_name)) < 0) {
diff --git a/src/worktree.c b/src/worktree.c
index f224b2333..ede155b69 100644
--- a/src/worktree.c
+++ b/src/worktree.c
@@ -212,7 +212,7 @@ int git_worktree_open_from_repository(git_worktree **out, git_repository *repo)
goto out;
out:
- free(name);
+ git__free(name);
git_buf_free(&parent);
return error;