Merge pull request #898 from redboltz/refine_assert

Replaced assert with BOOST_ASSERT.
This commit is contained in:
Takatoshi Kondo 2020-07-03 09:09:20 +09:00 committed by GitHub
commit 70912ffde4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
11 changed files with 40 additions and 22 deletions

View File

@ -11,10 +11,6 @@
#define MSGPACK_UNPACK_DEFINE_HPP
#include "msgpack/sysdep.hpp"
#include <stdlib.h>
#include <string.h>
#include <assert.h>
#include <stdio.h>
#ifndef MSGPACK_EMBED_STACK_SIZE
#define MSGPACK_EMBED_STACK_SIZE 32
@ -77,4 +73,3 @@ typedef enum {
#endif /* msgpack/unpack_define.hpp */

View File

@ -14,7 +14,6 @@
#include "msgpack/adaptor/check_container_size.hpp"
#include <cstring>
#include <string>
#include <cassert>
namespace msgpack {

View File

@ -14,7 +14,6 @@
#include "msgpack/adaptor/adaptor_base.hpp"
#include <cstring>
#include <string>
#include <cassert>
namespace msgpack {

View File

@ -15,6 +15,8 @@
#include <cstdio>
#include <stdexcept>
#include <boost/assert.hpp>
namespace msgpack {
/// @cond
@ -28,6 +30,8 @@ public:
public:
void write(const char* buf, unsigned int len)
{
BOOST_ASSERT(buf || len == 0);
if (!buf) return;
if (1 != fwrite(buf, len, 1, m_file)) {
throw std::runtime_error("fwrite() failed");
}

View File

@ -14,7 +14,8 @@
#include <stdexcept>
#include <cstring>
#include <cassert>
#include <boost/assert.hpp>
namespace msgpack {
@ -69,14 +70,15 @@ public:
void write(const char* buf, size_t len)
{
assert(buf || len == 0);
BOOST_ASSERT(buf || len == 0);
if (!buf) return;
if(m_alloc - m_size < len) {
expand_buffer(len);
}
if(buf) {
std::memcpy(m_data + m_size, buf, len);
m_size += len;
}
std::memcpy(m_data + m_size, buf, len);
m_size += len;
}
char* data()

View File

@ -21,10 +21,12 @@
#include <memory>
#if !defined(MSGPACK_USE_CPP03)
#include <atomic>
#endif
#include <boost/assert.hpp>
#if defined(_MSC_VER)
// avoiding confliction std::max, std::min, and macro in windows.h
@ -458,7 +460,7 @@ inline void context::check_ext_size<4>(std::size_t size) {
inline int context::execute(const char* data, std::size_t len, std::size_t& off)
{
assert(len >= off);
BOOST_ASSERT(len >= off);
m_start = data;
m_current = data + off;

View File

@ -15,6 +15,8 @@
#include <stdexcept>
#include <algorithm>
#include <boost/assert.hpp>
#if defined(_MSC_VER)
// avoiding confliction std::max, std::min, and macro in windows.h
#ifndef NOMINMAX
@ -107,6 +109,10 @@ public:
public:
void write(const char* buf, size_t len)
{
BOOST_ASSERT(buf || len == 0);
if (!buf) return;
if(len < m_ref_size) {
append_copy(buf, len);
} else {

View File

@ -15,6 +15,8 @@
#include <stdexcept>
#include <zlib.h>
#include <boost/assert.hpp>
namespace msgpack {
/// @cond
@ -46,6 +48,9 @@ public:
public:
void write(const char* buf, size_t len)
{
BOOST_ASSERT(buf || len == 0);
if (!buf) return;
m_stream.next_in = reinterpret_cast<Bytef*>(const_cast<char*>(buf));
m_stream.avail_in = static_cast<uInt>(len);

View File

@ -10,7 +10,7 @@
#ifndef MSGPACK_V2_CREATE_OBJECT_VISITOR_HPP
#define MSGPACK_V2_CREATE_OBJECT_VISITOR_HPP
#include <cassert>
#include <boost/assert.hpp>
#include "msgpack/unpack_decl.hpp"
#include "msgpack/unpack_exception.hpp"
@ -108,7 +108,7 @@ public:
return true;
}
bool visit_str(const char* v, uint32_t size) {
assert(v || size == 0);
BOOST_ASSERT(v || size == 0);
if (size > m_limit.str()) throw msgpack::str_size_overflow("str size overflow");
msgpack::object* obj = m_stack.back();
obj->type = msgpack::type::STR;
@ -132,6 +132,7 @@ public:
return true;
}
bool visit_bin(const char* v, uint32_t size) {
BOOST_ASSERT(v || size == 0);
if (size > m_limit.bin()) throw msgpack::bin_size_overflow("bin size overflow");
msgpack::object* obj = m_stack.back();
obj->type = msgpack::type::BIN;
@ -155,6 +156,7 @@ public:
return true;
}
bool visit_ext(const char* v, uint32_t size) {
BOOST_ASSERT(v || size == 0);
if (size > m_limit.ext()) throw msgpack::ext_size_overflow("ext size overflow");
msgpack::object* obj = m_stack.back();
obj->type = msgpack::type::EXT;

View File

@ -14,6 +14,8 @@
#include <cstddef>
#include <boost/assert.hpp>
#include "msgpack/unpack_define.hpp"
#include "msgpack/parse_return.hpp"
#include "msgpack/unpack_exception.hpp"
@ -165,10 +167,10 @@ private:
case MSGPACK_CT_MAP_KEY:
return visitor_holder.visitor().start_map_key() ? PARSE_CONTINUE : PARSE_STOP_VISITOR;
case MSGPACK_CT_MAP_VALUE:
assert(0);
BOOST_ASSERT(0);
return PARSE_STOP_VISITOR;
}
assert(0);
BOOST_ASSERT(0);
return PARSE_STOP_VISITOR;
}
parse_return consume(VisitorHolder& visitor_holder) {
@ -234,7 +236,7 @@ inline void check_ext_size<4>(std::size_t size) {
template <typename VisitorHolder>
inline parse_return context<VisitorHolder>::execute(const char* data, std::size_t len, std::size_t& off)
{
assert(len >= off);
BOOST_ASSERT(len >= off);
m_start = data;
m_current = data + off;

View File

@ -14,6 +14,8 @@
#include <cstddef>
#include <boost/assert.hpp>
#include "msgpack/parse_return.hpp"
namespace msgpack {
@ -159,10 +161,10 @@ private:
case MSGPACK_CT_MAP_KEY:
return visitor_holder.visitor().start_map_key() ? PARSE_CONTINUE : PARSE_STOP_VISITOR;
case MSGPACK_CT_MAP_VALUE:
assert(0);
BOOST_ASSERT(0);
return PARSE_STOP_VISITOR;
}
assert(0);
BOOST_ASSERT(0);
return PARSE_STOP_VISITOR;
}
parse_return consume(VisitorHolder& visitor_holder, char const*& current) {
@ -243,7 +245,7 @@ inline void check_ext_size<4>(std::size_t size) {
template <typename VisitorHolder>
inline parse_return context<VisitorHolder>::execute(const char* data, std::size_t len, std::size_t& off)
{
assert(len >= off);
BOOST_ASSERT(len >= off);
m_start = data;
m_current = data + off;