Skip to content

Commit e74cb35

Browse files
authored
test: guarantee proper lifetime for temporary Rules object: (#4917)
* Commit 01c37fe introduced a change to the STTx unit test where a local "defaultRules" object was created with a temporary inline "presets" value provided to the ctor. Rules::Impl stores a const ref to the presets provided to the ctor. This particular call provided an inline temp variable, which goes out of scope as soon as the object is created. On Windows, attempting to use the presets (e.g. via the enabled() function) causes an access violation, which crashes the test run. * An audit of the code indicates that all other instances of Rules use the Application's config.features list, which will have a sufficient lifetime.
1 parent da68651 commit e74cb35

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

src/test/protocol/STTx_test.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1591,7 +1591,11 @@ class STTx_test : public beast::unit_test::suite
15911591
});
15921592
j.sign(keypair.first, keypair.second);
15931593

1594-
Rules defaultRules{{}};
1594+
// Rules store a reference to the presets. Create a local to guarantee
1595+
// proper lifetime.
1596+
std::unordered_set<uint256, beast::uhash<>> const presets;
1597+
Rules const defaultRules{presets};
1598+
BEAST_EXPECT(!defaultRules.enabled(featureExpandedSignerList));
15951599

15961600
unexpected(
15971601
!j.checkSign(STTx::RequireFullyCanonicalSig::yes, defaultRules),

0 commit comments

Comments
 (0)