Merge pull request #6018 from libgit2/ethomson/fixups Fixes from code analysis
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146
diff --git a/src/date.c b/src/date.c
index 71bf631..2297ee6 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 3d1d1c9..ce883b2 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 f1d9614..dd7d2f7 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 43310ca..6b4fb83 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 9aab8b5..6a885ed 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 94b1ecd..aadf3f2 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 4612b43..d40c162 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;
}