Commit 55e0f53d by Russell Belfer

Fix various build warnings

This fixes various build warnings on Mac and Windows (64-bit).
parent 6950dca4
...@@ -39,10 +39,13 @@ git_reference *git_reference__alloc( ...@@ -39,10 +39,13 @@ git_reference *git_reference__alloc(
const char *symbolic) const char *symbolic)
{ {
git_reference *ref; git_reference *ref;
size_t namelen;
assert(refdb && name && ((oid && !symbolic) || (!oid && symbolic))); 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; return NULL;
if (oid) { if (oid) {
...@@ -51,12 +54,14 @@ git_reference *git_reference__alloc( ...@@ -51,12 +54,14 @@ git_reference *git_reference__alloc(
} else { } else {
ref->type = GIT_REF_SYMBOLIC; 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; return NULL;
} }
}
ref->db = refdb; ref->db = refdb;
strcpy(ref->name, name); memcpy(ref->name, name, namelen + 1);
return ref; return ref;
} }
......
...@@ -560,11 +560,11 @@ static int winhttp_stream_write_single( ...@@ -560,11 +560,11 @@ static int winhttp_stream_write_single(
return 0; 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; UUID uuid;
RPC_STATUS status = UuidCreate(&uuid); RPC_STATUS status = UuidCreate(&uuid);
int result; HRESULT result;
if (RPC_S_OK != status && if (RPC_S_OK != status &&
RPC_S_UUID_LOCAL_ONLY != status && RPC_S_UUID_LOCAL_ONLY != status &&
...@@ -573,17 +573,19 @@ static int put_uuid_string(LPWSTR buffer, DWORD buffer_len_cch) ...@@ -573,17 +573,19 @@ static int put_uuid_string(LPWSTR buffer, DWORD buffer_len_cch)
return -1; return -1;
} }
if (buffer_len_cch < (UUID_LENGTH_CCH + 1)) { if (buffer_len_cch < UUID_LENGTH_CCH + 1) {
giterr_set(GITERR_NET, "Buffer insufficient to generate temp file name"); giterr_set(GITERR_NET, "Buffer too small for name of temp file");
return -1; 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.Data1, uuid.Data2, uuid.Data3,
uuid.Data4[0], uuid.Data4[1], uuid.Data4[2], uuid.Data4[3], uuid.Data4[0], uuid.Data4[1], uuid.Data4[2], uuid.Data4[3],
uuid.Data4[4], uuid.Data4[5], uuid.Data4[6], uuid.Data4[7]); 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"); giterr_set(GITERR_OS, "Unable to generate name for temp file");
return -1; return -1;
} }
...@@ -602,17 +604,10 @@ static int get_temp_file(LPWSTR buffer, DWORD buffer_len_cch) ...@@ -602,17 +604,10 @@ static int get_temp_file(LPWSTR buffer, DWORD buffer_len_cch)
len = wcslen(buffer); len = wcslen(buffer);
/* 1 prefix character for the backslash, 1 postfix for if (buffer[len - 1] != '\\' && len < buffer_len_cch)
* 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] != '\\')
buffer[len++] = '\\'; 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 -1;
return 0; return 0;
......
...@@ -155,7 +155,7 @@ void test_commit_parse__signature(void) ...@@ -155,7 +155,7 @@ void test_commit_parse__signature(void)
cl_git_pass(git_signature__parse(&person, &str, str + len, passcase->header, '\n')); 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->name, person.name);
cl_assert_equal_s(passcase->email, person.email); 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); cl_assert_equal_i(passcase->offset, person.when.offset);
git__free(person.name); git__free(person.email); git__free(person.name); git__free(person.email);
} }
......
...@@ -19,7 +19,7 @@ void test_refs_pack__cleanup(void) ...@@ -19,7 +19,7 @@ void test_refs_pack__cleanup(void)
cl_git_sandbox_cleanup(); cl_git_sandbox_cleanup();
} }
void packall() static void packall(void)
{ {
git_refdb *refdb; git_refdb *refdb;
......
...@@ -5,6 +5,8 @@ static int written = 0; ...@@ -5,6 +5,8 @@ static int written = 0;
static void trace_callback(git_trace_level_t level, const char *message) static void trace_callback(git_trace_level_t level, const char *message)
{ {
GIT_UNUSED(level);
cl_assert(strcmp(message, "Hello world!") == 0); cl_assert(strcmp(message, "Hello world!") == 0);
written = 1; written = 1;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment