diff --git a/erb/cpp03_zone.hpp.erb b/erb/cpp03_zone.hpp.erb index 9fe142e8..212c315f 100644 --- a/erb/cpp03_zone.hpp.erb +++ b/erb/cpp03_zone.hpp.erb @@ -202,7 +202,7 @@ inline zone* zone::create(size_t chunk_size) { zone* z = static_cast(::malloc(sizeof(zone) + chunk_size)); if (!z) { - return nullptr; + throw std::bad_alloc(); } new (z) zone(chunk_size); return z; @@ -248,6 +248,7 @@ inline void* zone::allocate_expand(size_t size) } chunk* c = static_cast(::malloc(sizeof(chunk) + sz)); + if (!c) throw std::bad_alloc(); char* ptr = reinterpret_cast(c) + sizeof(chunk); diff --git a/include/msgpack/detail/cpp03_zone.hpp b/include/msgpack/detail/cpp03_zone.hpp index 9e6471b9..143402f3 100644 --- a/include/msgpack/detail/cpp03_zone.hpp +++ b/include/msgpack/detail/cpp03_zone.hpp @@ -247,7 +247,7 @@ inline zone* zone::create(size_t chunk_size) { zone* z = static_cast(::malloc(sizeof(zone) + chunk_size)); if (!z) { - return nullptr; + throw std::bad_alloc(); } new (z) zone(chunk_size); return z; @@ -293,6 +293,7 @@ inline void* zone::allocate_expand(size_t size) } chunk* c = static_cast(::malloc(sizeof(chunk) + sz)); + if (!c) throw std::bad_alloc(); char* ptr = reinterpret_cast(c) + sizeof(chunk); diff --git a/include/msgpack/detail/cpp11_zone.hpp b/include/msgpack/detail/cpp11_zone.hpp index 73d7d79f..7ea92863 100644 --- a/include/msgpack/detail/cpp11_zone.hpp +++ b/include/msgpack/detail/cpp11_zone.hpp @@ -202,7 +202,7 @@ inline zone* zone::create(size_t chunk_size) { zone* z = static_cast(::malloc(sizeof(zone) + chunk_size)); if (!z) { - return nullptr; + throw std::bad_alloc(); } new (z) zone(chunk_size); return z; @@ -248,7 +248,7 @@ inline void* zone::allocate_expand(size_t size) } chunk* c = static_cast(::malloc(sizeof(chunk) + sz)); - if (!c) return nullptr; + if (!c) throw std::bad_alloc(); char* ptr = reinterpret_cast(c) + sizeof(chunk); diff --git a/include/msgpack/unpack.hpp b/include/msgpack/unpack.hpp index 9836d65d..e3c7a535 100644 --- a/include/msgpack/unpack.hpp +++ b/include/msgpack/unpack.hpp @@ -106,12 +106,10 @@ inline void unpack_false(object& o) { o.type = type::BOOLEAN; o.via.boolean = false; } struct unpack_array { - bool operator()(unpack_user&u, unsigned int n, object& o) const { + void operator()(unpack_user&u, unsigned int n, object& o) const { o.type = type::ARRAY; o.via.array.size = 0; o.via.array.ptr = static_cast(u.zone().allocate_align(n*sizeof(object))); - if(o.via.array.ptr == nullptr) { return false; } - return true; } }; @@ -125,12 +123,10 @@ inline void unpack_array_item(object& c, object const& o) } struct unpack_map { - bool operator()(unpack_user& u, unsigned int n, object& o) const { + void operator()(unpack_user& u, unsigned int n, object& o) const { o.type = type::MAP; o.via.map.size = 0; o.via.map.ptr = static_cast(u.zone().allocate_align(n*sizeof(object_kv))); - if(o.via.map.ptr == nullptr) { return false; } - return true; } }; @@ -623,23 +619,18 @@ private: if(m_top < MSGPACK_EMBED_STACK_SIZE /* FIXME */) { typename value::type tmp; load(tmp, load_pos); - if (f(m_user, tmp, m_stack[m_top].obj())) { - if(tmp == 0) { - obj = m_stack[m_top].obj(); - int ret = push_proc(obj, off); - if (ret != 0) return ret; - } - else { - m_stack[m_top].set_container_type(container_type); - m_stack[m_top].set_count(tmp); - ++m_top; - m_cs = CS_HEADER; - ++m_current; - } + f(m_user, tmp, m_stack[m_top].obj()); + if(tmp == 0) { + obj = m_stack[m_top].obj(); + int ret = push_proc(obj, off); + if (ret != 0) return ret; } else { - off = m_current - m_start; - return -1; + m_stack[m_top].set_container_type(container_type); + m_stack[m_top].set_count(tmp); + ++m_top; + m_cs = CS_HEADER; + ++m_current; } } else {