Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion .drone.star
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,6 @@ def main(ctx):
'LCOV_BRANCH_COVERAGE': '0',
'B2_CXXSTD': '23',
'B2_VARIANT': 'debug',
'B2_DEFINES': 'BOOST_JSON_EXPENSIVE_TESTS',
'CODECOV_TOKEN': {'from_secret': 'codecov_token'},
},
},
Expand All @@ -122,9 +121,15 @@ def main(ctx):
},
{ 'match': {'compiler': 'clang =latest', 'os': 'linux'},
'special': 'valgrind',
'environment': {
'B2_DEFINES': 'BOOST_JSON_NO_LONG_TESTS',
},
},
{ 'match': {'compiler': 'gcc =latest', 'os': 'linux'},
'special': 'valgrind',
'environment': {
'B2_DEFINES': 'BOOST_JSON_NO_LONG_TESTS',
},
},
],
) + [
Expand Down
18 changes: 9 additions & 9 deletions include/boost/json/basic_parser_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -434,7 +434,7 @@ parse_comment(const char* p,
st_.pop(st);
switch(st)
{
default: BOOST_JSON_UNREACHABLE();
default: BOOST_JSON_UNREACHABLE(); // LCOV_EXCL_LINE
case state::com1: goto do_com1;
case state::com2: goto do_com2;
case state::com3: goto do_com3;
Expand Down Expand Up @@ -723,7 +723,7 @@ resume_value(const char* p,
st_.peek(st);
switch(st)
{
default: BOOST_JSON_UNREACHABLE();
default: BOOST_JSON_UNREACHABLE(); // LCOV_EXCL_LINE
case state::lit1:
return parse_literal(p, detail::literals_c<detail::literals::resume>() );

Expand Down Expand Up @@ -859,7 +859,7 @@ parse_literal(const char* p, Literal)
}
else
{
BOOST_JSON_UNREACHABLE();
BOOST_JSON_UNREACHABLE(); // LCOV_EXCL_LINE
}

cs += sz;
Expand Down Expand Up @@ -947,7 +947,7 @@ parse_literal(const char* p, Literal)
ec_)))
return fail(cs.begin());
break;
default: BOOST_JSON_UNREACHABLE();
default: BOOST_JSON_UNREACHABLE(); // LCOV_EXCL_LINE
}

