Skip to content

A few more fixes from coverity #3201

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jun 10, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions src/filter.c
Original file line number Diff line number Diff line change
Expand Up @@ -887,7 +887,7 @@ int git_filter_list_stream_file(
git_vector filter_streams = GIT_VECTOR_INIT;
git_writestream *stream_start;
ssize_t readlen;
int fd, error;
int fd = -1, error;

if ((error = stream_list_init(
&stream_start, &filter_streams, filters, target)) < 0 ||
Expand All @@ -909,9 +909,10 @@ int git_filter_list_stream_file(
else if (readlen < 0)
error = readlen;

p_close(fd);

done:
if (fd >= 0)
p_close(fd);
stream_list_free(&filter_streams);
git_buf_free(&abspath);
return error;
Expand Down
4 changes: 2 additions & 2 deletions src/merge.c
Original file line number Diff line number Diff line change
Expand Up @@ -1143,9 +1143,9 @@ static void merge_diff_list_count_candidates(
if (GIT_MERGE_INDEX_ENTRY_EXISTS(entry->ancestor_entry) &&
(!GIT_MERGE_INDEX_ENTRY_EXISTS(entry->our_entry) ||
!GIT_MERGE_INDEX_ENTRY_EXISTS(entry->their_entry)))
src_count++;
(*src_count)++;
else if (!GIT_MERGE_INDEX_ENTRY_EXISTS(entry->ancestor_entry))
tgt_count++;
(*tgt_count)++;
}
}

Expand Down
10 changes: 5 additions & 5 deletions src/object.c
Original file line number Diff line number Diff line change
Expand Up @@ -129,10 +129,10 @@ int git_object_lookup_prefix(
if (error < 0)
return error;

if (len > GIT_OID_HEXSZ)
len = GIT_OID_HEXSZ;
if (len > GIT_OID_RAWSZ)
len = GIT_OID_RAWSZ;

if (len == GIT_OID_HEXSZ) {
if (len == GIT_OID_RAWSZ) {
git_cached_obj *cached = NULL;

/* We want to match the full id : we can first look up in the cache,
Expand Down Expand Up @@ -172,9 +172,9 @@ int git_object_lookup_prefix(
memcpy(short_oid.id, id->id, (len + 1) / 2);
if (len % 2)
short_oid.id[len / 2] &= 0xF0;
memset(short_oid.id + (len + 1) / 2, 0, (GIT_OID_HEXSZ - len) / 2);
memset(short_oid.id + (len + 1) / 2, 0, (GIT_OID_RAWSZ - len) / 2);

/* If len < GIT_OID_HEXSZ (a strict short oid was given), we have
/* If len < GIT_OID_RAWSZ (a strict short oid was given), we have
* 2 options :
* - We always search in the cache first. If we find that short oid is
* ambiguous, we can stop. But in all the other cases, we must then
Expand Down
21 changes: 11 additions & 10 deletions src/pack.c
Original file line number Diff line number Diff line change
Expand Up @@ -319,32 +319,33 @@ static int pack_index_check(const char *path, struct git_pack_file *p)

static int pack_index_open(struct git_pack_file *p)
{
char *idx_name;
int error = 0;
size_t name_len, base_len;
size_t name_len;
git_buf idx_name = GIT_BUF_INIT;

if (p->index_version > -1)
return 0;

name_len = strlen(p->pack_name);
assert(name_len > strlen(".pack")); /* checked by git_pack_file alloc */

if ((idx_name = git__malloc(name_len)) == NULL)
git_buf_grow(&idx_name, name_len);
git_buf_put(&idx_name, p->pack_name, name_len - strlen(".pack"));
git_buf_puts(&idx_name, ".idx");
if (git_buf_oom(&idx_name)) {
giterr_set_oom();
return -1;

base_len = name_len - strlen(".pack");
memcpy(idx_name, p->pack_name, base_len);
memcpy(idx_name + base_len, ".idx", sizeof(".idx"));
}

if ((error = git_mutex_lock(&p->lock)) < 0) {
git__free(idx_name);
git_buf_free(&idx_name);
return error;
}

if (p->index_version == -1)
error = pack_index_check(idx_name, p);
error = pack_index_check(idx_name.ptr, p);

git__free(idx_name);
git_buf_free(&idx_name);

git_mutex_unlock(&p->lock);

Expand Down