Commit 7b453e7e by lhchavez

Fix a bunch of warnings

This change fixes a bunch of warnings that were discovered by compiling
with `clang -target=i386-pc-linux-gnu`. It turned out that the
intrinsics were not necessarily being used in all platforms! Especially
in GCC, since it does not support __has_builtin.

Some more warnings were gleaned from the Windows build, but I stopped
when I saw that some third-party dependencies (e.g. zlib) have warnings
of their own, so we might never be able to enable -Werror there.
parent fba70a9d
......@@ -55,16 +55,18 @@ GIT_INLINE(bool) git__add_uint64_overflow(uint64_t *out, uint64_t one, uint64_t
}
/* Use clang/gcc compiler intrinsics whenever possible */
#if (SIZE_MAX == ULONG_MAX) && __has_builtin(__builtin_uaddl_overflow)
#if (SIZE_MAX == ULLONG_MAX) && (__has_builtin(__builtin_uaddl_overflow) || \
(defined(__GNUC__) && (__GNUC__ >= 5)))
# define git__add_sizet_overflow(out, one, two) \
__builtin_uaddl_overflow(one, two, out)
# define git__multiply_sizet_overflow(out, one, two) \
__builtin_umull_overflow(one, two, out)
#elif (SIZE_MAX == UINT_MAX) && __has_builtin(__builtin_uadd_overflow)
#elif (__has_builtin(__builtin_add_overflow) || \
(defined(__GNUC__) && (__GNUC__ >= 5)))
# define git__add_sizet_overflow(out, one, two) \
__builtin_uadd_overflow(one, two, out)
__builtin_add_overflow(one, two, out)
# define git__multiply_sizet_overflow(out, one, two) \
__builtin_umul_overflow(one, two, out)
__builtin_mul_overflow(one, two, out)
#else
/**
......
......@@ -95,7 +95,7 @@ int git_odb__format_object_header(
int hdr_max = (hdr_size > INT_MAX-2) ? (INT_MAX-2) : (int)hdr_size;
int len;
len = p_snprintf(hdr, hdr_max, "%s %lld", type_str, (long long)obj_len);
len = p_snprintf(hdr, hdr_max, "%s %"PRId64, type_str, (int64_t)obj_len);
if (len < 0 || len >= hdr_max) {
giterr_set(GITERR_OS, "object header creation failed");
......
......@@ -38,7 +38,7 @@ static void net_set_error(const char *str)
giterr_set(GITERR_NET, "%s: %s", str, win32_error);
git__free(win32_error);
} else {
giterr_set(GITERR_NET, str);
giterr_set(GITERR_NET, "%s", str);
}
}
#else
......
......@@ -329,34 +329,6 @@ static void winhttp_stream_close(winhttp_stream *s)
s->sent_request = 0;
}
/**
* Extract the url and password from a URL. The outputs are pointers
* into the input.
*/
static int userpass_from_url(wchar_t **user, int *user_len,
wchar_t **pass, int *pass_len,
const wchar_t *url, int url_len)
{
URL_COMPONENTS components = { 0 };
components.dwStructSize = sizeof(components);
/* These tell WinHttpCrackUrl that we're interested in the fields */
components.dwUserNameLength = 1;
components.dwPasswordLength = 1;
if (!WinHttpCrackUrl(url, url_len, 0, &components)) {
giterr_set(GITERR_OS, "failed to extract user/pass from url");
return -1;
}
*user = components.lpszUserName;
*user_len = components.dwUserNameLength;
*pass = components.lpszPassword;
*pass_len = components.dwPasswordLength;
return 0;
}
#define SCHEME_HTTP "http://"
#define SCHEME_HTTPS "https://"
......@@ -659,7 +631,7 @@ static int write_chunk(HINTERNET request, const char *buffer, size_t len)
git_buf buf = GIT_BUF_INIT;
/* Chunk header */
git_buf_printf(&buf, "%X\r\n", len);
git_buf_printf(&buf, "%zX\r\n", len);
if (git_buf_oom(&buf))
return -1;
......@@ -747,7 +719,7 @@ static void CALLBACK winhttp_status(
else if ((status & WINHTTP_CALLBACK_STATUS_FLAG_SECURITY_CHANNEL_ERROR))
giterr_set(GITERR_NET, "security libraries could not be loaded");
else
giterr_set(GITERR_NET, "unknown security error %d", status);
giterr_set(GITERR_NET, "unknown security error %lu", status);
}
static int winhttp_connect(
......@@ -870,7 +842,7 @@ static int do_send_request(winhttp_stream *s, size_t len, int ignore_length)
len, 0);
}
if (success || GetLastError() != SEC_E_BUFFER_TOO_SMALL)
if (success || GetLastError() != (DWORD)SEC_E_BUFFER_TOO_SMALL)
break;
}
......@@ -1170,7 +1142,7 @@ replay:
}
if (HTTP_STATUS_OK != status_code) {
giterr_set(GITERR_NET, "request failed with status code: %d", status_code);
giterr_set(GITERR_NET, "request failed with status code: %lu", status_code);
return -1;
}
......
......@@ -397,7 +397,6 @@ int p_readlink(const char *path, char *buf, size_t bufsiz)
int p_symlink(const char *target, const char *path)
{
git_win32_path target_w, path_w;
wchar_t *target_p;
if (git_win32_path_from_utf8(path_w, path) < 0 ||
git__utf8_to_16(target_w, MAX_PATH, target) < 0)
......
......@@ -512,7 +512,7 @@ void test_revwalk_basic__big_timestamp(void)
cl_git_pass(git_reference_peel((git_object **) &tip, head, GIT_OBJECT_COMMIT));
/* Commit with a far-ahead timestamp, we should be able to parse it in the revwalk */
cl_git_pass(git_signature_new(&sig, "Joe", "joe@example.com", 2399662595, 0));
cl_git_pass(git_signature_new(&sig, "Joe", "joe@example.com", 2399662595ll, 0));
cl_git_pass(git_commit_tree(&tree, tip));
cl_git_pass(git_commit_create(&id, _repo, "HEAD", sig, sig, NULL, "some message", tree, 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