Merge pull request #1414 from arrbee/more-build-warning-fixes Fix various build warnings
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 147 148 149 150 151 152 153 154
diff --git a/src/refs.c b/src/refs.c
index 80307c9..41c6fd8 100644
--- a/src/refs.c
+++ b/src/refs.c
@@ -39,10 +39,13 @@ git_reference *git_reference__alloc(
const char *symbolic)
{
git_reference *ref;
+ size_t namelen;
assert(refdb && name && ((oid && !symbolic) || (!oid && symbolic)));
-
- if ((ref = git__calloc(1, sizeof(git_reference) + strlen(name) + 1)) == NULL)
+
+ namelen = strlen(name);
+
+ if ((ref = git__calloc(1, sizeof(git_reference) + namelen + 1)) == NULL)
return NULL;
if (oid) {
@@ -51,13 +54,15 @@ git_reference *git_reference__alloc(
} else {
ref->type = GIT_REF_SYMBOLIC;
- if ((ref->target.symbolic = git__strdup(symbolic)) == NULL)
+ if ((ref->target.symbolic = git__strdup(symbolic)) == NULL) {
+ git__free(ref);
return NULL;
+ }
}
-
+
ref->db = refdb;
- strcpy(ref->name, name);
-
+ memcpy(ref->name, name, namelen + 1);
+
return ref;
}
@@ -70,7 +75,7 @@ void git_reference_free(git_reference *reference)
git__free(reference->target.symbolic);
reference->target.symbolic = NULL;
}
-
+
reference->db = NULL;
reference->type = GIT_REF_INVALID;
diff --git a/src/transports/winhttp.c b/src/transports/winhttp.c
index 970fa53..d4d0179 100644
--- a/src/transports/winhttp.c
+++ b/src/transports/winhttp.c
@@ -560,11 +560,11 @@ static int winhttp_stream_write_single(
return 0;
}
-static int put_uuid_string(LPWSTR buffer, DWORD buffer_len_cch)
+static int put_uuid_string(LPWSTR buffer, size_t buffer_len_cch)
{
UUID uuid;
RPC_STATUS status = UuidCreate(&uuid);
- int result;
+ HRESULT result;
if (RPC_S_OK != status &&
RPC_S_UUID_LOCAL_ONLY != status &&
@@ -573,17 +573,19 @@ static int put_uuid_string(LPWSTR buffer, DWORD buffer_len_cch)
return -1;
}
- if (buffer_len_cch < (UUID_LENGTH_CCH + 1)) {
- giterr_set(GITERR_NET, "Buffer insufficient to generate temp file name");
+ if (buffer_len_cch < UUID_LENGTH_CCH + 1) {
+ giterr_set(GITERR_NET, "Buffer too small for name of temp file");
return -1;
}
- result = wsprintfW(buffer, L"%08x%04x%04x%02x%02x%02x%02x%02x%02x%02x%02x",
+ result = StringCbPrintfW(
+ buffer, buffer_len_cch,
+ L"%08x%04x%04x%02x%02x%02x%02x%02x%02x%02x%02x",
uuid.Data1, uuid.Data2, uuid.Data3,
uuid.Data4[0], uuid.Data4[1], uuid.Data4[2], uuid.Data4[3],
uuid.Data4[4], uuid.Data4[5], uuid.Data4[6], uuid.Data4[7]);
- if (result != UUID_LENGTH_CCH) {
+ if (FAILED(result)) {
giterr_set(GITERR_OS, "Unable to generate name for temp file");
return -1;
}
@@ -602,17 +604,10 @@ static int get_temp_file(LPWSTR buffer, DWORD buffer_len_cch)
len = wcslen(buffer);
- /* 1 prefix character for the backslash, 1 postfix for
- * the null terminator */
- if (buffer_len_cch - len < 1 + UUID_LENGTH_CCH + 1) {
- giterr_set(GITERR_NET, "Buffer insufficient to generate temp file name");
- return -1;
- }
-
- if (buffer[len - 1] != '\\')
+ if (buffer[len - 1] != '\\' && len < buffer_len_cch)
buffer[len++] = '\\';
- if (put_uuid_string(&buffer[len], UUID_LENGTH_CCH + 1) < 0)
+ if (put_uuid_string(&buffer[len], (size_t)buffer_len_cch - len) < 0)
return -1;
return 0;
diff --git a/tests-clar/commit/parse.c b/tests-clar/commit/parse.c
index 37f27b0..95c6285 100644
--- a/tests-clar/commit/parse.c
+++ b/tests-clar/commit/parse.c
@@ -155,7 +155,7 @@ void test_commit_parse__signature(void)
cl_git_pass(git_signature__parse(&person, &str, str + len, passcase->header, '\n'));
cl_assert_equal_s(passcase->name, person.name);
cl_assert_equal_s(passcase->email, person.email);
- cl_assert_equal_i(passcase->time, person.when.time);
+ cl_assert_equal_i((int)passcase->time, (int)person.when.time);
cl_assert_equal_i(passcase->offset, person.when.offset);
git__free(person.name); git__free(person.email);
}
diff --git a/tests-clar/refs/pack.c b/tests-clar/refs/pack.c
index 8da36cc..973abae 100644
--- a/tests-clar/refs/pack.c
+++ b/tests-clar/refs/pack.c
@@ -19,10 +19,10 @@ void test_refs_pack__cleanup(void)
cl_git_sandbox_cleanup();
}
-void packall()
+static void packall(void)
{
git_refdb *refdb;
-
+
cl_git_pass(git_repository_refdb(&refdb, g_repo));
cl_git_pass(git_refdb_compress(refdb));
}
diff --git a/tests-clar/trace/trace.c b/tests-clar/trace/trace.c
index 712fe62..cc99cd1 100644
--- a/tests-clar/trace/trace.c
+++ b/tests-clar/trace/trace.c
@@ -5,6 +5,8 @@ static int written = 0;
static void trace_callback(git_trace_level_t level, const char *message)
{
+ GIT_UNUSED(level);
+
cl_assert(strcmp(message, "Hello world!") == 0);
written = 1;