Skip to content

Commit abe2367

Browse files
authored
Merge pull request libgit2#4925 from lhchavez/fix-a-bunch-of-warnings
Fix a bunch of warnings
2 parents cecbe74 + c6bfaf1 commit abe2367

File tree

11 files changed

+32
-46
lines changed

11 files changed

+32
-46
lines changed

deps/zlib/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
DISABLE_WARNINGS(implicit-fallthrough)
12
ADD_DEFINITIONS(-DNO_VIZ -DSTDC -DNO_GZIP)
23
FILE(GLOB SRC_ZLIB "*.c" "*.h")
34
INCLUDE_DIRECTORIES(".")

src/cc-compat.h

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,12 +47,24 @@
4747

4848
/* Define the printf format specifer to use for size_t output */
4949
#if defined(_MSC_VER) || defined(__MINGW32__)
50-
# define PRIuZ "Iu"
51-
# define PRIxZ "Ix"
52-
# define PRIdZ "Id"
50+
51+
/* The first block is needed to avoid warnings on MingW amd64 */
52+
# if (SIZE_MAX == ULLONG_MAX)
53+
# define PRIuZ "I64u"
54+
# define PRIxZ "I64x"
55+
# define PRIXZ "I64X"
56+
# define PRIdZ "I64d"
57+
# else
58+
# define PRIuZ "Iu"
59+
# define PRIxZ "Ix"
60+
# define PRIXZ "IX"
61+
# define PRIdZ "Id"
62+
# endif
63+
5364
#else
5465
# define PRIuZ "zu"
5566
# define PRIxZ "zx"
67+
# define PRIXZ "zX"
5668
# define PRIdZ "zd"
5769
#endif
5870

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, "%"PRIXZ"\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/clar_libgit2.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
#define cl_win32_pass(expr) do { \
4141
int _win32_res; \
4242
if ((_win32_res = (expr)) == 0) { \
43-
giterr_set(GITERR_OS, "Returned: %d, system error code: %d", _win32_res, GetLastError()); \
43+
giterr_set(GITERR_OS, "Returned: %d, system error code: %lu", _win32_res, GetLastError()); \
4444
cl_git_report_failure(_win32_res, 0, __FILE__, __LINE__, "System call failed: " #expr); \
4545
} \
4646
} while(0)

tests/core/vector.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#include <stdint.h>
2+
13
#include "clar_libgit2.h"
24
#include "vector.h"
35

@@ -66,14 +68,14 @@ void test_core_vector__2(void)
6668

6769
static int compare_them(const void *a, const void *b)
6870
{
69-
return (int)((long)a - (long)b);
71+
return (int)((intptr_t)a - (intptr_t)b);
7072
}
7173

7274
/* insert_sorted */
7375
void test_core_vector__3(void)
7476
{
7577
git_vector x;
76-
long i;
78+
intptr_t i;
7779
git_vector_init(&x, 1, &compare_them);
7880

7981
for (i = 0; i < 10; i += 2) {
@@ -96,7 +98,7 @@ void test_core_vector__3(void)
9698
void test_core_vector__4(void)
9799
{
98100
git_vector x;
99-
long i;
101+
intptr_t i;
100102
git_vector_init(&x, 1, &compare_them);
101103

102104
for (i = 0; i < 10; i += 2) {

tests/index/addall.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,8 +123,8 @@ static void check_stat_data(git_index *index, const char *path, bool match)
123123
cl_assert(st.st_ctime == entry->ctime.seconds);
124124
cl_assert(st.st_mtime == entry->mtime.seconds);
125125
cl_assert(st.st_size == entry->file_size);
126-
cl_assert(st.st_uid == entry->uid);
127-
cl_assert(st.st_gid == entry->gid);
126+
cl_assert((uint32_t)st.st_uid == entry->uid);
127+
cl_assert((uint32_t)st.st_gid == entry->gid);
128128
cl_assert_equal_i_fmt(
129129
GIT_MODE_TYPE(st.st_mode), GIT_MODE_TYPE(entry->mode), "%07o");
130130
if (cl_is_chmod_supported())

tests/path/win32.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ static void test_remove_namespace(const wchar_t *in, const wchar_t *expected)
150150
cl_assert(wcslen(in) < MAX_PATH);
151151
wcscpy(canonical, in);
152152

153-
cl_must_pass(git_win32_path_remove_namespace(canonical, wcslen(in)));
153+
git_win32_path_remove_namespace(canonical, wcslen(in));
154154
cl_assert_equal_wcs(expected, canonical);
155155
#else
156156
GIT_UNUSED(in);

0 commit comments

Comments
 (0)