Skip to content

Commit c544850

Browse files
authored
Merge pull request libgit2#5078 from libgit2/ethomson/warnings
Remove warnings
2 parents a064920 + e61b92e commit c544850

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+307
-193
lines changed

CMakeLists.txt

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -239,10 +239,22 @@ ELSE ()
239239
ENABLE_WARNINGS(shift-count-overflow)
240240
ENABLE_WARNINGS(unused-const-variable)
241241
ENABLE_WARNINGS(unused-function)
242-
ENABLE_WARNINGS(format)
243-
ENABLE_WARNINGS(format-security)
244242
ENABLE_WARNINGS(int-conversion)
245-
DISABLE_WARNINGS(documentation-deprecated-sync)
243+
244+
# MinGW uses gcc, which expects POSIX formatting for printf, but
245+
# uses the Windows C library, which uses its own format specifiers.
246+
# Disable format specifier warnings.
247+
IF(MINGW)
248+
DISABLE_WARNINGS(format)
249+
DISABLE_WARNINGS(format-security)
250+
ELSE()
251+
ENABLE_WARNINGS(format)
252+
ENABLE_WARNINGS(format-security)
253+
ENDIF()
254+
255+
IF("${CMAKE_C_COMPILER_ID}" STREQUAL "Clang")
256+
DISABLE_WARNINGS(documentation-deprecated-sync)
257+
ENDIF()
246258

247259
IF (PROFILE)
248260
SET(CMAKE_C_FLAGS "-pg ${CMAKE_C_FLAGS}")

cmake/Modules/EnableWarnings.cmake

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,9 @@ MACRO(DISABLE_WARNINGS flag)
77
ENDMACRO()
88

99
IF(ENABLE_WERROR)
10-
ADD_C_FLAG_IF_SUPPORTED(-Werror)
10+
IF(MSVC)
11+
ADD_COMPILE_OPTIONS(-WX)
12+
ELSE()
13+
ADD_C_FLAG_IF_SUPPORTED(-Werror)
14+
ENDIF()
1115
ENDIF()

