Commit 90500d81 by Edward Thomson Committed by GitHub

Merge pull request #4253 from pks-t/pks/cov-fixes

Coverity fixes
parents 3a8801ae 90388aa8
...@@ -1155,9 +1155,13 @@ int git_futils_fsync_dir(const char *path) ...@@ -1155,9 +1155,13 @@ int git_futils_fsync_dir(const char *path)
int git_futils_fsync_parent(const char *path) int git_futils_fsync_parent(const char *path)
{ {
char *parent = git_path_dirname(path); char *parent;
int error = git_futils_fsync_dir(parent); int error;
if ((parent = git_path_dirname(path)) == NULL)
return -1;
error = git_futils_fsync_dir(parent);
git__free(parent); git__free(parent);
return error; return error;
} }
...@@ -1708,6 +1708,7 @@ GIT_INLINE(unsigned int) dotgit_flags( ...@@ -1708,6 +1708,7 @@ GIT_INLINE(unsigned int) dotgit_flags(
unsigned int flags) unsigned int flags)
{ {
int protectHFS = 0, protectNTFS = 0; int protectHFS = 0, protectNTFS = 0;
int error = 0;
flags |= GIT_PATH_REJECT_DOT_GIT_LITERAL; flags |= GIT_PATH_REJECT_DOT_GIT_LITERAL;
...@@ -1720,13 +1721,13 @@ GIT_INLINE(unsigned int) dotgit_flags( ...@@ -1720,13 +1721,13 @@ GIT_INLINE(unsigned int) dotgit_flags(
#endif #endif
if (repo && !protectHFS) if (repo && !protectHFS)
git_repository__cvar(&protectHFS, repo, GIT_CVAR_PROTECTHFS); error = git_repository__cvar(&protectHFS, repo, GIT_CVAR_PROTECTHFS);
if (protectHFS) if (!error && protectHFS)
flags |= GIT_PATH_REJECT_DOT_GIT_HFS; flags |= GIT_PATH_REJECT_DOT_GIT_HFS;
if (repo && !protectNTFS) if (repo && !protectNTFS)
git_repository__cvar(&protectNTFS, repo, GIT_CVAR_PROTECTNTFS); error = git_repository__cvar(&protectNTFS, repo, GIT_CVAR_PROTECTNTFS);
if (protectNTFS) if (!error && protectNTFS)
flags |= GIT_PATH_REJECT_DOT_GIT_NTFS; flags |= GIT_PATH_REJECT_DOT_GIT_NTFS;
return flags; return flags;
......
...@@ -1140,7 +1140,7 @@ out: ...@@ -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) static int maybe_append_head(refdb_fs_backend *backend, const git_reference *ref, const git_signature *who, const char *message)
{ {
int error; int error;
git_oid old_id = {{0}}; git_oid old_id;
git_reference *tmp = NULL, *head = NULL, *peeled = NULL; git_reference *tmp = NULL, *head = NULL, *peeled = NULL;
const char *name; const char *name;
...@@ -1148,7 +1148,8 @@ static int maybe_append_head(refdb_fs_backend *backend, const git_reference *ref ...@@ -1148,7 +1148,8 @@ static int maybe_append_head(refdb_fs_backend *backend, const git_reference *ref
return 0; return 0;
/* if we can't resolve, we use {0}*40 as old id */ /* 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) if ((error = git_reference_lookup(&head, backend->repo, GIT_HEAD_FILE)) < 0)
return error; return error;
......
...@@ -622,15 +622,25 @@ typedef struct { ...@@ -622,15 +622,25 @@ typedef struct {
static int update_wt_heads(git_repository *repo, const char *path, void *payload) static int update_wt_heads(git_repository *repo, const char *path, void *payload)
{ {
rename_cb_data *data = (rename_cb_data *) payload; rename_cb_data *data = (rename_cb_data *) payload;
git_reference *head; git_reference *head = NULL;
char *gitdir = 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 || if ((gitdir = git_path_dirname(path)) == NULL) {
git_reference_type(head) != GIT_REF_SYMBOLIC || error = -1;
git__strcmp(head->target.symbolic, data->old_name) != 0 ||
(gitdir = git_path_dirname(path)) == NULL)
goto out; 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 */ /* Update HEAD it was pointing to the reference being renamed */
if ((error = git_repository_create_head(gitdir, data->new_name)) < 0) { if ((error = git_repository_create_head(gitdir, data->new_name)) < 0) {
......
...@@ -212,7 +212,7 @@ int git_worktree_open_from_repository(git_worktree **out, git_repository *repo) ...@@ -212,7 +212,7 @@ int git_worktree_open_from_repository(git_worktree **out, git_repository *repo)
goto out; goto out;
out: out:
free(name); git__free(name);
git_buf_free(&parent); git_buf_free(&parent);
return error; return error;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment