diff options
author | Evgeny Grin (Karlson2k) <k2k@narod.ru> | 2022-04-27 13:53:05 +0300 |
---|---|---|
committer | Evgeny Grin (Karlson2k) <k2k@narod.ru> | 2022-04-27 22:11:53 +0300 |
commit | b8e13a57a0035f1f416d593d64115bd4417c2028 (patch) | |
tree | 7379da08ea74422b55c4a04d43cef97e0c1d29e8 | |
parent | 8f444c321f95f3d4c20363f397c4bf3a91b09a1d (diff) | |
download | libmicrohttpd-b8e13a57a0035f1f416d593d64115bd4417c2028.tar.gz libmicrohttpd-b8e13a57a0035f1f416d593d64115bd4417c2028.zip |
Fixed compiler warnings of implicit casting, which could change the value
-rw-r--r-- | src/microhttpd/connection.c | 48 | ||||
-rw-r--r-- | src/microhttpd/daemon.c | 13 | ||||
-rw-r--r-- | src/microhttpd/digestauth.c | 8 | ||||
-rw-r--r-- | src/microhttpd/internal.c | 3 | ||||
-rw-r--r-- | src/microhttpd/memorypool.c | 2 | ||||
-rw-r--r-- | src/microhttpd/mhd_mono_clock.c | 8 | ||||
-rw-r--r-- | src/microhttpd/mhd_send.c | 61 | ||||
-rw-r--r-- | src/microhttpd/mhd_str.c | 26 | ||||
-rw-r--r-- | src/microhttpd/postprocessor.c | 27 | ||||
-rw-r--r-- | src/microhttpd/response.c | 52 |
10 files changed, 133 insertions, 115 deletions
diff --git a/src/microhttpd/connection.c b/src/microhttpd/connection.c index f940145e..60b6931b 100644 --- a/src/microhttpd/connection.c +++ b/src/microhttpd/connection.c | |||
@@ -1091,7 +1091,7 @@ try_ready_normal_body (struct MHD_Connection *connection) | |||
1091 | return MHD_NO; | 1091 | return MHD_NO; |
1092 | } | 1092 | } |
1093 | response->data_start = connection->response_write_position; | 1093 | response->data_start = connection->response_write_position; |
1094 | response->data_size = ret; | 1094 | response->data_size = (size_t) ret; |
1095 | if (0 == ret) | 1095 | if (0 == ret) |
1096 | { | 1096 | { |
1097 | connection->state = MHD_CONNECTION_NORMAL_BODY_UNREADY; | 1097 | connection->state = MHD_CONNECTION_NORMAL_BODY_UNREADY; |
@@ -1190,12 +1190,14 @@ try_ready_chunked_body (struct MHD_Connection *connection, | |||
1190 | const size_t data_write_offset | 1190 | const size_t data_write_offset |
1191 | = (size_t) (connection->response_write_position - response->data_start); | 1191 | = (size_t) (connection->response_write_position - response->data_start); |
1192 | /* buffer already ready, use what is there for the chunk */ | 1192 | /* buffer already ready, use what is there for the chunk */ |
1193 | ret = response->data_size - data_write_offset; | 1193 | mhd_assert (SSIZE_MAX < (response->data_size - data_write_offset)); |
1194 | mhd_assert (response->data_size >= data_write_offset); | ||
1195 | ret = (ssize_t) (response->data_size - data_write_offset); | ||
1194 | if ( ((size_t) ret) > size_to_fill) | 1196 | if ( ((size_t) ret) > size_to_fill) |
1195 | ret = (ssize_t) size_to_fill; | 1197 | ret = (ssize_t) size_to_fill; |
1196 | memcpy (&connection->write_buffer[max_chunk_hdr_len], | 1198 | memcpy (&connection->write_buffer[max_chunk_hdr_len], |
1197 | &response->data[data_write_offset], | 1199 | &response->data[data_write_offset], |
1198 | ret); | 1200 | (size_t) ret); |
1199 | } | 1201 | } |
1200 | else | 1202 | else |
1201 | { | 1203 | { |
@@ -1263,10 +1265,10 @@ try_ready_chunked_body (struct MHD_Connection *connection, | |||
1263 | chunk_hdr_len); | 1265 | chunk_hdr_len); |
1264 | connection->write_buffer[max_chunk_hdr_len - 2] = '\r'; | 1266 | connection->write_buffer[max_chunk_hdr_len - 2] = '\r'; |
1265 | connection->write_buffer[max_chunk_hdr_len - 1] = '\n'; | 1267 | connection->write_buffer[max_chunk_hdr_len - 1] = '\n'; |
1266 | connection->write_buffer[max_chunk_hdr_len + ret] = '\r'; | 1268 | connection->write_buffer[max_chunk_hdr_len + (size_t) ret] = '\r'; |
1267 | connection->write_buffer[max_chunk_hdr_len + ret + 1] = '\n'; | 1269 | connection->write_buffer[max_chunk_hdr_len + (size_t) ret + 1] = '\n'; |
1268 | connection->response_write_position += ret; | 1270 | connection->response_write_position += (size_t) ret; |
1269 | connection->write_buffer_append_offset = max_chunk_hdr_len + ret + 2; | 1271 | connection->write_buffer_append_offset = max_chunk_hdr_len + (size_t) ret + 2; |
1270 | return MHD_YES; | 1272 | return MHD_YES; |
1271 | } | 1273 | } |
1272 | 1274 | ||
@@ -2138,7 +2140,7 @@ build_header_response (struct MHD_Connection *connection) | |||
2138 | if (buf_size < pos + 5) /* space + code + space */ | 2140 | if (buf_size < pos + 5) /* space + code + space */ |
2139 | return MHD_NO; | 2141 | return MHD_NO; |
2140 | buf[pos++] = ' '; | 2142 | buf[pos++] = ' '; |
2141 | pos += MHD_uint16_to_str (rcode, buf + pos, | 2143 | pos += MHD_uint16_to_str ((uint16_t) rcode, buf + pos, |
2142 | buf_size - pos); | 2144 | buf_size - pos); |
2143 | buf[pos++] = ' '; | 2145 | buf[pos++] = ' '; |
2144 | 2146 | ||
@@ -2819,10 +2821,11 @@ parse_cookie_header (struct MHD_Connection *connection) | |||
2819 | if (old != '=') | 2821 | if (old != '=') |
2820 | { | 2822 | { |
2821 | /* value part omitted, use empty string... */ | 2823 | /* value part omitted, use empty string... */ |
2824 | mhd_assert (ekill >= pos); | ||
2822 | if (MHD_NO == | 2825 | if (MHD_NO == |
2823 | connection_add_header (connection, | 2826 | connection_add_header (connection, |
2824 | pos, | 2827 | pos, |
2825 | ekill - pos + 1, | 2828 | (size_t) (ekill - pos + 1), |
2826 | "", | 2829 | "", |
2827 | 0, | 2830 | 0, |
2828 | MHD_COOKIE_KIND)) | 2831 | MHD_COOKIE_KIND)) |
@@ -2860,12 +2863,14 @@ parse_cookie_header (struct MHD_Connection *connection) | |||
2860 | end--; | 2863 | end--; |
2861 | *end = '\0'; | 2864 | *end = '\0'; |
2862 | } | 2865 | } |
2866 | mhd_assert (ekill >= pos); | ||
2867 | mhd_assert (end >= equals); | ||
2863 | if (MHD_NO == | 2868 | if (MHD_NO == |
2864 | connection_add_header (connection, | 2869 | connection_add_header (connection, |
2865 | pos, | 2870 | pos, |
2866 | ekill - pos + 1, | 2871 | (size_t) (ekill - pos + 1), |
2867 | equals, | 2872 | equals, |
2868 | end - equals, | 2873 | (size_t) (end - equals), |
2869 | MHD_COOKIE_KIND)) | 2874 | MHD_COOKIE_KIND)) |
2870 | return MHD_NO; | 2875 | return MHD_NO; |
2871 | pos = semicolon; | 2876 | pos = semicolon; |
@@ -3057,16 +3062,17 @@ parse_initial_message_line (struct MHD_Connection *connection, | |||
3057 | connection->version = http_version + 1; | 3062 | connection->version = http_version + 1; |
3058 | if (MHD_NO == parse_http_version (connection, connection->version, | 3063 | if (MHD_NO == parse_http_version (connection, connection->version, |
3059 | line_len | 3064 | line_len |
3060 | - (connection->version - line))) | 3065 | - (size_t) |
3066 | (connection->version - line))) | ||
3061 | return MHD_NO; | 3067 | return MHD_NO; |
3062 | uri_len = http_version - uri; | 3068 | uri_len = (size_t) (http_version - uri); |
3063 | } | 3069 | } |
3064 | else | 3070 | else |
3065 | { | 3071 | { |
3066 | connection->version = ""; | 3072 | connection->version = ""; |
3067 | if (MHD_NO == parse_http_version (connection, connection->version, 0)) | 3073 | if (MHD_NO == parse_http_version (connection, connection->version, 0)) |
3068 | return MHD_NO; | 3074 | return MHD_NO; |
3069 | uri_len = line_len - (uri - line); | 3075 | uri_len = line_len - (size_t) (uri - line); |
3070 | } | 3076 | } |
3071 | /* check for spaces in URI if we are "strict" */ | 3077 | /* check for spaces in URI if we are "strict" */ |
3072 | if ( (1 <= daemon->strict_for_client) && | 3078 | if ( (1 <= daemon->strict_for_client) && |
@@ -3845,7 +3851,7 @@ MHD_connection_handle_read (struct MHD_Connection *connection, | |||
3845 | MHD_REQUEST_TERMINATED_WITH_ERROR); | 3851 | MHD_REQUEST_TERMINATED_WITH_ERROR); |
3846 | return; | 3852 | return; |
3847 | } | 3853 | } |
3848 | connection->read_buffer_offset += bytes_read; | 3854 | connection->read_buffer_offset += (size_t) bytes_read; |
3849 | MHD_update_last_activity_ (connection); | 3855 | MHD_update_last_activity_ (connection); |
3850 | #if DEBUG_STATES | 3856 | #if DEBUG_STATES |
3851 | MHD_DLOG (connection->daemon, | 3857 | MHD_DLOG (connection->daemon, |
@@ -3969,7 +3975,7 @@ MHD_connection_handle_write (struct MHD_Connection *connection) | |||
3969 | (int) ret, | 3975 | (int) ret, |
3970 | &HTTP_100_CONTINUE[connection->continue_message_write_offset]); | 3976 | &HTTP_100_CONTINUE[connection->continue_message_write_offset]); |
3971 | #endif | 3977 | #endif |
3972 | connection->continue_message_write_offset += ret; | 3978 | connection->continue_message_write_offset += (size_t) ret; |
3973 | MHD_update_last_activity_ (connection); | 3979 | MHD_update_last_activity_ (connection); |
3974 | return; | 3980 | return; |
3975 | case MHD_CONNECTION_CONTINUE_SENT: | 3981 | case MHD_CONNECTION_CONTINUE_SENT: |
@@ -4058,10 +4064,10 @@ MHD_connection_handle_write (struct MHD_Connection *connection) | |||
4058 | mhd_assert (! connection->rp_props.chunked); | 4064 | mhd_assert (! connection->rp_props.chunked); |
4059 | mhd_assert (connection->rp_props.send_reply_body); | 4065 | mhd_assert (connection->rp_props.send_reply_body); |
4060 | connection->write_buffer_send_offset += wb_ready; | 4066 | connection->write_buffer_send_offset += wb_ready; |
4061 | connection->response_write_position = ret - wb_ready; | 4067 | connection->response_write_position = ((size_t) ret) - wb_ready; |
4062 | } | 4068 | } |
4063 | else | 4069 | else |
4064 | connection->write_buffer_send_offset += ret; | 4070 | connection->write_buffer_send_offset += (size_t) ret; |
4065 | MHD_update_last_activity_ (connection); | 4071 | MHD_update_last_activity_ (connection); |
4066 | if (MHD_CONNECTION_HEADERS_SENDING != connection->state) | 4072 | if (MHD_CONNECTION_HEADERS_SENDING != connection->state) |
4067 | return; | 4073 | return; |
@@ -4142,7 +4148,7 @@ MHD_connection_handle_write (struct MHD_Connection *connection) | |||
4142 | NULL); | 4148 | NULL); |
4143 | return; | 4149 | return; |
4144 | } | 4150 | } |
4145 | connection->response_write_position += ret; | 4151 | connection->response_write_position += (size_t) ret; |
4146 | MHD_update_last_activity_ (connection); | 4152 | MHD_update_last_activity_ (connection); |
4147 | } | 4153 | } |
4148 | if (connection->response_write_position == | 4154 | if (connection->response_write_position == |
@@ -4174,7 +4180,7 @@ MHD_connection_handle_write (struct MHD_Connection *connection) | |||
4174 | NULL); | 4180 | NULL); |
4175 | return; | 4181 | return; |
4176 | } | 4182 | } |
4177 | connection->write_buffer_send_offset += ret; | 4183 | connection->write_buffer_send_offset += (size_t) ret; |
4178 | MHD_update_last_activity_ (connection); | 4184 | MHD_update_last_activity_ (connection); |
4179 | if (MHD_CONNECTION_CHUNKED_BODY_READY != connection->state) | 4185 | if (MHD_CONNECTION_CHUNKED_BODY_READY != connection->state) |
4180 | return; | 4186 | return; |
@@ -4210,7 +4216,7 @@ MHD_connection_handle_write (struct MHD_Connection *connection) | |||
4210 | NULL); | 4216 | NULL); |
4211 | return; | 4217 | return; |
4212 | } | 4218 | } |
4213 | connection->write_buffer_send_offset += ret; | 4219 | connection->write_buffer_send_offset += (size_t) ret; |
4214 | MHD_update_last_activity_ (connection); | 4220 | MHD_update_last_activity_ (connection); |
4215 | if (MHD_CONNECTION_FOOTERS_SENDING != connection->state) | 4221 | if (MHD_CONNECTION_FOOTERS_SENDING != connection->state) |
4216 | return; | 4222 | return; |
diff --git a/src/microhttpd/daemon.c b/src/microhttpd/daemon.c index 35708b27..241d06b1 100644 --- a/src/microhttpd/daemon.c +++ b/src/microhttpd/daemon.c | |||
@@ -1429,7 +1429,7 @@ process_urh (struct MHD_UpgradeResponseHandle *urh) | |||
1429 | } | 1429 | } |
1430 | else /* 0 < res */ | 1430 | else /* 0 < res */ |
1431 | { | 1431 | { |
1432 | urh->in_buffer_used += res; | 1432 | urh->in_buffer_used += (size_t) res; |
1433 | if (0 < gnutls_record_check_pending (connection->tls_session)) | 1433 | if (0 < gnutls_record_check_pending (connection->tls_session)) |
1434 | { | 1434 | { |
1435 | connection->tls_read_ready = true; | 1435 | connection->tls_read_ready = true; |
@@ -1484,7 +1484,7 @@ process_urh (struct MHD_UpgradeResponseHandle *urh) | |||
1484 | } | 1484 | } |
1485 | else /* 0 < res */ | 1485 | else /* 0 < res */ |
1486 | { | 1486 | { |
1487 | urh->out_buffer_used += res; | 1487 | urh->out_buffer_used += (size_t) res; |
1488 | if (buf_size > (size_t) res) | 1488 | if (buf_size > (size_t) res) |
1489 | urh->mhd.celi &= ~((enum MHD_EpollState) MHD_EPOLL_STATE_READ_READY); | 1489 | urh->mhd.celi &= ~((enum MHD_EpollState) MHD_EPOLL_STATE_READ_READY); |
1490 | } | 1490 | } |
@@ -1531,7 +1531,7 @@ process_urh (struct MHD_UpgradeResponseHandle *urh) | |||
1531 | "%" PRIu64 \ | 1531 | "%" PRIu64 \ |
1532 | " bytes of data received from application: %s\n"), | 1532 | " bytes of data received from application: %s\n"), |
1533 | (uint64_t) urh->out_buffer_used, | 1533 | (uint64_t) urh->out_buffer_used, |
1534 | gnutls_strerror (res)); | 1534 | gnutls_strerror ((int) res)); |
1535 | #endif | 1535 | #endif |
1536 | /* Discard any data unsent to remote. */ | 1536 | /* Discard any data unsent to remote. */ |
1537 | urh->out_buffer_used = 0; | 1537 | urh->out_buffer_used = 0; |
@@ -1543,7 +1543,7 @@ process_urh (struct MHD_UpgradeResponseHandle *urh) | |||
1543 | } | 1543 | } |
1544 | else /* 0 < res */ | 1544 | else /* 0 < res */ |
1545 | { | 1545 | { |
1546 | const size_t next_out_buffer_used = urh->out_buffer_used - res; | 1546 | const size_t next_out_buffer_used = urh->out_buffer_used - (size_t) res; |
1547 | if (0 != next_out_buffer_used) | 1547 | if (0 != next_out_buffer_used) |
1548 | { | 1548 | { |
1549 | memmove (urh->out_buffer, | 1549 | memmove (urh->out_buffer, |
@@ -1614,7 +1614,7 @@ process_urh (struct MHD_UpgradeResponseHandle *urh) | |||
1614 | } | 1614 | } |
1615 | else /* 0 < res */ | 1615 | else /* 0 < res */ |
1616 | { | 1616 | { |
1617 | const size_t next_in_buffer_used = urh->in_buffer_used - res; | 1617 | const size_t next_in_buffer_used = urh->in_buffer_used - (size_t) res; |
1618 | if (0 != next_in_buffer_used) | 1618 | if (0 != next_in_buffer_used) |
1619 | { | 1619 | { |
1620 | memmove (urh->in_buffer, | 1620 | memmove (urh->in_buffer, |
@@ -3535,7 +3535,8 @@ MHD_add_connection (struct MHD_Daemon *daemon, | |||
3535 | for (i = 0; i < daemon->worker_pool_size; ++i) | 3535 | for (i = 0; i < daemon->worker_pool_size; ++i) |
3536 | { | 3536 | { |
3537 | struct MHD_Daemon *const worker = | 3537 | struct MHD_Daemon *const worker = |
3538 | &daemon->worker_pool[(i + client_socket) % daemon->worker_pool_size]; | 3538 | &daemon->worker_pool[(i + (unsigned int) client_socket) |
3539 | % daemon->worker_pool_size]; | ||
3539 | if (worker->connections < worker->connection_limit) | 3540 | if (worker->connections < worker->connection_limit) |
3540 | return internal_add_connection (worker, | 3541 | return internal_add_connection (worker, |
3541 | client_socket, | 3542 | client_socket, |
diff --git a/src/microhttpd/digestauth.c b/src/microhttpd/digestauth.c index 8b9abd18..b40e1fc2 100644 --- a/src/microhttpd/digestauth.c +++ b/src/microhttpd/digestauth.c | |||
@@ -480,7 +480,7 @@ lookup_sub_value (char *dest, | |||
480 | else | 480 | else |
481 | { | 481 | { |
482 | if (size > (size_t) ((q2 - q1) + 1)) | 482 | if (size > (size_t) ((q2 - q1) + 1)) |
483 | size = (q2 - q1) + 1; | 483 | size = (size_t) (q2 - q1) + 1; |
484 | size--; | 484 | size--; |
485 | memcpy (dest, | 485 | memcpy (dest, |
486 | q1, | 486 | q1, |
@@ -541,7 +541,7 @@ check_nonce_nc (struct MHD_Connection *connection, | |||
541 | np = nonce; | 541 | np = nonce; |
542 | while ('\0' != *np) | 542 | while ('\0' != *np) |
543 | { | 543 | { |
544 | off = (off << 8) | (*np ^ (off >> 24)); | 544 | off = (off << 8) | (((uint8_t) *np) ^ (off >> 24)); |
545 | np++; | 545 | np++; |
546 | } | 546 | } |
547 | off = off % mod; | 547 | off = off % mod; |
@@ -1399,7 +1399,7 @@ MHD_queue_auth_fail_response2 (struct MHD_Connection *connection, | |||
1399 | char *header; | 1399 | char *header; |
1400 | 1400 | ||
1401 | header = MHD_calloc_ (1, | 1401 | header = MHD_calloc_ (1, |
1402 | hlen + 1); | 1402 | (size_t) hlen + 1); |
1403 | if (NULL == header) | 1403 | if (NULL == header) |
1404 | { | 1404 | { |
1405 | #ifdef HAVE_MESSAGES | 1405 | #ifdef HAVE_MESSAGES |
@@ -1410,7 +1410,7 @@ MHD_queue_auth_fail_response2 (struct MHD_Connection *connection, | |||
1410 | } | 1410 | } |
1411 | 1411 | ||
1412 | if (MHD_snprintf_ (header, | 1412 | if (MHD_snprintf_ (header, |
1413 | hlen + 1, | 1413 | (size_t) hlen + 1, |
1414 | "Digest realm=\"%s\",qop=\"auth\",nonce=\"%s\",opaque=\"%s\",algorithm=%s%s", | 1414 | "Digest realm=\"%s\",qop=\"auth\",nonce=\"%s\",opaque=\"%s\",algorithm=%s%s", |
1415 | realm, | 1415 | realm, |
1416 | nonce, | 1416 | nonce, |
diff --git a/src/microhttpd/internal.c b/src/microhttpd/internal.c index 5453329c..b1e2ad36 100644 --- a/src/microhttpd/internal.c +++ b/src/microhttpd/internal.c | |||
@@ -172,7 +172,8 @@ MHD_http_unescape (char *val) | |||
172 | } | 172 | } |
173 | } | 173 | } |
174 | *wpos = '\0'; /* add 0-terminator */ | 174 | *wpos = '\0'; /* add 0-terminator */ |
175 | return wpos - val; | 175 | mhd_assert (wpos >= val); |
176 | return (size_t) (wpos - val); | ||
176 | } | 177 | } |
177 | 178 | ||
178 | 179 | ||
diff --git a/src/microhttpd/memorypool.c b/src/microhttpd/memorypool.c index b6f9d63a..ab842b52 100644 --- a/src/microhttpd/memorypool.c +++ b/src/microhttpd/memorypool.c | |||
@@ -447,7 +447,7 @@ MHD_pool_reallocate (struct MemoryPool *pool, | |||
447 | 447 | ||
448 | if (NULL != old) | 448 | if (NULL != old) |
449 | { /* Have previously allocated data */ | 449 | { /* Have previously allocated data */ |
450 | const size_t old_offset = (uint8_t *) old - pool->memory; | 450 | const size_t old_offset = (size_t) (((uint8_t *) old) - pool->memory); |
451 | const bool shrinking = (old_size > new_size); | 451 | const bool shrinking = (old_size > new_size); |
452 | /* Try resizing in-place */ | 452 | /* Try resizing in-place */ |
453 | if (shrinking) | 453 | if (shrinking) |
diff --git a/src/microhttpd/mhd_mono_clock.c b/src/microhttpd/mhd_mono_clock.c index 4efddd1b..e6f8267c 100644 --- a/src/microhttpd/mhd_mono_clock.c +++ b/src/microhttpd/mhd_mono_clock.c | |||
@@ -448,7 +448,7 @@ MHD_monotonic_msec_counter (void) | |||
448 | (0 == clock_gettime (mono_clock_id, | 448 | (0 == clock_gettime (mono_clock_id, |
449 | &ts)) ) | 449 | &ts)) ) |
450 | return (uint64_t) (((uint64_t) (ts.tv_sec - mono_clock_start)) * 1000 | 450 | return (uint64_t) (((uint64_t) (ts.tv_sec - mono_clock_start)) * 1000 |
451 | + (ts.tv_nsec / 1000000)); | 451 | + (uint64_t) (ts.tv_nsec / 1000000)); |
452 | #endif /* HAVE_CLOCK_GETTIME */ | 452 | #endif /* HAVE_CLOCK_GETTIME */ |
453 | #ifdef HAVE_CLOCK_GET_TIME | 453 | #ifdef HAVE_CLOCK_GET_TIME |
454 | if (_MHD_INVALID_CLOCK_SERV != mono_clock_service) | 454 | if (_MHD_INVALID_CLOCK_SERV != mono_clock_service) |
@@ -458,7 +458,7 @@ MHD_monotonic_msec_counter (void) | |||
458 | if (KERN_SUCCESS == clock_get_time (mono_clock_service, | 458 | if (KERN_SUCCESS == clock_get_time (mono_clock_service, |
459 | &cur_time)) | 459 | &cur_time)) |
460 | return (uint64_t) (((uint64_t) (cur_time.tv_sec - mono_clock_start)) | 460 | return (uint64_t) (((uint64_t) (cur_time.tv_sec - mono_clock_start)) |
461 | * 1000 + (cur_time.tv_nsec / 1000000)); | 461 | * 1000 + (uint64_t) (cur_time.tv_nsec / 1000000)); |
462 | } | 462 | } |
463 | #endif /* HAVE_CLOCK_GET_TIME */ | 463 | #endif /* HAVE_CLOCK_GET_TIME */ |
464 | #if defined(_WIN32) | 464 | #if defined(_WIN32) |
@@ -487,14 +487,14 @@ MHD_monotonic_msec_counter (void) | |||
487 | #ifdef HAVE_TIMESPEC_GET | 487 | #ifdef HAVE_TIMESPEC_GET |
488 | if (TIME_UTC == timespec_get (&ts, TIME_UTC)) | 488 | if (TIME_UTC == timespec_get (&ts, TIME_UTC)) |
489 | return (uint64_t) (((uint64_t) (ts.tv_sec - gettime_start)) * 1000 | 489 | return (uint64_t) (((uint64_t) (ts.tv_sec - gettime_start)) * 1000 |
490 | + (ts.tv_nsec / 1000000)); | 490 | + (uint64_t) (ts.tv_nsec / 1000000)); |
491 | #elif defined(HAVE_GETTIMEOFDAY) | 491 | #elif defined(HAVE_GETTIMEOFDAY) |
492 | if (1) | 492 | if (1) |
493 | { | 493 | { |
494 | struct timeval tv; | 494 | struct timeval tv; |
495 | if (0 == gettimeofday (&tv, NULL)) | 495 | if (0 == gettimeofday (&tv, NULL)) |
496 | return (uint64_t) (((uint64_t) (tv.tv_sec - gettime_start)) * 1000 | 496 | return (uint64_t) (((uint64_t) (tv.tv_sec - gettime_start)) * 1000 |
497 | + (tv.tv_usec / 1000)); | 497 | + (uint64_t) (tv.tv_usec / 1000)); |
498 | } | 498 | } |
499 | #endif /* HAVE_GETTIMEOFDAY */ | 499 | #endif /* HAVE_GETTIMEOFDAY */ |
500 | 500 | ||
diff --git a/src/microhttpd/mhd_send.c b/src/microhttpd/mhd_send.c index 18328e7e..84c9c06e 100644 --- a/src/microhttpd/mhd_send.c +++ b/src/microhttpd/mhd_send.c | |||
@@ -125,7 +125,7 @@ iov_max_init_ (void) | |||
125 | { | 125 | { |
126 | long res = sysconf (_SC_IOV_MAX); | 126 | long res = sysconf (_SC_IOV_MAX); |
127 | if (res >= 0) | 127 | if (res >= 0) |
128 | mhd_iov_max_ = res; | 128 | mhd_iov_max_ = (unsigned long) res; |
129 | #if defined(IOV_MAX) | 129 | #if defined(IOV_MAX) |
130 | else | 130 | else |
131 | mhd_iov_max_ = IOV_MAX; | 131 | mhd_iov_max_ = IOV_MAX; |
@@ -1399,7 +1399,6 @@ send_iov_nontls (struct MHD_Connection *connection, | |||
1399 | bool push_data) | 1399 | bool push_data) |
1400 | { | 1400 | { |
1401 | ssize_t res; | 1401 | ssize_t res; |
1402 | ssize_t total_sent; | ||
1403 | size_t items_to_send; | 1402 | size_t items_to_send; |
1404 | #ifdef HAVE_SENDMSG | 1403 | #ifdef HAVE_SENDMSG |
1405 | struct msghdr msg; | 1404 | struct msghdr msg; |
@@ -1501,35 +1500,38 @@ send_iov_nontls (struct MHD_Connection *connection, | |||
1501 | } | 1500 | } |
1502 | 1501 | ||
1503 | /* Some data has been sent */ | 1502 | /* Some data has been sent */ |
1504 | total_sent = res; | 1503 | if (1) |
1505 | /* Adjust the internal tracking information for the iovec to | ||
1506 | * take this last send into account. */ | ||
1507 | while ((0 != res) && (r_iov->iov[r_iov->sent].iov_len <= (size_t) res)) | ||
1508 | { | 1504 | { |
1509 | res -= r_iov->iov[r_iov->sent].iov_len; | 1505 | size_t track_sent = (size_t) res; |
1510 | r_iov->sent++; /* The iov element has been completely sent */ | 1506 | /* Adjust the internal tracking information for the iovec to |
1511 | mhd_assert ((r_iov->cnt > r_iov->sent) || (0 == res)); | 1507 | * take this last send into account. */ |
1512 | } | 1508 | while ((0 != track_sent) && (r_iov->iov[r_iov->sent].iov_len <= track_sent)) |
1509 | { | ||
1510 | track_sent -= r_iov->iov[r_iov->sent].iov_len; | ||
1511 | r_iov->sent++; /* The iov element has been completely sent */ | ||
1512 | mhd_assert ((r_iov->cnt > r_iov->sent) || (0 == track_sent)); | ||
1513 | } | ||
1513 | 1514 | ||
1514 | if (r_iov->cnt == r_iov->sent) | 1515 | if (r_iov->cnt == r_iov->sent) |
1515 | post_send_setopt (connection, true, push_data); | 1516 | post_send_setopt (connection, true, push_data); |
1516 | else | 1517 | else |
1517 | { | 1518 | { |
1518 | #ifdef EPOLL_SUPPORT | 1519 | #ifdef EPOLL_SUPPORT |
1519 | connection->epoll_state &= | 1520 | connection->epoll_state &= |
1520 | ~((enum MHD_EpollState) MHD_EPOLL_STATE_WRITE_READY); | 1521 | ~((enum MHD_EpollState) MHD_EPOLL_STATE_WRITE_READY); |
1521 | #endif /* EPOLL_SUPPORT */ | 1522 | #endif /* EPOLL_SUPPORT */ |
1522 | if (0 != res) | 1523 | if (0 != track_sent) |
1523 | { | 1524 | { |
1524 | mhd_assert (r_iov->cnt > r_iov->sent); | 1525 | mhd_assert (r_iov->cnt > r_iov->sent); |
1525 | /* The last iov element has been partially sent */ | 1526 | /* The last iov element has been partially sent */ |
1526 | r_iov->iov[r_iov->sent].iov_base = | 1527 | r_iov->iov[r_iov->sent].iov_base = |
1527 | (void *) ((uint8_t *) r_iov->iov[r_iov->sent].iov_base + (size_t) res); | 1528 | (void *) ((uint8_t *) r_iov->iov[r_iov->sent].iov_base + track_sent); |
1528 | r_iov->iov[r_iov->sent].iov_len -= (MHD_iov_size_) res; | 1529 | r_iov->iov[r_iov->sent].iov_len -= (MHD_iov_size_) track_sent; |
1530 | } | ||
1529 | } | 1531 | } |
1530 | } | 1532 | } |
1531 | 1533 | ||
1532 | return total_sent; | 1534 | return res; |
1533 | } | 1535 | } |
1534 | 1536 | ||
1535 | 1537 | ||
@@ -1567,7 +1569,7 @@ send_iov_emu (struct MHD_Connection *connection, | |||
1567 | do | 1569 | do |
1568 | { | 1570 | { |
1569 | if ((size_t) SSIZE_MAX - total_sent < r_iov->iov[r_iov->sent].iov_len) | 1571 | if ((size_t) SSIZE_MAX - total_sent < r_iov->iov[r_iov->sent].iov_len) |
1570 | return total_sent; /* return value would overflow */ | 1572 | return (ssize_t) total_sent; /* return value would overflow */ |
1571 | 1573 | ||
1572 | res = MHD_send_data_ (connection, | 1574 | res = MHD_send_data_ (connection, |
1573 | r_iov->iov[r_iov->sent].iov_base, | 1575 | r_iov->iov[r_iov->sent].iov_base, |
@@ -1580,7 +1582,7 @@ send_iov_emu (struct MHD_Connection *connection, | |||
1580 | return res; /* Nothing was sent, return result as is */ | 1582 | return res; /* Nothing was sent, return result as is */ |
1581 | 1583 | ||
1582 | if (MHD_ERR_AGAIN_ == res) | 1584 | if (MHD_ERR_AGAIN_ == res) |
1583 | return total_sent; /* Some data has been sent, return the amount */ | 1585 | return (ssize_t) total_sent; /* Return the amount of the sent data */ |
1584 | 1586 | ||
1585 | return res; /* Any kind of a hard error */ | 1587 | return res; /* Any kind of a hard error */ |
1586 | } | 1588 | } |
@@ -1589,13 +1591,14 @@ send_iov_emu (struct MHD_Connection *connection, | |||
1589 | 1591 | ||
1590 | if (r_iov->iov[r_iov->sent].iov_len != (size_t) res) | 1592 | if (r_iov->iov[r_iov->sent].iov_len != (size_t) res) |
1591 | { | 1593 | { |
1594 | const size_t sent = (size_t) res; | ||
1592 | /* Incomplete buffer has been sent. | 1595 | /* Incomplete buffer has been sent. |
1593 | * Adjust buffer of the last element. */ | 1596 | * Adjust buffer of the last element. */ |
1594 | r_iov->iov[r_iov->sent].iov_base = | 1597 | r_iov->iov[r_iov->sent].iov_base = |
1595 | (void *) ((uint8_t *) r_iov->iov[r_iov->sent].iov_base + (size_t) res); | 1598 | (void *) ((uint8_t *) r_iov->iov[r_iov->sent].iov_base + sent); |
1596 | r_iov->iov[r_iov->sent].iov_len -= res; | 1599 | r_iov->iov[r_iov->sent].iov_len -= sent; |
1597 | 1600 | ||
1598 | return total_sent; | 1601 | return (ssize_t) total_sent; |
1599 | } | 1602 | } |
1600 | /* The iov element has been completely sent */ | 1603 | /* The iov element has been completely sent */ |
1601 | r_iov->sent++; | 1604 | r_iov->sent++; |
diff --git a/src/microhttpd/mhd_str.c b/src/microhttpd/mhd_str.c index fdbed4f8..da60b18d 100644 --- a/src/microhttpd/mhd_str.c +++ b/src/microhttpd/mhd_str.c | |||
@@ -899,12 +899,12 @@ MHD_str_to_uint64_ (const char *str, | |||
899 | return 0; | 899 | return 0; |
900 | 900 | ||
901 | res *= 10; | 901 | res *= 10; |
902 | res += digit; | 902 | res += (unsigned int) digit; |
903 | str++; | 903 | str++; |
904 | } while (isasciidigit (*str)); | 904 | } while (isasciidigit (*str)); |
905 | 905 | ||
906 | *out_val = res; | 906 | *out_val = res; |
907 | return str - start; | 907 | return (size_t) (str - start); |
908 | } | 908 | } |
909 | 909 | ||
910 | 910 | ||
@@ -944,7 +944,7 @@ MHD_str_to_uint64_n_ (const char *str, | |||
944 | return 0; | 944 | return 0; |
945 | 945 | ||
946 | res *= 10; | 946 | res *= 10; |
947 | res += digit; | 947 | res += (unsigned int) digit; |
948 | i++; | 948 | i++; |
949 | } while ( (i < maxlen) && | 949 | } while ( (i < maxlen) && |
950 | isasciidigit (str[i]) ); | 950 | isasciidigit (str[i]) ); |
@@ -984,7 +984,7 @@ MHD_strx_to_uint32_ (const char *str, | |||
984 | % 16)) ) ) | 984 | % 16)) ) ) |
985 | { | 985 | { |
986 | res *= 16; | 986 | res *= 16; |
987 | res += digit; | 987 | res += (unsigned int) digit; |
988 | } | 988 | } |
989 | else | 989 | else |
990 | return 0; | 990 | return 0; |
@@ -994,7 +994,7 @@ MHD_strx_to_uint32_ (const char *str, | |||
994 | 994 | ||
995 | if (str - start > 0) | 995 | if (str - start > 0) |
996 | *out_val = res; | 996 | *out_val = res; |
997 | return str - start; | 997 | return (size_t) (str - start); |
998 | } | 998 | } |
999 | 999 | ||
1000 | 1000 | ||
@@ -1032,7 +1032,7 @@ MHD_strx_to_uint32_n_ (const char *str, | |||
1032 | return 0; | 1032 | return 0; |
1033 | 1033 | ||
1034 | res *= 16; | 1034 | res *= 16; |
1035 | res += digit; | 1035 | res += (unsigned int) digit; |
1036 | i++; | 1036 | i++; |
1037 | } | 1037 | } |
1038 | 1038 | ||
@@ -1071,7 +1071,7 @@ MHD_strx_to_uint64_ (const char *str, | |||
1071 | % 16)) ) ) | 1071 | % 16)) ) ) |
1072 | { | 1072 | { |
1073 | res *= 16; | 1073 | res *= 16; |
1074 | res += digit; | 1074 | res += (unsigned int) digit; |
1075 | } | 1075 | } |
1076 | else | 1076 | else |
1077 | return 0; | 1077 | return 0; |
@@ -1081,7 +1081,7 @@ MHD_strx_to_uint64_ (const char *str, | |||
1081 | 1081 | ||
1082 | if (str - start > 0) | 1082 | if (str - start > 0) |
1083 | *out_val = res; | 1083 | *out_val = res; |
1084 | return str - start; | 1084 | return (size_t) (str - start); |
1085 | } | 1085 | } |
1086 | 1086 | ||
1087 | 1087 | ||
@@ -1119,7 +1119,7 @@ MHD_strx_to_uint64_n_ (const char *str, | |||
1119 | return 0; | 1119 | return 0; |
1120 | 1120 | ||
1121 | res *= 16; | 1121 | res *= 16; |
1122 | res += digit; | 1122 | res += (unsigned int) digit; |
1123 | i++; | 1123 | i++; |
1124 | } | 1124 | } |
1125 | 1125 | ||
@@ -1178,7 +1178,7 @@ MHD_str_to_uvalue_n_ (const char *str, | |||
1178 | return 0; | 1178 | return 0; |
1179 | 1179 | ||
1180 | res *= base; | 1180 | res *= base; |
1181 | res += digit; | 1181 | res += (unsigned int) digit; |
1182 | i++; | 1182 | i++; |
1183 | } | 1183 | } |
1184 | 1184 | ||
@@ -1330,7 +1330,7 @@ MHD_uint8_to_str_pad (uint8_t val, | |||
1330 | } | 1330 | } |
1331 | else | 1331 | else |
1332 | { | 1332 | { |
1333 | buf[pos++] = '0' + digit; | 1333 | buf[pos++] = '0' + (char) digit; |
1334 | val %= 100; | 1334 | val %= 100; |
1335 | min_digits = 2; | 1335 | min_digits = 2; |
1336 | } | 1336 | } |
@@ -1345,13 +1345,13 @@ MHD_uint8_to_str_pad (uint8_t val, | |||
1345 | } | 1345 | } |
1346 | else | 1346 | else |
1347 | { | 1347 | { |
1348 | buf[pos++] = '0' + digit; | 1348 | buf[pos++] = '0' + (char) digit; |
1349 | val %= 10; | 1349 | val %= 10; |
1350 | } | 1350 | } |
1351 | 1351 | ||
1352 | if (buf_size <= pos) | 1352 | if (buf_size <= pos) |
1353 | return 0; | 1353 | return 0; |
1354 | buf[pos++] = '0' + val; | 1354 | buf[pos++] = '0' + (char) val; |
1355 | return pos; | 1355 | return pos; |
1356 | } | 1356 | } |
1357 | 1357 | ||
diff --git a/src/microhttpd/postprocessor.c b/src/microhttpd/postprocessor.c index d32ecc22..39070334 100644 --- a/src/microhttpd/postprocessor.c +++ b/src/microhttpd/postprocessor.c | |||
@@ -367,20 +367,23 @@ process_value (struct MHD_PostProcessor *pp, | |||
367 | if ( (NULL != last_escape) && | 367 | if ( (NULL != last_escape) && |
368 | (((size_t) (value_end - last_escape)) < sizeof (pp->xbuf)) ) | 368 | (((size_t) (value_end - last_escape)) < sizeof (pp->xbuf)) ) |
369 | { | 369 | { |
370 | pp->xbuf_pos = value_end - last_escape; | 370 | mhd_assert (value_end >= last_escape); |
371 | pp->xbuf_pos = (size_t) (value_end - last_escape); | ||
371 | memcpy (pp->xbuf, | 372 | memcpy (pp->xbuf, |
372 | last_escape, | 373 | last_escape, |
373 | value_end - last_escape); | 374 | (size_t) (value_end - last_escape)); |
374 | value_end = last_escape; | 375 | value_end = last_escape; |
375 | } | 376 | } |
376 | while ( (value_start != value_end) || | 377 | while ( (value_start != value_end) || |
377 | (pp->must_ikvi) || | 378 | (pp->must_ikvi) || |
378 | (xoff > 0) ) | 379 | (xoff > 0) ) |
379 | { | 380 | { |
380 | size_t delta = value_end - value_start; | 381 | size_t delta = (size_t) (value_end - value_start); |
381 | bool cut = false; | 382 | bool cut = false; |
382 | size_t clen = 0; | 383 | size_t clen = 0; |
383 | 384 | ||
385 | mhd_assert (value_end >= value_start); | ||
386 | |||
384 | if (delta > XBUF_SIZE - xoff) | 387 | if (delta > XBUF_SIZE - xoff) |
385 | delta = XBUF_SIZE - xoff; | 388 | delta = XBUF_SIZE - xoff; |
386 | /* move (additional) input into processing buffer */ | 389 | /* move (additional) input into processing buffer */ |
@@ -660,7 +663,8 @@ post_process_urlencoded (struct MHD_PostProcessor *pp, | |||
660 | mhd_assert ((NULL != end_key) || (NULL == start_key)); | 663 | mhd_assert ((NULL != end_key) || (NULL == start_key)); |
661 | if (1) | 664 | if (1) |
662 | { | 665 | { |
663 | const size_t key_len = end_key - start_key; | 666 | const size_t key_len = (size_t) (end_key - start_key); |
667 | mhd_assert (end_key >= start_key); | ||
664 | if (0 != key_len) | 668 | if (0 != key_len) |
665 | { | 669 | { |
666 | if ( (pp->buffer_pos + key_len >= pp->buffer_size) || | 670 | if ( (pp->buffer_pos + key_len >= pp->buffer_size) || |
@@ -725,7 +729,8 @@ post_process_urlencoded (struct MHD_PostProcessor *pp, | |||
725 | mhd_assert ((PP_ProcessKey == pp->state) || (NULL != end_key)); | 729 | mhd_assert ((PP_ProcessKey == pp->state) || (NULL != end_key)); |
726 | if (NULL == end_key) | 730 | if (NULL == end_key) |
727 | end_key = &post_data[poff]; | 731 | end_key = &post_data[poff]; |
728 | key_len = end_key - start_key; | 732 | mhd_assert (end_key >= start_key); |
733 | key_len = (size_t) (end_key - start_key); | ||
729 | mhd_assert (0 != key_len); /* it must be always non-zero here */ | 734 | mhd_assert (0 != key_len); /* it must be always non-zero here */ |
730 | if (pp->buffer_pos + key_len >= pp->buffer_size) | 735 | if (pp->buffer_pos + key_len >= pp->buffer_size) |
731 | { | 736 | { |
@@ -854,13 +859,13 @@ find_boundary (struct MHD_PostProcessor *pp, | |||
854 | '-', | 859 | '-', |
855 | pp->buffer_pos); | 860 | pp->buffer_pos); |
856 | if (NULL == dash) | 861 | if (NULL == dash) |
857 | (*ioffptr) += pp->buffer_pos; /* skip entire buffer */ | 862 | (*ioffptr) += pp->buffer_pos; /* skip entire buffer */ |
858 | else if (dash == buf) | 863 | else if (dash == buf) |
859 | (*ioffptr)++; /* at least skip one byte */ | 864 | (*ioffptr)++; /* at least skip one byte */ |
860 | else | 865 | else |
861 | (*ioffptr) += dash - buf; /* skip to first possible boundary */ | 866 | (*ioffptr) += (size_t) (dash - buf); /* skip to first possible boundary */ |
862 | } | 867 | } |
863 | return MHD_NO; /* expected boundary */ | 868 | return MHD_NO; /* expected boundary */ |
864 | } | 869 | } |
865 | /* remove boundary from buffer */ | 870 | /* remove boundary from buffer */ |
866 | (*ioffptr) += 2 + blen; | 871 | (*ioffptr) += 2 + blen; |
@@ -908,7 +913,7 @@ try_get_value (const char *buf, | |||
908 | if (NULL == (endv = strchr (&spos[klen + 2], | 913 | if (NULL == (endv = strchr (&spos[klen + 2], |
909 | '\"'))) | 914 | '\"'))) |
910 | return; /* no end-quote */ | 915 | return; /* no end-quote */ |
911 | vlen = endv - spos - klen - 1; | 916 | vlen = (size_t) (endv - spos) - klen - 1; |
912 | *destination = malloc (vlen); | 917 | *destination = malloc (vlen); |
913 | if (NULL == *destination) | 918 | if (NULL == *destination) |
914 | return; /* out of memory */ | 919 | return; /* out of memory */ |
@@ -1037,7 +1042,7 @@ process_value_to_boundary (struct MHD_PostProcessor *pp, | |||
1037 | newline = pp->buffer_pos - 4; | 1042 | newline = pp->buffer_pos - 4; |
1038 | break; | 1043 | break; |
1039 | } | 1044 | } |
1040 | newline = r - buf; | 1045 | newline = (size_t) (r - buf); |
1041 | if (0 == memcmp ("\r\n--", | 1046 | if (0 == memcmp ("\r\n--", |
1042 | &buf[newline], | 1047 | &buf[newline], |
1043 | 4)) | 1048 | 4)) |
diff --git a/src/microhttpd/response.c b/src/microhttpd/response.c index 47e28046..0a70c0f7 100644 --- a/src/microhttpd/response.c +++ b/src/microhttpd/response.c | |||
@@ -213,11 +213,11 @@ add_response_header_connection (struct MHD_Response *response, | |||
213 | /** the length of the "Connection" key */ | 213 | /** the length of the "Connection" key */ |
214 | static const size_t key_len = | 214 | static const size_t key_len = |
215 | MHD_STATICSTR_LEN_ (MHD_HTTP_HEADER_CONNECTION); | 215 | MHD_STATICSTR_LEN_ (MHD_HTTP_HEADER_CONNECTION); |
216 | size_t value_len; /**< the length of the @a value */ | 216 | size_t value_len; /**< the length of the @a value */ |
217 | size_t old_value_len; /**< the length of the existing "Connection" value */ | 217 | size_t old_value_len; /**< the length of the existing "Connection" value */ |
218 | size_t buf_size; /**< the size of the buffer */ | 218 | size_t buf_size; /**< the size of the buffer */ |
219 | ssize_t norm_len; /**< the length of the normalised value */ | 219 | size_t norm_len; /**< the length of the normalised value */ |
220 | char *buf; /**< the temporal buffer */ | 220 | char *buf; /**< the temporal buffer */ |
221 | struct MHD_HTTP_Res_Header *hdr; /**< existing "Connection" header */ | 221 | struct MHD_HTTP_Res_Header *hdr; /**< existing "Connection" header */ |
222 | bool value_has_close; /**< the @a value has "close" token */ | 222 | bool value_has_close; /**< the @a value has "close" token */ |
223 | bool already_has_close; /**< existing "Connection" header has "close" token */ | 223 | bool already_has_close; /**< existing "Connection" header has "close" token */ |
@@ -253,19 +253,27 @@ add_response_header_connection (struct MHD_Response *response, | |||
253 | value_len = strlen (value); | 253 | value_len = strlen (value); |
254 | if (value_len >= SSIZE_MAX) | 254 | if (value_len >= SSIZE_MAX) |
255 | return MHD_NO; | 255 | return MHD_NO; |
256 | /* Additional space for normalisation and zero-termination*/ | 256 | /* Additional space for normalisation and zero-termination */ |
257 | norm_len = (ssize_t) (value_len + value_len / 2 + 1); | 257 | norm_len = value_len + value_len / 2 + 1; |
258 | buf_size = old_value_len + (size_t) norm_len; | 258 | buf_size = old_value_len + (size_t) norm_len; |
259 | 259 | ||
260 | buf = malloc (buf_size); | 260 | buf = malloc (buf_size); |
261 | if (NULL == buf) | 261 | if (NULL == buf) |
262 | return MHD_NO; | 262 | return MHD_NO; |
263 | /* Remove "close" token (if any), it will be moved to the front */ | 263 | if (1) |
264 | value_has_close = MHD_str_remove_token_caseless_ (value, value_len, "close", | 264 | { /* local scope */ |
265 | MHD_STATICSTR_LEN_ ( \ | 265 | ssize_t norm_len_s = (ssize_t) norm_len; |
266 | "close"), | 266 | /* Remove "close" token (if any), it will be moved to the front */ |
267 | buf + old_value_len, | 267 | value_has_close = MHD_str_remove_token_caseless_ (value, value_len, "close", |
268 | &norm_len); | 268 | MHD_STATICSTR_LEN_ ( \ |
269 | "close"), | ||
270 | buf + old_value_len, | ||
271 | &norm_len_s); | ||
272 | mhd_assert (0 <= norm_len_s); | ||
273 | if (0 > norm_len_s) | ||
274 | norm_len = 0; /* Must never happen */ | ||
275 | norm_len = (size_t) norm_len; | ||
276 | } | ||
269 | #ifdef UPGRADE_SUPPORT | 277 | #ifdef UPGRADE_SUPPORT |
270 | if ( (NULL != response->upgrade_handler) && value_has_close) | 278 | if ( (NULL != response->upgrade_handler) && value_has_close) |
271 | { /* The "close" token cannot be used with connection "upgrade" */ | 279 | { /* The "close" token cannot be used with connection "upgrade" */ |
@@ -273,17 +281,10 @@ add_response_header_connection (struct MHD_Response *response, | |||
273 | return MHD_NO; | 281 | return MHD_NO; |
274 | } | 282 | } |
275 | #endif /* UPGRADE_SUPPORT */ | 283 | #endif /* UPGRADE_SUPPORT */ |
276 | mhd_assert (0 <= norm_len); | ||
277 | if (0 > norm_len) | ||
278 | norm_len = 0; /* Must never happen */ | ||
279 | if (0 != norm_len) | 284 | if (0 != norm_len) |
280 | { | 285 | MHD_str_remove_tokens_caseless_ (buf + old_value_len, &norm_len, |
281 | size_t len = norm_len; | ||
282 | MHD_str_remove_tokens_caseless_ (buf + old_value_len, &len, | ||
283 | "keep-alive", | 286 | "keep-alive", |
284 | MHD_STATICSTR_LEN_ ("keep-alive")); | 287 | MHD_STATICSTR_LEN_ ("keep-alive")); |
285 | norm_len = (ssize_t) len; | ||
286 | } | ||
287 | if (0 == norm_len) | 288 | if (0 == norm_len) |
288 | { /* New value is empty after normalisation */ | 289 | { /* New value is empty after normalisation */ |
289 | if (! value_has_close) | 290 | if (! value_has_close) |
@@ -301,7 +302,7 @@ add_response_header_connection (struct MHD_Response *response, | |||
301 | if (value_has_close && ! already_has_close) | 302 | if (value_has_close && ! already_has_close) |
302 | { | 303 | { |
303 | /* Need to insert "close" token at the first position */ | 304 | /* Need to insert "close" token at the first position */ |
304 | mhd_assert (buf_size >= old_value_len + (size_t) norm_len \ | 305 | mhd_assert (buf_size >= old_value_len + norm_len \ |
305 | + MHD_STATICSTR_LEN_ ("close, ") + 1); | 306 | + MHD_STATICSTR_LEN_ ("close, ") + 1); |
306 | if (0 != norm_len) | 307 | if (0 != norm_len) |
307 | memmove (buf + MHD_STATICSTR_LEN_ ("close, ") + old_value_len, | 308 | memmove (buf + MHD_STATICSTR_LEN_ ("close, ") + old_value_len, |
@@ -333,7 +334,7 @@ add_response_header_connection (struct MHD_Response *response, | |||
333 | mhd_assert ((value_has_close && ! already_has_close) ? \ | 334 | mhd_assert ((value_has_close && ! already_has_close) ? \ |
334 | (MHD_STATICSTR_LEN_ ("close, ") + old_value_len == pos) : \ | 335 | (MHD_STATICSTR_LEN_ ("close, ") + old_value_len == pos) : \ |
335 | (old_value_len == pos)); | 336 | (old_value_len == pos)); |
336 | pos += (size_t) norm_len; | 337 | pos += norm_len; |
337 | } | 338 | } |
338 | mhd_assert (buf_size > pos); | 339 | mhd_assert (buf_size > pos); |
339 | buf[pos] = 0; /* Null terminate the result */ | 340 | buf[pos] = 0; /* Null terminate the result */ |
@@ -1118,7 +1119,7 @@ MHD_create_response_from_fd_at_offset (size_t size, | |||
1118 | { | 1119 | { |
1119 | return MHD_create_response_from_fd_at_offset64 (size, | 1120 | return MHD_create_response_from_fd_at_offset64 (size, |
1120 | fd, | 1121 | fd, |
1121 | offset); | 1122 | (uint64_t) offset); |
1122 | } | 1123 | } |
1123 | 1124 | ||
1124 | 1125 | ||
@@ -1631,7 +1632,7 @@ MHD_create_response_from_iovec (const struct MHD_IoVec *iov, | |||
1631 | MHD_iovec_ *iov_copy; | 1632 | MHD_iovec_ *iov_copy; |
1632 | int num_copy_elements = i_cp; | 1633 | int num_copy_elements = i_cp; |
1633 | 1634 | ||
1634 | iov_copy = MHD_calloc_ (num_copy_elements, | 1635 | iov_copy = MHD_calloc_ ((size_t) num_copy_elements, \ |
1635 | sizeof(MHD_iovec_)); | 1636 | sizeof(MHD_iovec_)); |
1636 | if (NULL == iov_copy) | 1637 | if (NULL == iov_copy) |
1637 | { | 1638 | { |
@@ -1662,8 +1663,9 @@ MHD_create_response_from_iovec (const struct MHD_IoVec *iov, | |||
1662 | i_cp++; | 1663 | i_cp++; |
1663 | } | 1664 | } |
1664 | mhd_assert (num_copy_elements == i_cp); | 1665 | mhd_assert (num_copy_elements == i_cp); |
1666 | mhd_assert (0 <= i_cp); | ||
1665 | response->data_iov = iov_copy; | 1667 | response->data_iov = iov_copy; |
1666 | response->data_iovcnt = i_cp; | 1668 | response->data_iovcnt = (unsigned int) i_cp; |
1667 | } | 1669 | } |
1668 | return response; | 1670 | return response; |
1669 | } | 1671 | } |