Skip to content

Commit db72980

Browse files
authored
Merge pull request libgit2#6018 from libgit2/ethomson/fixups
Fixes from code analysis
2 parents 969a056 + ed0ea96 commit db72980

File tree

7 files changed

+29
-15
lines changed

7 files changed

+29
-15
lines changed

src/date.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -722,7 +722,7 @@ static const char *approxidate_alpha(const char *date, struct tm *tm, struct tm
722722
while (tl->type) {
723723
size_t len = strlen(tl->type);
724724
if (match_string(date, tl->type) >= len-1) {
725-
update_tm(tm, now, tl->length * *num);
725+
update_tm(tm, now, tl->length * (unsigned long)*num);
726726
*num = 0;
727727
*touched = 1;
728728
return end;

src/errors.c

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -107,11 +107,6 @@ int git_error_set_str(int error_class, const char *string)
107107

108108
GIT_ASSERT_ARG(string);
109109

110-
if (!string) {
111-
git_error_set(GIT_ERROR_INVALID, "unspecified caller error");
112-
return -1;
113-
}
114-
115110
git_buf_clear(buf);
116111
git_buf_puts(buf, string);
117112

src/filter.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,8 @@ int git_filter_global_init(void)
206206
GIT_FILTER_IDENT, ident, GIT_FILTER_IDENT_PRIORITY) < 0)
207207
error = -1;
208208

209-
error = git_runtime_shutdown_register(git_filter_global_shutdown);
209+
if (!error)
210+
error = git_runtime_shutdown_register(git_filter_global_shutdown);
210211

211212
done:
212213
if (error) {

src/hashsig.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -286,8 +286,10 @@ int git_hashsig_create_fromfile(
286286
return fd;
287287
}
288288

289-
if ((error = hashsig_in_progress_init(&prog, sig)) < 0)
289+
if ((error = hashsig_in_progress_init(&prog, sig)) < 0) {
290+
p_close(fd);
290291
return error;
292+
}
291293

292294
while (!error) {
293295
if ((buflen = p_read(fd, buf, sizeof(buf))) <= 0) {

src/midx.c

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -714,8 +714,10 @@ static int midx_write(
714714
error = git_vector_init(&object_entries, git_array_size(object_entries_array), object_entry__cmp);
715715
if (error < 0)
716716
goto cleanup;
717-
git_array_foreach (object_entries_array, i, entry)
718-
error = git_vector_set(NULL, &object_entries, i, entry);
717+
git_array_foreach (object_entries_array, i, entry) {
718+
if ((error = git_vector_set(NULL, &object_entries, i, entry)) < 0)
719+
goto cleanup;
720+
}
719721
git_vector_set_sorted(&object_entries, 0);
720722
git_vector_sort(&object_entries);
721723
git_vector_uniq(&object_entries, NULL);
@@ -751,10 +753,12 @@ static int midx_write(
751753
goto cleanup;
752754
if (entry->offset >= 0x80000000l) {
753755
word = htonl(0x80000000u | object_large_offsets_count++);
754-
error = write_offset(entry->offset, midx_write_buf, &object_large_offsets);
756+
if ((error = write_offset(entry->offset, midx_write_buf, &object_large_offsets)) < 0)
757+
goto cleanup;
755758
} else {
756759
word = htonl((uint32_t)entry->offset & 0x7fffffffu);
757760
}
761+
758762
error = git_buf_put(&object_offsets, (const char *)&word, sizeof(word));
759763
if (error < 0)
760764
goto cleanup;

src/pack.c

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1298,7 +1298,12 @@ int git_pack_foreach_entry(
12981298
return error;
12991299
}
13001300

1301-
GIT_ASSERT(p->index_map.data);
1301+
if (!p->index_map.data) {
1302+
git_error_set(GIT_ERROR_INTERNAL, "internal error: p->index_map.data == NULL");
1303+
git_mutex_unlock(&p->lock);
1304+
return -1;
1305+
}
1306+
13021307
index = p->index_map.data;
13031308

13041309
if (p->index_version > 1)
@@ -1387,7 +1392,11 @@ int git_pack_foreach_entry_offset(
13871392
if ((error = pack_index_open_locked(p)) < 0)
13881393
goto cleanup;
13891394

1390-
GIT_ASSERT(p->index_map.data);
1395+
if (!p->index_map.data) {
1396+
git_error_set(GIT_ERROR_INTERNAL, "internal error: p->index_map.data == NULL");
1397+
goto cleanup;
1398+
}
1399+
13911400
index = p->index_map.data;
13921401
}
13931402

@@ -1479,7 +1488,11 @@ static int pack_entry_find_offset(
14791488
if ((error = pack_index_open_locked(p)) < 0)
14801489
goto cleanup;
14811490

1482-
GIT_ASSERT(p->index_map.data);
1491+
if (!p->index_map.data) {
1492+
git_error_set(GIT_ERROR_INTERNAL, "internal error: p->index_map.data == NULL");
1493+
goto cleanup;
1494+
}
1495+
14831496
index = p->index_map.data;
14841497
level1_ofs = p->index_map.data;
14851498

src/transports/httpclient.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -598,7 +598,6 @@ static int apply_credentials(
598598
} else if (!token.size) {
599599
git_error_set(GIT_ERROR_HTTP, "failed to respond to authentication challenge");
600600
error = GIT_EAUTH;
601-
error = -1;
602601
goto done;
603602
}
604603

0 commit comments

Comments
 (0)