Commit e953c160 by Vicent Martí

Merge pull request #1414 from arrbee/more-build-warning-fixes

Fix various build warnings
parents 6950dca4 55e0f53d
......@@ -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;
......
......@@ -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;
......
......@@ -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);
}
......
......@@ -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));
}
......
......@@ -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;
......
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