Skip to content

Commit 70912ff

Browse files
authored
Merge pull request #898 from redboltz/refine_assert
Replaced assert with BOOST_ASSERT.
2 parents eb1e7e6 + 6598c62 commit 70912ff

File tree

11 files changed

+40
-22
lines changed

11 files changed

+40
-22
lines changed

include/msgpack/unpack_define.hpp

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,6 @@
1111
#define MSGPACK_UNPACK_DEFINE_HPP
1212

1313
#include "msgpack/sysdep.hpp"
14-
#include <stdlib.h>
15-
#include <string.h>
16-
#include <assert.h>
17-
#include <stdio.h>
1814

1915
#ifndef MSGPACK_EMBED_STACK_SIZE
2016
#define MSGPACK_EMBED_STACK_SIZE 32
@@ -77,4 +73,3 @@ typedef enum {
7773

7874

7975
#endif /* msgpack/unpack_define.hpp */
80-

include/msgpack/v1/adaptor/ext.hpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
#include "msgpack/adaptor/check_container_size.hpp"
1515
#include <cstring>
1616
#include <string>
17-
#include <cassert>
1817

1918
namespace msgpack {
2019

include/msgpack/v1/adaptor/ext_decl.hpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
#include "msgpack/adaptor/adaptor_base.hpp"
1515
#include <cstring>
1616
#include <string>
17-
#include <cassert>
1817

1918
namespace msgpack {
2019

include/msgpack/v1/fbuffer.hpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
#include <cstdio>
1616
#include <stdexcept>
1717

18+
#include <boost/assert.hpp>
19+
1820
namespace msgpack {
1921

2022
/// @cond
@@ -28,6 +30,8 @@ class fbuffer {
2830
public:
2931
void write(const char* buf, unsigned int len)
3032
{
33+
BOOST_ASSERT(buf || len == 0);
34+
if (!buf) return;
3135
if (1 != fwrite(buf, len, 1, m_file)) {
3236
throw std::runtime_error("fwrite() failed");
3337
}

include/msgpack/v1/sbuffer.hpp

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@
1414

1515
#include <stdexcept>
1616
#include <cstring>
17-
#include <cassert>
17+
18+
#include <boost/assert.hpp>
1819

1920
namespace msgpack {
2021

@@ -69,14 +70,15 @@ class sbuffer {
6970

7071
void write(const char* buf, size_t len)
7172
{
72-
assert(buf || len == 0);
73+
BOOST_ASSERT(buf || len == 0);
74+
75+
if (!buf) return;
76+
7377
if(m_alloc - m_size < len) {
7478
expand_buffer(len);
7579
}
76-
if(buf) {
77-
std::memcpy(m_data + m_size, buf, len);
78-
m_size += len;
79-
}
80+
std::memcpy(m_data + m_size, buf, len);
81+
m_size += len;
8082
}
8183

8284
char* data()

include/msgpack/v1/unpack.hpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,12 @@
2121

2222
#include <memory>
2323

24+
2425
#if !defined(MSGPACK_USE_CPP03)
2526
#include <atomic>
2627
#endif
2728

29+
#include <boost/assert.hpp>
2830

2931
#if defined(_MSC_VER)
3032
// 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) {
458460

459461
inline int context::execute(const char* data, std::size_t len, std::size_t& off)
460462
{
461-
assert(len >= off);
463+
BOOST_ASSERT(len >= off);
462464

463465
m_start = data;
464466
m_current = data + off;

include/msgpack/v1/vrefbuffer.hpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
#include <stdexcept>
1616
#include <algorithm>
1717

18+
#include <boost/assert.hpp>
19+
1820
#if defined(_MSC_VER)
1921
// avoiding confliction std::max, std::min, and macro in windows.h
2022
#ifndef NOMINMAX
@@ -107,6 +109,10 @@ class vrefbuffer {
107109
public:
108110
void write(const char* buf, size_t len)
109111
{
112+
BOOST_ASSERT(buf || len == 0);
113+
114+
if (!buf) return;
115+
110116
if(len < m_ref_size) {
111117
append_copy(buf, len);
112118
} else {

include/msgpack/v1/zbuffer.hpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
#include <stdexcept>
1616
#include <zlib.h>
1717

18+
#include <boost/assert.hpp>
19+
1820
namespace msgpack {
1921

2022
/// @cond
@@ -46,6 +48,9 @@ class zbuffer {
4648
public:
4749
void write(const char* buf, size_t len)
4850
{
51+
BOOST_ASSERT(buf || len == 0);
52+
if (!buf) return;
53+
4954
m_stream.next_in = reinterpret_cast<Bytef*>(const_cast<char*>(buf));
5055
m_stream.avail_in = static_cast<uInt>(len);
5156

include/msgpack/v2/create_object_visitor.hpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
#ifndef MSGPACK_V2_CREATE_OBJECT_VISITOR_HPP
1111
#define MSGPACK_V2_CREATE_OBJECT_VISITOR_HPP
1212

13-
#include <cassert>
13+
#include <boost/assert.hpp>
1414

1515
#include "msgpack/unpack_decl.hpp"
1616
#include "msgpack/unpack_exception.hpp"
@@ -108,7 +108,7 @@ class create_object_visitor : public msgpack::v2::null_visitor {
108108
return true;
109109
}
110110
bool visit_str(const char* v, uint32_t size) {
111-
assert(v || size == 0);
111+
BOOST_ASSERT(v || size == 0);
112112
if (size > m_limit.str()) throw msgpack::str_size_overflow("str size overflow");
113113
msgpack::object* obj = m_stack.back();
114114
obj->type = msgpack::type::STR;
@@ -132,6 +132,7 @@ class create_object_visitor : public msgpack::v2::null_visitor {
132132
return true;
133133
}
134134
bool visit_bin(const char* v, uint32_t size) {
135+
BOOST_ASSERT(v || size == 0);
135136
if (size > m_limit.bin()) throw msgpack::bin_size_overflow("bin size overflow");
136137
msgpack::object* obj = m_stack.back();
137138
obj->type = msgpack::type::BIN;
@@ -155,6 +156,7 @@ class create_object_visitor : public msgpack::v2::null_visitor {
155156
return true;
156157
}
157158
bool visit_ext(const char* v, uint32_t size) {
159+
BOOST_ASSERT(v || size == 0);
158160
if (size > m_limit.ext()) throw msgpack::ext_size_overflow("ext size overflow");
159161
msgpack::object* obj = m_stack.back();
160162
obj->type = msgpack::type::EXT;

include/msgpack/v2/parse.hpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414

1515
#include <cstddef>
1616

17+
#include <boost/assert.hpp>
18+
1719
#include "msgpack/unpack_define.hpp"
1820
#include "msgpack/parse_return.hpp"
1921
#include "msgpack/unpack_exception.hpp"
@@ -165,10 +167,10 @@ class context {
165167
case MSGPACK_CT_MAP_KEY:
166168
return visitor_holder.visitor().start_map_key() ? PARSE_CONTINUE : PARSE_STOP_VISITOR;
167169
case MSGPACK_CT_MAP_VALUE:
168-
assert(0);
170+
BOOST_ASSERT(0);
169171
return PARSE_STOP_VISITOR;
170172
}
171-
assert(0);
173+
BOOST_ASSERT(0);
172174
return PARSE_STOP_VISITOR;
173175
}
174176
parse_return consume(VisitorHolder& visitor_holder) {
@@ -234,7 +236,7 @@ inline void check_ext_size<4>(std::size_t size) {
234236
template <typename VisitorHolder>
235237
inline parse_return context<VisitorHolder>::execute(const char* data, std::size_t len, std::size_t& off)
236238
{
237-
assert(len >= off);
239+
BOOST_ASSERT(len >= off);
238240

239241
m_start = data;
240242
m_current = data + off;

0 commit comments

Comments
 (0)