Fix dev branch under MSVC In libgit2: Move an enum out of an int bitfield in the HTTP transport. In the parser: Use int bitfields and change some variable sizes to better fit thir use. Variables that count the size of the data chunk can only ever be as large as off_t. Warning 4127 can be ignored, as nobody takes it seriously anyway. From Emeric: change some variable declarations to keep MSVC happy. Signed-off-by: Carlos Martín Nieto <carlos@cmartin.tk>
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127
diff --git a/CMakeLists.txt b/CMakeLists.txt
index b505d75..8ef3587 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -53,7 +53,7 @@ OPTION (BUILD_CLAY "Build Tests using the Clay suite" ON)
# Platform specific compilation flags
IF (MSVC)
- SET(CMAKE_C_FLAGS "/W4 /WX /nologo /Zi")
+ SET(CMAKE_C_FLAGS "/W4 /WX /nologo /Zi /wd4127")
IF (STDCALL)
SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /Gz")
ENDIF ()
diff --git a/deps/http-parser/http_parser.c b/deps/http-parser/http_parser.c
index e905747..e9d42ce 100644
--- a/deps/http-parser/http_parser.c
+++ b/deps/http-parser/http_parser.c
@@ -364,11 +364,13 @@ size_t http_parser_execute (http_parser *parser,
char c, ch;
int8_t unhex_val;
const char *p = data, *pe;
- int64_t to_read;
+ off_t to_read;
enum state state;
enum header_states header_state;
uint64_t index = parser->index;
uint64_t nread = parser->nread;
+ const char *header_field_mark, *header_value_mark, *url_mark;
+ const char *matcher;
/* We're in an error state. Don't bother doing anything. */
if (HTTP_PARSER_ERRNO(parser) != HPE_OK) {
@@ -399,9 +401,9 @@ size_t http_parser_execute (http_parser *parser,
/* technically we could combine all of these (except for url_mark) into one
variable, saving stack space, but it seems more clear to have them
separated. */
- const char *header_field_mark = 0;
- const char *header_value_mark = 0;
- const char *url_mark = 0;
+ header_field_mark = 0;
+ header_value_mark = 0;
+ url_mark = 0;
if (state == s_header_field)
header_field_mark = data;
@@ -695,7 +697,7 @@ size_t http_parser_execute (http_parser *parser,
goto error;
}
- const char *matcher = method_strings[parser->method];
+ matcher = method_strings[parser->method];
if (ch == ' ' && matcher[index] == '\0') {
state = s_req_spaces_before_url;
} else if (ch == matcher[index]) {
@@ -1576,7 +1578,7 @@ size_t http_parser_execute (http_parser *parser,
}
case s_body_identity:
- to_read = MIN(pe - p, (int64_t)parser->content_length);
+ to_read = (off_t) MIN(pe - p, parser->content_length);
if (to_read > 0) {
if (settings->on_body) settings->on_body(parser, p, to_read);
p += to_read - 1;
@@ -1670,7 +1672,7 @@ size_t http_parser_execute (http_parser *parser,
{
assert(parser->flags & F_CHUNKED);
- to_read = MIN(pe - p, (int64_t)(parser->content_length));
+ to_read = (off_t) MIN(pe - p, parser->content_length);
if (to_read > 0) {
if (settings->on_body) settings->on_body(parser, p, to_read);
@@ -1710,7 +1712,7 @@ size_t http_parser_execute (http_parser *parser,
parser->state = state;
parser->header_state = header_state;
- parser->index = index;
+ parser->index = (unsigned char) index;
parser->nread = nread;
return len;
diff --git a/src/transport-http.c b/src/transport-http.c
index d111d5c..70086ad 100644
--- a/src/transport-http.c
+++ b/src/transport-http.c
@@ -33,11 +33,11 @@
#include "buffer.h"
#include "pkt.h"
-typedef enum {
+enum last_cb {
NONE,
FIELD,
VALUE
-} last_cb_type;
+};
typedef struct {
git_transport parent;
@@ -48,8 +48,8 @@ typedef struct {
int error;
int transfer_finished :1,
ct_found :1,
- ct_finished :1,
- last_cb :3;
+ ct_finished :1;
+ enum last_cb last_cb;
char *content_type;
char *service;
} transport_http;
@@ -75,10 +75,13 @@ static int gen_request(git_buf *buf, const char *url, const char *host, const ch
static int do_connect(transport_http *t, const char *service)
{
- int s = -1, error;;
- const char *url = t->parent.url, *prefix = "http://";
- char *host = NULL, *port = NULL;
git_buf request = GIT_BUF_INIT;
+ int s = -1, error;
+ const char *url, *prefix;
+ char *host = NULL, *port = NULL;
+
+ url = t->parent.url;
+ prefix = "http://";
if (!git__prefixcmp(url, prefix))
url += strlen(prefix);