From 9658c80b48de25d9f567e63636364b7259a65e41 Mon Sep 17 00:00:00 2001 From: Michael Date: Thu, 3 Jan 2019 21:25:09 +0000 Subject: [PATCH] Minor build fixes --- CMakeLists.txt | 3 ++- llarp/crypto.cpp | 4 +++- llarp/ev_kqueue.hpp | 6 ++++-- llarp/link/utp.cpp | 2 +- llarp/link/utp_internal.hpp | 6 +++++- llarp/profiling.cpp | 5 ++--- 6 files changed, 17 insertions(+), 9 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index ae4d3e690..9d3fe03be 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -116,7 +116,7 @@ if(NOT DEBIAN) endif(NOT DEBIAN) if(ASAN) - set(DEBUG_FLAGS "${DEBUG_FLAGS} -fsanitize=address -fno-omit-frame-pointer") + set(DEBUG_FLAGS ${DEBUG_FLAGS} -fsanitize=address -fno-omit-frame-pointer) set(OPTIMIZE_FLAGS "-O0") endif(ASAN) @@ -146,6 +146,7 @@ endif(SHADOW) if(CMAKE_BUILD_TYPE MATCHES "[Dd][Ee][Bb][Uu][Gg]") set(OPTIMIZE_FLAGS "") add_compile_options( ${DEBUG_FLAGS} ) + link_libraries( ${DEBUG_FLAGS} ) endif(CMAKE_BUILD_TYPE MATCHES "[Dd][Ee][Bb][Uu][Gg]") # Add non-386 target-specific options here diff --git a/llarp/crypto.cpp b/llarp/crypto.cpp index 445b00b59..8c3eed86e 100644 --- a/llarp/crypto.cpp +++ b/llarp/crypto.cpp @@ -1,7 +1,9 @@ #include -#include #include +#include +#include + namespace llarp { bool diff --git a/llarp/ev_kqueue.hpp b/llarp/ev_kqueue.hpp index cbbba4911..b9bf8699d 100644 --- a/llarp/ev_kqueue.hpp +++ b/llarp/ev_kqueue.hpp @@ -417,12 +417,12 @@ struct llarp_kqueue_loop : public llarp_ev_loop int tick(int ms) { - struct kevent events[1024]; + std::array< struct kevent, 1024 > events; int result; timespec t; t.tv_sec = 0; t.tv_nsec = ms * 1000000UL; - result = kevent(kqueuefd, nullptr, 0, events, 1024, &t); + result = kevent(kqueuefd, nullptr, 0, events.data(), events.size(), &t); // result: 0 is a timeout if(result > 0) { @@ -436,7 +436,9 @@ struct llarp_kqueue_loop : public llarp_ev_loop ev->read(readbuf, std::min(sizeof(readbuf), size_t(events[idx].data))); if(events[idx].filter & EVFILT_WRITE) + { ev->flush_write_buffers(events[idx].data); + } } ++idx; } diff --git a/llarp/link/utp.cpp b/llarp/link/utp.cpp index 267c6ec6c..c2ea5a96a 100644 --- a/llarp/link/utp.cpp +++ b/llarp/link/utp.cpp @@ -1064,7 +1064,7 @@ namespace llarp // get message if(m_RecvMsgs.find(msgid) == m_RecvMsgs.end()) - m_RecvMsgs.emplace(std::make_pair(msgid, InboundMessage{})); + m_RecvMsgs.emplace(msgid, InboundMessage{}); auto itr = m_RecvMsgs.find(msgid); // add message activity diff --git a/llarp/link/utp_internal.hpp b/llarp/link/utp_internal.hpp index e73a400a4..6401bb979 100644 --- a/llarp/link/utp_internal.hpp +++ b/llarp/link/utp_internal.hpp @@ -55,7 +55,11 @@ namespace llarp MessageBuffer _msg; /// for accessing message buffer - llarp_buffer_t buffer = _msg.as_buffer(); + llarp_buffer_t buffer; + + InboundMessage() : lastActive(0), _msg(), buffer(_msg.as_buffer()) + { + } bool operator==(const InboundMessage& other) const diff --git a/llarp/profiling.cpp b/llarp/profiling.cpp index bd323fc66..cdd5d6a7b 100644 --- a/llarp/profiling.cpp +++ b/llarp/profiling.cpp @@ -100,8 +100,8 @@ namespace llarp lock_t lock(m_ProfilesMutex); size_t sz = (m_Profiles.size() * (RouterProfile::MaxSize + 32 + 8)) + 8; - byte_t* tmp = new byte_t[sz]; - auto buf = llarp::InitBuffer(tmp, sz); + std::vector tmp(sz, 0); + auto buf = llarp::Buffer(tmp); auto res = BEncode(&buf); if(res) { @@ -113,7 +113,6 @@ namespace llarp f.write((char*)buf.base, buf.sz); } } - delete[] tmp; return res; }