summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEdward Thomson <ethomson@edwardthomson.com>2021-08-30 09:24:48 -0400
committerGitHub <noreply@github.com>2021-08-30 09:24:48 -0400
commitdb72980323d3000411c18790d96556719c54a44f (patch)
treeb0b6523a8eafd522af1969e5cf341c56d0da792c
parent969a056cc5b03d49c336a4e58c290efc052e79fb (diff)
parented0ea96ed9ab19c0757a7b81619ace39e71a22c5 (diff)
downloadlibgit2-db72980323d3000411c18790d96556719c54a44f.tar.gz
Merge pull request #6018 from libgit2/ethomson/fixups
Fixes from code analysis
-rw-r--r--src/date.c2
-rw-r--r--src/errors.c5
-rw-r--r--src/filter.c3
-rw-r--r--src/hashsig.c4
-rw-r--r--src/midx.c10
-rw-r--r--src/pack.c19
-rw-r--r--src/transports/httpclient.c1
7 files changed, 29 insertions, 15 deletions
diff --git a/src/date.c b/src/date.c
index 71bf631a0..2297ee66c 100644
--- a/src/date.c
+++ b/src/date.c
@@ -722,7 +722,7 @@ static const char *approxidate_alpha(const char *date, struct tm *tm, struct tm
while (tl->type) {
size_t len = strlen(tl->type);
if (match_string(date, tl->type) >= len-1) {
- update_tm(tm, now, tl->length * *num);
+ update_tm(tm, now, tl->length * (unsigned long)*num);
*num = 0;
*touched = 1;
return end;
diff --git a/src/errors.c b/src/errors.c
index 3d1d1c9a1..ce883b2da 100644
--- a/src/errors.c
+++ b/src/errors.c
@@ -107,11 +107,6 @@ int git_error_set_str(int error_class, const char *string)
GIT_ASSERT_ARG(string);
- if (!string) {
- git_error_set(GIT_ERROR_INVALID, "unspecified caller error");
- return -1;
- }
-
git_buf_clear(buf);
git_buf_puts(buf, string);
diff --git a/src/filter.c b/src/filter.c
index f1d961406..dd7d2f7ec 100644
--- a/src/filter.c
+++ b/src/filter.c
@@ -206,7 +206,8 @@ int git_filter_global_init(void)
GIT_FILTER_IDENT, ident, GIT_FILTER_IDENT_PRIORITY) < 0)
error = -1;
- error = git_runtime_shutdown_register(git_filter_global_shutdown);
+ if (!error)
+ error = git_runtime_shutdown_register(git_filter_global_shutdown);
done:
if (error) {
diff --git a/src/hashsig.c b/src/hashsig.c
index 43310ca48..6b4fb8352 100644
--- a/src/hashsig.c
+++ b/src/hashsig.c
@@ -286,8 +286,10 @@ int git_hashsig_create_fromfile(
return fd;
}
- if ((error = hashsig_in_progress_init(&prog, sig)) < 0)
+ if ((error = hashsig_in_progress_init(&prog, sig)) < 0) {
+ p_close(fd);
return error;
+ }
while (!error) {
if ((buflen = p_read(fd, buf, sizeof(buf))) <= 0) {
diff --git a/src/midx.c b/src/midx.c
index 9aab8b588..6a885eddc 100644
--- a/src/midx.c
+++ b/src/midx.c
@@ -714,8 +714,10 @@ static int midx_write(
error = git_vector_init(&object_entries, git_array_size(object_entries_array), object_entry__cmp);
if (error < 0)
goto cleanup;
- git_array_foreach (object_entries_array, i, entry)
- error = git_vector_set(NULL, &object_entries, i, entry);
+ git_array_foreach (object_entries_array, i, entry) {
+ if ((error = git_vector_set(NULL, &object_entries, i, entry)) < 0)
+ goto cleanup;
+ }
git_vector_set_sorted(&object_entries, 0);
git_vector_sort(&object_entries);
git_vector_uniq(&object_entries, NULL);
@@ -751,10 +753,12 @@ static int midx_write(
goto cleanup;
if (entry->offset >= 0x80000000l) {
word = htonl(0x80000000u | object_large_offsets_count++);
- error = write_offset(entry->offset, midx_write_buf, &object_large_offsets);
+ if ((error = write_offset(entry->offset, midx_write_buf, &object_large_offsets)) < 0)
+ goto cleanup;
} else {
word = htonl((uint32_t)entry->offset & 0x7fffffffu);
}
+
error = git_buf_put(&object_offsets, (const char *)&word, sizeof(word));
if (error < 0)
goto cleanup;
diff --git a/src/pack.c b/src/pack.c
index 94b1ecd9d..aadf3f2be 100644
--- a/src/pack.c
+++ b/src/pack.c
@@ -1298,7 +1298,12 @@ int git_pack_foreach_entry(
return error;
}
- GIT_ASSERT(p->index_map.data);
+ if (!p->index_map.data) {
+ git_error_set(GIT_ERROR_INTERNAL, "internal error: p->index_map.data == NULL");
+ git_mutex_unlock(&p->lock);
+ return -1;
+ }
+
index = p->index_map.data;
if (p->index_version > 1)
@@ -1387,7 +1392,11 @@ int git_pack_foreach_entry_offset(
if ((error = pack_index_open_locked(p)) < 0)
goto cleanup;
- GIT_ASSERT(p->index_map.data);
+ if (!p->index_map.data) {
+ git_error_set(GIT_ERROR_INTERNAL, "internal error: p->index_map.data == NULL");
+ goto cleanup;
+ }
+
index = p->index_map.data;
}
@@ -1479,7 +1488,11 @@ static int pack_entry_find_offset(
if ((error = pack_index_open_locked(p)) < 0)
goto cleanup;
- GIT_ASSERT(p->index_map.data);
+ if (!p->index_map.data) {
+ git_error_set(GIT_ERROR_INTERNAL, "internal error: p->index_map.data == NULL");
+ goto cleanup;
+ }
+
index = p->index_map.data;
level1_ofs = p->index_map.data;
diff --git a/src/transports/httpclient.c b/src/transports/httpclient.c
index 4612b4334..d40c1627c 100644
--- a/src/transports/httpclient.c
+++ b/src/transports/httpclient.c
@@ -598,7 +598,6 @@ static int apply_credentials(
} else if (!token.size) {
git_error_set(GIT_ERROR_HTTP, "failed to respond to authentication challenge");
error = GIT_EAUTH;
- error = -1;
goto done;
}