cs += size;
Expand Down Expand Up @@ -977,7 +977,7 @@ parse_string(const char* p,
st_.pop(total);
switch(st)
{
default: BOOST_JSON_UNREACHABLE();
default: BOOST_JSON_UNREACHABLE(); // LCOV_EXCL_LINE
case state::str2: goto do_str2;
case state::str8: goto do_str8;
case state::str1: break;
Expand Down Expand Up @@ -1191,7 +1191,7 @@ parse_escaped(
st_.pop(st);
switch(st)
{
default: BOOST_JSON_UNREACHABLE();
default: BOOST_JSON_UNREACHABLE(); // LCOV_EXCL_LINE
case state::str3: goto do_str3;
case state::str4: goto do_str4;
case state::str5: goto do_str5;
Expand Down Expand Up @@ -1739,7 +1739,7 @@ parse_object(const char* p,
st_.pop(size);
switch(st)
{
default: BOOST_JSON_UNREACHABLE();
default: BOOST_JSON_UNREACHABLE(); // LCOV_EXCL_LINE
case state::obj1: goto do_obj1;
case state::obj2: goto do_obj2;
case state::obj3: goto do_obj3;
Expand Down Expand Up @@ -1908,7 +1908,7 @@ parse_array(const char* p,
st_.pop(size);
switch(st)
{
default: BOOST_JSON_UNREACHABLE();
default: BOOST_JSON_UNREACHABLE(); // LCOV_EXCL_LINE
case state::arr1: goto do_arr1;
case state::arr2: goto do_arr2;
case state::arr3: goto do_arr3;
Expand Down Expand Up @@ -2158,7 +2158,7 @@ parse_number(const char* p,
st_.pop(st);
switch(st)
{
default: BOOST_JSON_UNREACHABLE();
default: BOOST_JSON_UNREACHABLE(); // LCOV_EXCL_LINE
case state::num1: goto do_num1;
case state::num2: goto do_num2;
case state::num3: goto do_num3;
Expand Down
4 changes: 1 addition & 3 deletions include/boost/json/impl/serialize.ipp
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,7 @@ serialize_impl(
s.max_size() / 2;
for(;;)
{
sv = sr.read(
&s[0] + len,
s.size() - len);
sv = sr.read(&s[0] + len, s.size() - len);
len += sv.size();
if(sr.done())
break;
Expand Down
4 changes: 2 additions & 2 deletions include/boost/json/impl/serializer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ BOOST_FORCEINLINE
bool
write_impl(bool_conversion_tag, writer& w, stream& ss)
{
BOOST_ASSERT( w.p_ );
BOOST_ASSERT( w.p_ ); // LCOV_EXCL_LINE
auto const t = *reinterpret_cast<T const*>(w.p_);

#if defined(_MSC_VER)
Expand Down Expand Up @@ -193,7 +193,7 @@ write_impl(string_like_conversion_tag, writer& w, stream& ss0)
# pragma warning( pop )
#endif
{
string_view const sv = *reinterpret_cast<T const*>(w.p_);
string_view const sv = *reinterpret_cast<T const*>(w.p_); // LCOV_EXCL_LINE
w.cs0_ = { sv.data(), sv.size() };
return write_string(w, ss0);
}
Expand Down
27 changes: 8 additions & 19 deletions include/boost/json/impl/value.ipp
Original file line number Diff line number Diff line change
Expand Up @@ -225,30 +225,19 @@ value(
//
//----------------------------------------------------------

value::
value(
std::initializer_list<value_ref> init,
storage_ptr sp)
value::value(std::initializer_list<value_ref> init, storage_ptr sp)
{
if(value_ref::maybe_object(init))
if( value_ref::maybe_object(init) )
{
::new(&obj_) object(
value_ref::make_object(
init, std::move(sp)));
::new(&obj_) object( value_ref::make_object(init, std::move(sp)) );
}
else if( init.size() == 1 )
{
::new(this) value( init.begin()->make_value(std::move(sp)) );
}
else
{
if( init.size() == 1 )
{
::new(this) value(
init.begin()->make_value( std::move(sp) ));
}
else
{
::new(&arr_) array(
value_ref::make_array(
init, std::move(sp)));
}
::new(&arr_) array( value_ref::make_array(init, std::move(sp)) );
}
}

Expand Down
16 changes: 2 additions & 14 deletions include/boost/json/impl/value_ref.ipp
Original file line number Diff line number Diff line change
Expand Up @@ -24,18 +24,6 @@ value() const
return make_value({});
}

value
value_ref::
from_init_list(
void const* p,
storage_ptr sp)
{
return make_value(
*reinterpret_cast<
init_list const*>(p),
std::move(sp));
}

bool
value_ref::
is_key_value_pair() const noexcept
Expand Down Expand Up @@ -97,11 +85,11 @@ make_value(
case what::func:
return f_.f(f_.p,
std::move(sp));

case what::strfunc:
return f_.f(f_.p,
std::move(sp));

case what::cfunc:
return cf_.f(cf_.p,
std::move(sp));
Expand Down
7 changes: 0 additions & 7 deletions include/boost/json/value_ref.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -431,13 +431,6 @@ class value_ref
void* p,
storage_ptr sp);

static
BOOST_JSON_DECL
value
from_init_list(
void const* p,
storage_ptr sp);

inline
bool
is_key_value_pair() const noexcept;
Expand Down
59 changes: 58 additions & 1 deletion test/basic_parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -659,8 +659,8 @@ class basic_parser_test
good("1000000000000000000000000.000000000001");
good("1000000000000000000000000.0e1 ");
good("1000000000000000000000000.0 ");

good("1000000000.1000000000 ");
good("100000000000000000000e+2147483647");

bad("");
bad("- ");
Expand Down Expand Up @@ -1453,6 +1453,7 @@ class basic_parser_test
bad("\"\xf1\x7f\xbf\xbf----------\"");
bad("\"\xf2\x80\x7f\xbf----------\"");
bad("\"\xf3\x80\xbf\xce----------\"");
bad("\"\xf3\x80\xbf");

// utf8 after escape
good("\"\\u0000 \xf3\xbf\x80\xbf\xf3\xbf\x80\xbf\"");
Expand Down Expand Up @@ -1821,6 +1822,60 @@ class basic_parser_test
#pragma warning(pop)
#endif

struct null_handler
{
constexpr static std::size_t max_object_size = std::size_t(-1);
constexpr static std::size_t max_array_size = std::size_t(-1);
constexpr static std::size_t max_key_size = std::size_t(-1);
constexpr static std::size_t max_string_size = std::size_t(-1);

bool on_document_begin( system::error_code& ) { return true; }
bool on_document_end( system::error_code& ) { return true; }
bool on_object_begin( system::error_code& ) { return true; }
bool on_object_end( std::size_t, system::error_code& ) { return true; }
bool on_array_begin( system::error_code& ) { return true; }
bool on_array_end( std::size_t, system::error_code& ) { return true; }
bool on_key_part( string_view, std::size_t, system::error_code& ) { return true; }
bool on_key( string_view, std::size_t, system::error_code& ) { return true; }
bool on_string_part( string_view, std::size_t, system::error_code& ) { return true; }
bool on_string( string_view, std::size_t, system::error_code& ) { return true; }
bool on_number_part( string_view, system::error_code&) { return true; }
bool on_int64( std::int64_t, string_view, system::error_code& ) { return true; }
bool on_uint64( std::uint64_t, string_view, system::error_code& ) { return true; }
bool on_double( double, string_view, system::error_code& ) { return true; }
bool on_bool( bool, system::error_code& ) { return true; }
bool on_null( system::error_code& ) { return true; }
bool on_comment_part( string_view, system::error_code& ) { return true; }
bool on_comment( string_view, system::error_code& ) { return true; }
};

void
testManualFail()
{
basic_parser<null_handler> p({});
p.fail( system::error_code() );
BOOST_TEST( !p.done() );
BOOST_TEST( p.last_error() == error::incomplete );
BOOST_TEST( p.last_error().has_location() );

p.reset();

system::error_code ec;
p.write_some(false, "null", 4, ec);
BOOST_TEST( p.done() );
p.fail( make_error_code(error::array_too_large) );
BOOST_TEST( !p.done() );
BOOST_TEST( p.last_error() == error::array_too_large );
}

void
testWhitespace()
{
parse_options opts;
opts.allow_comments = true;
bad("//\n ", opts);
}

void
run()
{
Expand All @@ -1845,6 +1900,8 @@ class basic_parser_test
testNumberLiteral();
testStickyErrors();
testStdTypes();
testManualFail();
testWhitespace();
}
};

Expand Down
59 changes: 49 additions & 10 deletions test/limits.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -192,19 +192,12 @@ class limits_test
(s.insert(0, s.subview(0, 10))) );
}

#if 0
{
// VFALCO tsan doesn't like this
// capacity overflow
string s;
try
{
s.resize(s.max_size() - 1);
}
catch(std::exception const&)
{
}
s.reserve(s.max_size() - 1);
s.reserve(s.max_size());
}
#endif
}

// string in parser
Expand All @@ -220,6 +213,52 @@ class limits_test
BOOST_TEST(ec.has_location());
}

// string in parser, fails at the beginning of the 2nd escape sequence
{
stream_parser p;
system::error_code ec;
p.write_some("\"", 1, ec);
BOOST_TEST( !ec.failed() );
for(std::size_t i = 0; i < string::max_size(); ++i)
{
p.write_some("0", 1, ec);
}
p.write_some("\\n\\", 3, ec);
BOOST_TEST(ec == error::string_too_large);
BOOST_TEST(ec.has_location());
}

// string in parser, fails at the beginning of the 2nd
// (unicode) escape sequence
{
stream_parser p;
system::error_code ec;
p.write_some("\"", 1, ec);
BOOST_TEST( !ec.failed() );
for(std::size_t i = 0; i < string::max_size(); ++i)
{
p.write_some("0", 1, ec);
}
p.write_some("\\n\\u", 4, ec);
BOOST_TEST(ec == error::string_too_large);
BOOST_TEST(ec.has_location());
}

// string in parser, fails after the last escape
{
stream_parser p;
system::error_code ec;
p.write_some("\"", 1, ec);
BOOST_TEST( !ec.failed() );
for(std::size_t i = 0; i < string::max_size(); ++i)
{
p.write_some("0", 1, ec);
}
p.write_some("\\n0", 3, ec);
BOOST_TEST(ec == error::string_too_large);
BOOST_TEST(ec.has_location());
}

// key in parser
{
stream_parser p;
Expand Down
8 changes: 8 additions & 0 deletions test/monotonic_resource.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,14 @@ class monotonic_resource_test
(void)mr.allocate(10,1);
}

// equality comparison
{
monotonic_resource mr1;
monotonic_resource mr2;
BOOST_TEST(mr1 != mr2);
BOOST_TEST(mr1 == mr1);
}

// coverage
{
monotonic_resource mr(std::size_t(-1)-2);
Expand Down
Loading
Loading