Skip to content

Commit 7b453e7

Browse files
committed
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.
1 parent fba70a9 commit 7b453e7

File tree

6 files changed

+13
-40
lines changed

6 files changed

+13
-40
lines changed

src/integer.h

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,16 +55,18 @@ GIT_INLINE(bool) git__add_uint64_overflow(uint64_t *out, uint64_t one, uint64_t
5555
}
5656

5757
/* Use clang/gcc compiler intrinsics whenever possible */
58-
#if (SIZE_MAX == ULONG_MAX) && __has_builtin(__builtin_uaddl_overflow)
58+
#if (SIZE_MAX == ULLONG_MAX) && (__has_builtin(__builtin_uaddl_overflow) || \
59+
(defined(__GNUC__) && (__GNUC__ >= 5)))
5960
# define git__add_sizet_overflow(out, one, two) \
6061
__builtin_uaddl_overflow(one, two, out)
6162
# define git__multiply_sizet_overflow(out, one, two) \
6263
__builtin_umull_overflow(one, two, out)
63-
#elif (SIZE_MAX == UINT_MAX) && __has_builtin(__builtin_uadd_overflow)
64+
#elif (__has_builtin(__builtin_add_overflow) || \
65+
(defined(__GNUC__) && (__GNUC__ >= 5)))
6466
# define git__add_sizet_overflow(out, one, two) \
65-
__builtin_uadd_overflow(one, two, out)
67+
__builtin_add_overflow(one, two, out)
6668
# define git__multiply_sizet_overflow(out, one, two) \
67-
__builtin_umul_overflow(one, two, out)
69+
__builtin_mul_overflow(one, two, out)
6870
#else
6971

7072
/**

src/odb.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ int git_odb__format_object_header(
9595
int hdr_max = (hdr_size > INT_MAX-2) ? (INT_MAX-2) : (int)hdr_size;
9696
int len;
9797

98-
len = p_snprintf(hdr, hdr_max, "%s %lld", type_str, (long long)obj_len);
98+
len = p_snprintf(hdr, hdr_max, "%s %"PRId64, type_str, (int64_t)obj_len);
9999

100100
if (len < 0 || len >= hdr_max) {
101101
giterr_set(GITERR_OS, "object header creation failed");

src/streams/socket.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ static void net_set_error(const char *str)
3838
giterr_set(GITERR_NET, "%s: %s", str, win32_error);
3939
git__free(win32_error);
4040
} else {
41-
giterr_set(GITERR_NET, str);
41+
giterr_set(GITERR_NET, "%s", str);
4242
}
4343
}
4444
#else

src/transports/winhttp.c

Lines changed: 4 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -329,34 +329,6 @@ static void winhttp_stream_close(winhttp_stream *s)
329329
s->sent_request = 0;
330330
}
331331

332-
/**
333-
* Extract the url and password from a URL. The outputs are pointers
334-
* into the input.
335-
*/
336-
static int userpass_from_url(wchar_t **user, int *user_len,
337-
wchar_t **pass, int *pass_len,
338-
const wchar_t *url, int url_len)
339-
{
340-
URL_COMPONENTS components = { 0 };
341-
342-
components.dwStructSize = sizeof(components);
343-
/* These tell WinHttpCrackUrl that we're interested in the fields */
344-
components.dwUserNameLength = 1;
345-
components.dwPasswordLength = 1;
346-
347-
if (!WinHttpCrackUrl(url, url_len, 0, &components)) {
348-
giterr_set(GITERR_OS, "failed to extract user/pass from url");
349-
return -1;
350-
}
351-
352-
*user = components.lpszUserName;
353-
*user_len = components.dwUserNameLength;
354-
*pass = components.lpszPassword;
355-
*pass_len = components.dwPasswordLength;
356-
357-
return 0;
358-
}
359-
360332
#define SCHEME_HTTP "http://"
361333
#define SCHEME_HTTPS "https://"
362334

@@ -659,7 +631,7 @@ static int write_chunk(HINTERNET request, const char *buffer, size_t len)
659631
git_buf buf = GIT_BUF_INIT;
660632

661633
/* Chunk header */
662-
git_buf_printf(&buf, "%X\r\n", len);
634+
git_buf_printf(&buf, "%zX\r\n", len);
663635

664636
if (git_buf_oom(&buf))
665637
return -1;
@@ -747,7 +719,7 @@ static void CALLBACK winhttp_status(
747719
else if ((status & WINHTTP_CALLBACK_STATUS_FLAG_SECURITY_CHANNEL_ERROR))
748720
giterr_set(GITERR_NET, "security libraries could not be loaded");
749721
else
750-
giterr_set(GITERR_NET, "unknown security error %d", status);
722+
giterr_set(GITERR_NET, "unknown security error %lu", status);
751723
}
752724

753725
static int winhttp_connect(
@@ -870,7 +842,7 @@ static int do_send_request(winhttp_stream *s, size_t len, int ignore_length)
870842
len, 0);
871843
}
872844

873-
if (success || GetLastError() != SEC_E_BUFFER_TOO_SMALL)
845+
if (success || GetLastError() != (DWORD)SEC_E_BUFFER_TOO_SMALL)
874846
break;
875847
}
876848

@@ -1170,7 +1142,7 @@ static int winhttp_stream_read(
11701142
}
11711143

11721144
if (HTTP_STATUS_OK != status_code) {
1173-
giterr_set(GITERR_NET, "request failed with status code: %d", status_code);
1145+
giterr_set(GITERR_NET, "request failed with status code: %lu", status_code);
11741146
return -1;
11751147
}
11761148

src/win32/posix_w32.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -397,7 +397,6 @@ int p_readlink(const char *path, char *buf, size_t bufsiz)
397397
int p_symlink(const char *target, const char *path)
398398
{
399399
git_win32_path target_w, path_w;
400-
wchar_t *target_p;
401400

402401
if (git_win32_path_from_utf8(path_w, path) < 0 ||
403402
git__utf8_to_16(target_w, MAX_PATH, target) < 0)

tests/revwalk/basic.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -512,7 +512,7 @@ void test_revwalk_basic__big_timestamp(void)
512512
cl_git_pass(git_reference_peel((git_object **) &tip, head, GIT_OBJECT_COMMIT));
513513

514514
/* Commit with a far-ahead timestamp, we should be able to parse it in the revwalk */
515-
cl_git_pass(git_signature_new(&sig, "Joe", "joe@example.com", 2399662595, 0));
515+
cl_git_pass(git_signature_new(&sig, "Joe", "joe@example.com", 2399662595ll, 0));
516516
cl_git_pass(git_commit_tree(&tree, tip));
517517

518518
cl_git_pass(git_commit_create(&id, _repo, "HEAD", sig, sig, NULL, "some message", tree, 1,

0 commit comments

Comments
 (0)