Skip to content

Commit da6720f

Browse files
committed
Merge pull request libgit2#3201 from libgit2/cmn/coverity
A few more fixes from coverity
2 parents 2d73075 + 0137aba commit da6720f

File tree

4 files changed

+21
-19
lines changed

4 files changed

+21
-19
lines changed

src/filter.c

+3-2
Original file line numberDiff line numberDiff line change
@@ -887,7 +887,7 @@ int git_filter_list_stream_file(
887887
git_vector filter_streams = GIT_VECTOR_INIT;
888888
git_writestream *stream_start;
889889
ssize_t readlen;
890-
int fd, error;
890+
int fd = -1, error;
891891

892892
if ((error = stream_list_init(
893893
&stream_start, &filter_streams, filters, target)) < 0 ||
@@ -909,9 +909,10 @@ int git_filter_list_stream_file(
909909
else if (readlen < 0)
910910
error = readlen;
911911

912-
p_close(fd);
913912

914913
done:
914+
if (fd >= 0)
915+
p_close(fd);
915916
stream_list_free(&filter_streams);
916917
git_buf_free(&abspath);
917918
return error;

src/merge.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -1143,9 +1143,9 @@ static void merge_diff_list_count_candidates(
11431143
if (GIT_MERGE_INDEX_ENTRY_EXISTS(entry->ancestor_entry) &&
11441144
(!GIT_MERGE_INDEX_ENTRY_EXISTS(entry->our_entry) ||
11451145
!GIT_MERGE_INDEX_ENTRY_EXISTS(entry->their_entry)))
1146-
src_count++;
1146+
(*src_count)++;
11471147
else if (!GIT_MERGE_INDEX_ENTRY_EXISTS(entry->ancestor_entry))
1148-
tgt_count++;
1148+
(*tgt_count)++;
11491149
}
11501150
}
11511151

src/object.c

+5-5
Original file line numberDiff line numberDiff line change
@@ -129,10 +129,10 @@ int git_object_lookup_prefix(
129129
if (error < 0)
130130
return error;
131131

132-
if (len > GIT_OID_HEXSZ)
133-
len = GIT_OID_HEXSZ;
132+
if (len > GIT_OID_RAWSZ)
133+
len = GIT_OID_RAWSZ;
134134

135-
if (len == GIT_OID_HEXSZ) {
135+
if (len == GIT_OID_RAWSZ) {
136136
git_cached_obj *cached = NULL;
137137

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

177-
/* If len < GIT_OID_HEXSZ (a strict short oid was given), we have
177+
/* If len < GIT_OID_RAWSZ (a strict short oid was given), we have
178178
* 2 options :
179179
* - We always search in the cache first. If we find that short oid is
180180
* ambiguous, we can stop. But in all the other cases, we must then

src/pack.c

+11-10
Original file line numberDiff line numberDiff line change
@@ -319,32 +319,33 @@ static int pack_index_check(const char *path, struct git_pack_file *p)
319319

320320
static int pack_index_open(struct git_pack_file *p)
321321
{
322-
char *idx_name;
323322
int error = 0;
324-
size_t name_len, base_len;
323+
size_t name_len;
324+
git_buf idx_name = GIT_BUF_INIT;
325325

326326
if (p->index_version > -1)
327327
return 0;
328328

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

332-
if ((idx_name = git__malloc(name_len)) == NULL)
332+
git_buf_grow(&idx_name, name_len);
333+
git_buf_put(&idx_name, p->pack_name, name_len - strlen(".pack"));
334+
git_buf_puts(&idx_name, ".idx");
335+
if (git_buf_oom(&idx_name)) {
336+
giterr_set_oom();
333337
return -1;
334-
335-
base_len = name_len - strlen(".pack");
336-
memcpy(idx_name, p->pack_name, base_len);
337-
memcpy(idx_name + base_len, ".idx", sizeof(".idx"));
338+
}
338339

339340
if ((error = git_mutex_lock(&p->lock)) < 0) {
340-
git__free(idx_name);
341+
git_buf_free(&idx_name);
341342
return error;
342343
}
343344

344345
if (p->index_version == -1)
345-
error = pack_index_check(idx_name, p);
346+
error = pack_index_check(idx_name.ptr, p);
346347

347-
git__free(idx_name);
348+
git_buf_free(&idx_name);
348349

349350
git_mutex_unlock(&p->lock);
350351

0 commit comments

Comments
 (0)