Skip to content

Commit f299282

Browse files
committed
fix UB in value::emplace_ functions
With enough optimisations emplace functions accessed an object after its lifetime has ended, due to order of evaluation. The fix is to make the correct order correct.
1 parent 2c9794d commit f299282

1 file changed

Lines changed: 6 additions & 3 deletions

File tree

include/boost/json/impl/value.ipp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -637,21 +637,24 @@ string&
637637
value::
638638
emplace_string() noexcept
639639
{
640-
return *::new(&str_) string(destroy());
640+
storage_ptr sp = destroy();
641+
return *::new(&str_) string(sp);
641642
}
642643

643644
array&
644645
value::
645646
emplace_array() noexcept
646647
{
647-
return *::new(&arr_) array(destroy());
648+
storage_ptr sp = destroy();
649+
return *::new(&arr_) array(sp);
648650
}
649651

650652
object&
651653
value::
652654
emplace_object() noexcept
653655
{
654-
return *::new(&obj_) object(destroy());
656+
storage_ptr sp = destroy();
657+
return *::new(&obj_) object(sp);
655658
}
656659

657660
void

0 commit comments

Comments
 (0)