Skip to content

Commit 90500d8

Browse files
authored
Merge pull request libgit2#4253 from pks-t/pks/cov-fixes
Coverity fixes
2 parents 3a8801a + 90388aa commit 90500d8

File tree

5 files changed

+31
-15
lines changed

5 files changed

+31
-15
lines changed

src/fileops.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1155,9 +1155,13 @@ int git_futils_fsync_dir(const char *path)
11551155

11561156
int git_futils_fsync_parent(const char *path)
11571157
{
1158-
char *parent = git_path_dirname(path);
1159-
int error = git_futils_fsync_dir(parent);
1158+
char *parent;
1159+
int error;
1160+
1161+
if ((parent = git_path_dirname(path)) == NULL)
1162+
return -1;
11601163

1164+
error = git_futils_fsync_dir(parent);
11611165
git__free(parent);
11621166
return error;
11631167
}

src/path.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1708,6 +1708,7 @@ GIT_INLINE(unsigned int) dotgit_flags(
17081708
unsigned int flags)
17091709
{
17101710
int protectHFS = 0, protectNTFS = 0;
1711+
int error = 0;
17111712

17121713
flags |= GIT_PATH_REJECT_DOT_GIT_LITERAL;
17131714

@@ -1720,13 +1721,13 @@ GIT_INLINE(unsigned int) dotgit_flags(
17201721
#endif
17211722

17221723
if (repo && !protectHFS)
1723-
git_repository__cvar(&protectHFS, repo, GIT_CVAR_PROTECTHFS);
1724-
if (protectHFS)
1724+
error = git_repository__cvar(&protectHFS, repo, GIT_CVAR_PROTECTHFS);
1725+
if (!error && protectHFS)
17251726
flags |= GIT_PATH_REJECT_DOT_GIT_HFS;
17261727

17271728
if (repo && !protectNTFS)
1728-
git_repository__cvar(&protectNTFS, repo, GIT_CVAR_PROTECTNTFS);
1729-
if (protectNTFS)
1729+
error = git_repository__cvar(&protectNTFS, repo, GIT_CVAR_PROTECTNTFS);
1730+
if (!error && protectNTFS)
17301731
flags |= GIT_PATH_REJECT_DOT_GIT_NTFS;
17311732

17321733
return flags;

src/refdb_fs.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1140,15 +1140,16 @@ static int cmp_old_ref(int *cmp, git_refdb_backend *backend, const char *name,
11401140
static int maybe_append_head(refdb_fs_backend *backend, const git_reference *ref, const git_signature *who, const char *message)
11411141
{
11421142
int error;
1143-
git_oid old_id = {{0}};
1143+
git_oid old_id;
11441144
git_reference *tmp = NULL, *head = NULL, *peeled = NULL;
11451145
const char *name;
11461146

11471147
if (ref->type == GIT_REF_SYMBOLIC)
11481148
return 0;
11491149

11501150
/* if we can't resolve, we use {0}*40 as old id */
1151-
git_reference_name_to_id(&old_id, backend->repo, ref->name);
1151+
if (git_reference_name_to_id(&old_id, backend->repo, ref->name) < 0)
1152+
memset(&old_id, 0, sizeof(old_id));
11521153

11531154
if ((error = git_reference_lookup(&head, backend->repo, GIT_HEAD_FILE)) < 0)
11541155
return error;

src/refs.c

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -622,15 +622,25 @@ typedef struct {
622622
static int update_wt_heads(git_repository *repo, const char *path, void *payload)
623623
{
624624
rename_cb_data *data = (rename_cb_data *) payload;
625-
git_reference *head;
625+
git_reference *head = NULL;
626626
char *gitdir = NULL;
627-
int error = 0;
627+
int error;
628+
629+
if ((error = git_reference__read_head(&head, repo, path)) < 0) {
630+
giterr_set(GITERR_REFERENCE, "could not read HEAD when renaming references");
631+
goto out;
632+
}
628633

629-
if (git_reference__read_head(&head, repo, path) < 0 ||
630-
git_reference_type(head) != GIT_REF_SYMBOLIC ||
631-
git__strcmp(head->target.symbolic, data->old_name) != 0 ||
632-
(gitdir = git_path_dirname(path)) == NULL)
634+
if ((gitdir = git_path_dirname(path)) == NULL) {
635+
error = -1;
633636
goto out;
637+
}
638+
639+
if (git_reference_type(head) != GIT_REF_SYMBOLIC ||
640+
git__strcmp(head->target.symbolic, data->old_name) != 0) {
641+
error = 0;
642+
goto out;
643+
}
634644

635645
/* Update HEAD it was pointing to the reference being renamed */
636646
if ((error = git_repository_create_head(gitdir, data->new_name)) < 0) {

src/worktree.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ int git_worktree_open_from_repository(git_worktree **out, git_repository *repo)
212212
goto out;
213213

214214
out:
215-
free(name);
215+
git__free(name);
216216
git_buf_free(&parent);
217217

218218
return error;

0 commit comments

Comments
 (0)