diff options
author | Evgeny Grin (Karlson2k) <k2k@narod.ru> | 2015-08-08 12:29:34 +0000 |
---|---|---|
committer | Evgeny Grin (Karlson2k) <k2k@narod.ru> | 2015-08-08 12:29:34 +0000 |
commit | 1ff4b273acc0221fb89b922f16d636adc0ea9116 (patch) | |
tree | 78912d45bef263d9cf017db657fd85c0f674f245 /src/microhttpd/connection.c | |
parent | 341b9db92e91d9ddcf8230a0329c52e319bdee1f (diff) | |
download | libmicrohttpd-1ff4b273acc0221fb89b922f16d636adc0ea9116.tar.gz libmicrohttpd-1ff4b273acc0221fb89b922f16d636adc0ea9116.zip |
connection.c: try_ready_chunked_body(): fix VS compiler warning, small refactoring for readability
Diffstat (limited to 'src/microhttpd/connection.c')
-rw-r--r-- | src/microhttpd/connection.c | 15 |
1 files changed, 8 insertions, 7 deletions
diff --git a/src/microhttpd/connection.c b/src/microhttpd/connection.c index 0933a7f7..b4125211 100644 --- a/src/microhttpd/connection.c +++ b/src/microhttpd/connection.c | |||
@@ -411,7 +411,7 @@ try_ready_chunked_body (struct MHD_Connection *connection) | |||
411 | response = connection->response; | 411 | response = connection->response; |
412 | if (0 == connection->write_buffer_size) | 412 | if (0 == connection->write_buffer_size) |
413 | { | 413 | { |
414 | size = connection->daemon->pool_size; | 414 | size = MHD_MIN(connection->daemon->pool_size, 2 * (0xFFFFFF + sizeof(cbuf) + 2)); |
415 | do | 415 | do |
416 | { | 416 | { |
417 | size /= 2; | 417 | size /= 2; |
@@ -433,17 +433,18 @@ try_ready_chunked_body (struct MHD_Connection *connection) | |||
433 | ret = 0; /* response must be empty, don't bother calling crc */ | 433 | ret = 0; /* response must be empty, don't bother calling crc */ |
434 | else if ( (response->data_start <= | 434 | else if ( (response->data_start <= |
435 | connection->response_write_position) && | 435 | connection->response_write_position) && |
436 | (response->data_size + response->data_start > | 436 | (response->data_start + response->data_size > |
437 | connection->response_write_position) ) | 437 | connection->response_write_position) ) |
438 | { | 438 | { |
439 | /* difference between response_write_position and data_start is less | ||
440 | than data_size which is size_t type, no need to check for overflow */ | ||
441 | const size_t data_write_offset = (size_t)(connection->response_write_position - response->data_start); | ||
439 | /* buffer already ready, use what is there for the chunk */ | 442 | /* buffer already ready, use what is there for the chunk */ |
440 | ret = response->data_size + response->data_start - connection->response_write_position; | 443 | ret = response->data_size - data_write_offset; |
441 | if ( (ret > 0) && | 444 | if ( ((size_t) ret) > connection->write_buffer_size - sizeof (cbuf) - 2 ) |
442 | (((size_t) ret) > connection->write_buffer_size - sizeof (cbuf) - 2) ) | ||
443 | ret = connection->write_buffer_size - sizeof (cbuf) - 2; | 445 | ret = connection->write_buffer_size - sizeof (cbuf) - 2; |
444 | memcpy (&connection->write_buffer[sizeof (cbuf)], | 446 | memcpy (&connection->write_buffer[sizeof (cbuf)], |
445 | &response->data[connection->response_write_position - response->data_start], | 447 | &response->data[data_write_offset], ret); |
446 | ret); | ||
447 | } | 448 | } |
448 | else | 449 | else |
449 | { | 450 | { |