aboutsummaryrefslogtreecommitdiff
path: root/contrib/epee/include
diff options
context:
space:
mode:
Diffstat (limited to 'contrib/epee/include')
-rw-r--r--contrib/epee/include/misc_os_dependent.h2
-rw-r--r--contrib/epee/include/net/abstract_tcp_server2.inl24
-rw-r--r--contrib/epee/include/serialization/keyvalue_serialization_overloads.h6
-rw-r--r--contrib/epee/include/storages/parserse_base_utils.h9
4 files changed, 35 insertions, 6 deletions
diff --git a/contrib/epee/include/misc_os_dependent.h b/contrib/epee/include/misc_os_dependent.h
index ffe575501..0d09683d6 100644
--- a/contrib/epee/include/misc_os_dependent.h
+++ b/contrib/epee/include/misc_os_dependent.h
@@ -24,7 +24,7 @@
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
#ifdef _WIN32
-#include <Winsock2.h>
+#include <winsock2.h>
#endif
#ifdef WIN32
diff --git a/contrib/epee/include/net/abstract_tcp_server2.inl b/contrib/epee/include/net/abstract_tcp_server2.inl
index 59a126163..3a5c83017 100644
--- a/contrib/epee/include/net/abstract_tcp_server2.inl
+++ b/contrib/epee/include/net/abstract_tcp_server2.inl
@@ -1109,8 +1109,16 @@ POP_WARNINGS
sock_.open(remote_endpoint.protocol());
if(bind_ip != "0.0.0.0" && bind_ip != "0" && bind_ip != "" )
{
- boost::asio::ip::tcp::endpoint local_endpoint(boost::asio::ip::address::from_string(adr.c_str()), 0);
- sock_.bind(local_endpoint);
+ boost::asio::ip::tcp::endpoint local_endpoint(boost::asio::ip::address::from_string(bind_ip.c_str()), 0);
+ boost::system::error_code ec;
+ sock_.bind(local_endpoint, ec);
+ if (ec)
+ {
+ MERROR("Error binding to " << bind_ip << ": " << ec.message());
+ if (sock_.is_open())
+ sock_.close();
+ return false;
+ }
}
/*
@@ -1215,8 +1223,16 @@ POP_WARNINGS
sock_.open(remote_endpoint.protocol());
if(bind_ip != "0.0.0.0" && bind_ip != "0" && bind_ip != "" )
{
- boost::asio::ip::tcp::endpoint local_endpoint(boost::asio::ip::address::from_string(adr.c_str()), 0);
- sock_.bind(local_endpoint);
+ boost::asio::ip::tcp::endpoint local_endpoint(boost::asio::ip::address::from_string(bind_ip.c_str()), 0);
+ boost::system::error_code ec;
+ sock_.bind(local_endpoint, ec);
+ if (ec)
+ {
+ MERROR("Error binding to " << bind_ip << ": " << ec.message());
+ if (sock_.is_open())
+ sock_.close();
+ return false;
+ }
}
boost::shared_ptr<boost::asio::deadline_timer> sh_deadline(new boost::asio::deadline_timer(io_service_));
diff --git a/contrib/epee/include/serialization/keyvalue_serialization_overloads.h b/contrib/epee/include/serialization/keyvalue_serialization_overloads.h
index 09087f785..15c95f07a 100644
--- a/contrib/epee/include/serialization/keyvalue_serialization_overloads.h
+++ b/contrib/epee/include/serialization/keyvalue_serialization_overloads.h
@@ -35,6 +35,11 @@
namespace epee
{
+ namespace
+ {
+ template<class C> void hint_resize(C &container, size_t size) {}
+ template<class C> void hint_resize(std::vector<C> &container, size_t size) { container.reserve(size); }
+ }
namespace serialization
{
@@ -158,6 +163,7 @@ namespace epee
false,
"size in blob " << loaded_size << " not have not zero modulo for sizeof(value_type) = " << sizeof(typename stl_container::value_type) << ", type " << typeid(typename stl_container::value_type).name());
size_t count = (loaded_size/sizeof(typename stl_container::value_type));
+ hint_resize(container, count);
for(size_t i = 0; i < count; i++)
container.insert(container.end(), *(pelem++));
}
diff --git a/contrib/epee/include/storages/parserse_base_utils.h b/contrib/epee/include/storages/parserse_base_utils.h
index c809392f4..8c6c1a64d 100644
--- a/contrib/epee/include/storages/parserse_base_utils.h
+++ b/contrib/epee/include/storages/parserse_base_utils.h
@@ -28,6 +28,8 @@
#pragma once
+#include <algorithm>
+
namespace epee
{
namespace misc_utils
@@ -36,8 +38,12 @@ namespace misc_utils
{
inline std::string transform_to_escape_sequence(const std::string& src)
{
- //std::stringstream res;
+ static const char escaped[] = "\b\f\n\r\t\v\"\\/";
+ if (std::find_first_of(src.begin(), src.end(), escaped, escaped + sizeof(escaped)) == src.end())
+ return src;
+
std::string res;
+ res.reserve(2 * src.size());
for(std::string::const_iterator it = src.begin(); it!=src.end(); ++it)
{
switch(*it)
@@ -84,6 +90,7 @@ namespace misc_utils
inline void match_string2(std::string::const_iterator& star_end_string, std::string::const_iterator buf_end, std::string& val)
{
val.clear();
+ val.reserve(std::distance(star_end_string, buf_end));
bool escape_mode = false;
std::string::const_iterator it = star_end_string;
++it;