Skip to content

Commit 26fcc03

Browse files
committed
Applied some minor fixes discovered by Coverity.
1 parent 657b5a2 commit 26fcc03

File tree

3 files changed

+23
-9
lines changed

3 files changed

+23
-9
lines changed

README.rst

+3
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ Modern C++ network programming libraries.
66
.. image:: https://travis-ci.org/cpp-netlib/cpp-netlib.svg?branch=master
77
:target: https://travis-ci.org/cpp-netlib/cpp-netlib
88

9+
.. image:: https://scan.coverity.com/projects/6714/badge.svg
10+
:target: https://scan.coverity.com/projects/cpp-netlib
11+
912
Join us on Slack: http://slack.cpp-netlib.org/
1013

1114
Subscribe to the mailing list: https://groups.google.com/forum/#!forum/cpp-netlib

boost/network/protocol/http/server/async_connection.hpp

+1
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,7 @@ struct async_connection
199199
headers_in_progress(false) {
200200
(void)ctx;
201201
new_start = read_buffer_.begin();
202+
data_end = read_buffer_.begin();
202203
}
203204

204205
~async_connection() throw() {

libs/network/example/http/fileserver.cpp

+19-9
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ struct file_cache {
3333
explicit file_cache(std::string doc_root) : doc_root_(std::move(doc_root)) {}
3434

3535
~file_cache() throw() {
36-
BOOST_FOREACH(region_map::value_type const & region, regions) {
36+
for (auto &region : regions) {
3737
munmap(region.second.first, region.second.second);
3838
}
3939
}
@@ -53,7 +53,11 @@ struct file_cache {
5353
int fd = open(real_filename.c_str(), O_RDONLY | O_NONBLOCK);
5454
#endif
5555
if (fd == -1) return false;
56-
std::size_t size = lseek(fd, 0, SEEK_END);
56+
off_t size = lseek(fd, 0, SEEK_END);
57+
if (size == -1) {
58+
close(fd);
59+
return false;
60+
}
5761
void *region = mmap(0, size, PROT_READ, MAP_PRIVATE, fd, 0);
5862
if (region == MAP_FAILED) {
5963
close(fd);
@@ -68,6 +72,7 @@ struct file_cache {
6872
common_headers + 3);
6973
headers[2].value = std::to_string(size);
7074
file_headers.insert(std::make_pair(real_filename, headers));
75+
close(fd);
7176
return true;
7277
}
7378

@@ -174,11 +179,16 @@ struct file_server {
174179
};
175180

176181
int main(int, char *[]) {
177-
file_cache cache(".");
178-
file_server handler(cache);
179-
server::options options(handler);
180-
server instance(options.thread_pool(std::make_shared<utils::thread_pool>(4))
181-
.address("0.0.0.0")
182-
.port("8000"));
183-
instance.run();
182+
try {
183+
file_cache cache(".");
184+
file_server handler(cache);
185+
server::options options(handler);
186+
server instance(options.thread_pool(std::make_shared<utils::thread_pool>(4))
187+
.address("0.0.0.0")
188+
.port("8000"));
189+
instance.run();
190+
}
191+
catch (std::exception &e) {
192+
std::cerr << e.what() << std::endl;
193+
}
184194
}

0 commit comments

Comments
 (0)