diff --git a/core/Buf.cpp b/core/Buf.cpp index 4091b9c6f..8e770a714 100644 --- a/core/Buf.cpp +++ b/core/Buf.cpp @@ -43,7 +43,7 @@ void *Buf::operator new(std::size_t sz) s_pool.store(0); b = (Buf *) malloc(sz); if (!b) - throw std::bad_alloc(); + throw Utils::BadAllocException; ++s_allocated; } diff --git a/core/FCV.hpp b/core/FCV.hpp index ad99822b7..0d6592985 100644 --- a/core/FCV.hpp +++ b/core/FCV.hpp @@ -19,6 +19,7 @@ #include #include #include +#include namespace ZeroTier { @@ -114,14 +115,14 @@ public: { if (likely(i < _s)) return reinterpret_cast(_m)[i]; - throw std::out_of_range("i > capacity"); + throw Utils::OutOfRangeException; } ZT_INLINE const T &operator[](const unsigned int i) const { if (likely(i < _s)) return reinterpret_cast(_m)[i]; - throw std::out_of_range("i > capacity"); + throw Utils::OutOfRangeException; } static constexpr unsigned int capacity() noexcept @@ -150,7 +151,7 @@ public: { if (likely(_s < C)) new(reinterpret_cast(_m) + _s++) T(v); - else throw std::out_of_range("capacity exceeded"); + throw Utils::OutOfRangeException; } /** @@ -200,7 +201,7 @@ public: ZT_INLINE void resize(unsigned int ns) { if (unlikely(ns > C)) - throw std::out_of_range("capacity exceeded"); + throw Utils::OutOfRangeException; unsigned int s = _s; while (s < ns) new(reinterpret_cast(_m) + s++) T(); diff --git a/core/Utils.cpp b/core/Utils.cpp index 869462488..51d9a0c90 100644 --- a/core/Utils.cpp +++ b/core/Utils.cpp @@ -84,6 +84,8 @@ CPUIDRegisters::CPUIDRegisters() noexcept const CPUIDRegisters CPUID; #endif +const std::bad_alloc BadAllocException; +const std::out_of_range OutOfRangeException("access out of range"); const uint64_t ZERO256[4] = {0, 0, 0, 0}; const char HEXCHARS[16] = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'}; const uint64_t s_mapNonce = getSecureRandomU64(); diff --git a/core/Utils.hpp b/core/Utils.hpp index 57021d624..9da4e4729 100644 --- a/core/Utils.hpp +++ b/core/Utils.hpp @@ -69,6 +69,9 @@ struct CPUIDRegisters extern const CPUIDRegisters CPUID; #endif +extern const std::bad_alloc BadAllocException; +extern const std::out_of_range OutOfRangeException; + /** * 256 zero bits / 32 zero bytes */ @@ -862,7 +865,7 @@ struct Mallocator return nullptr; pointer temp = (pointer)malloc(s * sizeof(T)); if (temp == nullptr) - throw std::bad_alloc(); + throw BadAllocException; return temp; } diff --git a/pkg/zerotier/node.go b/pkg/zerotier/node.go index c15abe079..c7329e625 100644 --- a/pkg/zerotier/node.go +++ b/pkg/zerotier/node.go @@ -14,8 +14,8 @@ package zerotier // #cgo CFLAGS: -O3 -I${SRCDIR}/../../build/core -// #cgo darwin LDFLAGS: -Wl,-undefined -Wl,dynamic_lookup -// #cgo !darwin LDFLAGS: -Wl,-unresolved-symbols=ignore-all +// #cgo darwin LDFLAGS: -Wl,-undefined -Wl,dynamic_lookup -lc++ +// #cgo !darwin LDFLAGS: -Wl,-unresolved-symbols=ignore-all -lstdc++ // #include "../../serviceiocore/GoGlue.h" import "C"