deps/http-parser/http_parser.c

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1992,6 +1992,9 @@ http_parse_host(const char * buf, struct http_parser_url *u, int found_at) {
19921992
const char *p;
19931993
size_t buflen = u->field_data[UF_HOST].off + u->field_data[UF_HOST].len;
19941994

1995+
if (buflen > UINT16_MAX)
1996+
return 1;
1997+
19951998
u->field_data[UF_HOST].len = 0;
19961999

19972000
s = found_at ? s_http_userinfo_start : s_http_host_start;
@@ -2006,21 +2009,21 @@ http_parse_host(const char * buf, struct http_parser_url *u, int found_at) {
20062009
switch(new_s) {
20072010
case s_http_host:
20082011
if (s != s_http_host) {
2009-
u->field_data[UF_HOST].off = p - buf;
2012+
u->field_data[UF_HOST].off = (uint16_t)(p - buf);
20102013
}
20112014
u->field_data[UF_HOST].len++;
20122015
break;
20132016

20142017
case s_http_host_v6:
20152018
if (s != s_http_host_v6) {
2016-
u->field_data[UF_HOST].off = p - buf;
2019+
u->field_data[UF_HOST].off = (uint16_t)(p - buf);
20172020
}
20182021
u->field_data[UF_HOST].len++;
20192022
break;
20202023

20212024
case s_http_host_port:
20222025
if (s != s_http_host_port) {
2023-
u->field_data[UF_PORT].off = p - buf;
2026+
u->field_data[UF_PORT].off = (uint16_t)(p - buf);
20242027
u->field_data[UF_PORT].len = 0;
20252028
u->field_set |= (1 << UF_PORT);
20262029
}
@@ -2029,7 +2032,7 @@ http_parse_host(const char * buf, struct http_parser_url *u, int found_at) {
20292032

20302033
case s_http_userinfo:
20312034
if (s != s_http_userinfo) {
2032-
u->field_data[UF_USERINFO].off = p - buf ;
2035+
u->field_data[UF_USERINFO].off = (uint16_t)(p - buf);
20332036
u->field_data[UF_USERINFO].len = 0;
20342037
u->field_set |= (1 << UF_USERINFO);
20352038
}
@@ -2066,6 +2069,9 @@ http_parser_parse_url(const char *buf, size_t buflen, int is_connect,
20662069
enum http_parser_url_fields uf, old_uf;
20672070
int found_at = 0;
20682071

2072+
if (buflen > UINT16_MAX)
2073+
return 1;
2074+
20692075
u->port = u->field_set = 0;
20702076
s = is_connect ? s_req_server_start : s_req_spaces_before_url;
20712077
uf = old_uf = UF_MAX;
@@ -2121,7 +2127,7 @@ http_parser_parse_url(const char *buf, size_t buflen, int is_connect,
21212127
continue;
21222128
}
21232129

2124-
u->field_data[uf].off = p - buf;
2130+
u->field_data[uf].off = (uint16_t)(p - buf);
21252131
u->field_data[uf].len = 1;
21262132

21272133
u->field_set |= (1 << uf);

deps/zlib/adler32.c

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -177,10 +177,3 @@ uLong ZEXPORT adler32_combine(adler1, adler2, len2)
177177
return adler32_combine_(adler1, adler2, len2);
178178
}
179179

180-
uLong ZEXPORT adler32_combine64(adler1, adler2, len2)
181-
uLong adler1;
182-
uLong adler2;
183-
z_off64_t len2;
184-
{
185-
return adler32_combine_(adler1, adler2, len2);
186-
}

deps/zlib/crc32.c

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -433,10 +433,3 @@ uLong ZEXPORT crc32_combine(crc1, crc2, len2)
433433
return crc32_combine_(crc1, crc2, len2);
434434
}
435435

436-
uLong ZEXPORT crc32_combine64(crc1, crc2, len2)
437-
uLong crc1;
438-
uLong crc2;
439-
z_off64_t len2;
440-
{
441-
return crc32_combine_(crc1, crc2, len2);
442-
}

include/git2/tree.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,7 @@ GIT_EXTERN(void) git_treebuilder_clear(git_treebuilder *bld);
267267
* @param bld a previously loaded treebuilder.
268268
* @return the number of entries in the treebuilder
269269
*/
270-
GIT_EXTERN(unsigned int) git_treebuilder_entrycount(git_treebuilder *bld);
270+
GIT_EXTERN(size_t) git_treebuilder_entrycount(git_treebuilder *bld);
271271

272272
/**
273273
* Free a tree builder

src/CMakeLists.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -314,12 +314,20 @@ ELSE()
314314
ENDIF()
315315
FILE(GLOB SRC_OS unix/*.c unix/*.h)
316316
ENDIF()
317+
317318
FILE(GLOB SRC_GIT2 *.c *.h
318319
allocators/*.c allocators/*.h
319320
streams/*.c streams/*.h
320321
transports/*.c transports/*.h
321322
xdiff/*.c xdiff/*.h)
322323

324+
# the xdiff dependency is not (yet) warning-free, disable warnings as
325+
# errors for the xdiff sources until we've sorted them out
326+
IF(MSVC)
327+
SET_SOURCE_FILES_PROPERTIES(xdiff/xdiffi.c PROPERTIES COMPILE_FLAGS -WX-)
328+
SET_SOURCE_FILES_PROPERTIES(xdiff/xutils.c PROPERTIES COMPILE_FLAGS -WX-)
329+
ENDIF()
330+
323331
# Determine architecture of the machine
324332
IF (CMAKE_SIZEOF_VOID_P EQUAL 8)
325333
SET(GIT_ARCH_64 1)

src/attrcache.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ int git_attr_cache__alloc_file_entry(
5454
cachesize++;
5555
}
5656

57-
ce = git_pool_mallocz(pool, (uint32_t)cachesize);
57+
ce = git_pool_mallocz(pool, cachesize);
5858
GIT_ERROR_CHECK_ALLOC(ce);
5959

6060
if (baselen) {

src/commit_list.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ static git_commit_list_node **alloc_parents(
7373
return (git_commit_list_node **)((char *)commit + sizeof(git_commit_list_node));
7474

7575
return (git_commit_list_node **)git_pool_malloc(
76-
&walk->commit_pool, (uint32_t)(n_parents * sizeof(git_commit_list_node *)));
76+
&walk->commit_pool, (n_parents * sizeof(git_commit_list_node *)));
7777
}
7878

7979

src/config_parse.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,11 @@ static int parse_subsection_header(git_config_parser *reader, const char *line,
8888
last_quote = strrchr(line, '"');
8989
quoted_len = last_quote - first_quote;
9090

91+
if ((last_quote - line) > INT_MAX) {
92+
set_parse_error(reader, 0, "invalid section header, line too long");
93+
goto end_error;
94+
}
95+
9196
if (quoted_len == 0) {
9297
set_parse_error(reader, 0, "missing closing quotation mark in section header");
9398
goto end_error;
@@ -146,7 +151,7 @@ static int parse_subsection_header(git_config_parser *reader, const char *line,
146151
}
147152

148153
*section_name = git_buf_detach(&buf);
149-
return &line[rpos + 2] - line_start; /* rpos is at the closing quote */
154+
return (int)(&line[rpos + 2] - line_start); /* rpos is at the closing quote */
150155

151156
end_error:
152157
git_buf_dispose(&buf);

0 commit comments

Comments
 (0)