Merge branch 'hotfix/#1019-UB-when-passing-a-temporary-lambda-to-a-delegate' into development

This commit is contained in:
John Wellbelove 2025-02-01 17:55:30 +00:00
commit 548c2be4c3
15 changed files with 58 additions and 20 deletions

View File

@ -148,6 +148,12 @@ namespace etl
assign((void*)(&instance), const_lambda_stub<TLambda>);
}
//*************************************************************************
// Delete construction from rvalue reference lambda or functor.
//*************************************************************************
template <typename TLambda, typename = etl::enable_if_t<etl::is_class<TLambda>::value && !etl::is_same<etl::delegate<TReturn(TParams...)>, TLambda>::value, void>>
ETL_CONSTEXPR14 delegate(TLambda&& instance) = delete;
//*************************************************************************
/// Create from function (Compile time).
//*************************************************************************

View File

@ -64,7 +64,7 @@ namespace
std::vector<unsigned char> decoded_output;
bool received_final_block = false;
codec::callback_type callback = [](const codec::span_type& sp)
auto lambda = [](const codec::span_type& sp)
{
if (sp.empty())
{
@ -76,6 +76,8 @@ namespace
}
};
codec::callback_type callback = lambda;
std::array<unsigned char, 256> input_data =
{
0x3B, 0x27, 0x03, 0x43, 0x2D, 0xFB, 0x28, 0x2A, 0x61, 0xAE, 0xBC, 0x49, 0x71, 0x32, 0x01, 0x15,

View File

@ -62,7 +62,7 @@ namespace
std::string encoded_output;
bool received_final_block = false;
codec::callback_type callback = [](const codec::span_type& sp)
auto lambda = [](const codec::span_type& sp)
{
if (sp.empty())
{
@ -74,6 +74,8 @@ namespace
}
};
codec::callback_type callback = lambda;
std::array<unsigned char, 256> input_data =
{
0x3B, 0x27, 0x03, 0x43, 0x2D, 0xFB, 0x28, 0x2A, 0x61, 0xAE, 0xBC, 0x49, 0x71, 0x32, 0x01, 0x15,

View File

@ -61,7 +61,7 @@ namespace
std::vector<unsigned char> decoded_output;
bool received_final_block = false;
codec::callback_type callback = [](const codec::span_type& sp)
auto lambda = [](const codec::span_type& sp)
{
if (sp.empty())
{
@ -73,6 +73,8 @@ namespace
}
};
codec::callback_type callback = lambda;
std::array<unsigned char, 256> input_data =
{
0x3B, 0x27, 0x03, 0x43, 0x2D, 0xFB, 0x28, 0x2A, 0x61, 0xAE, 0xBC, 0x49, 0x71, 0x32, 0x01, 0x15,

View File

@ -62,7 +62,7 @@ namespace
std::string encoded_output;
bool received_final_block = false;
codec::callback_type callback = [](const codec::span_type& sp)
auto lambda = [](const codec::span_type& sp)
{
if (sp.empty())
{
@ -74,6 +74,8 @@ namespace
}
};
codec::callback_type callback = lambda;
std::array<unsigned char, 256> input_data =
{
0x3B, 0x27, 0x03, 0x43, 0x2D, 0xFB, 0x28, 0x2A, 0x61, 0xAE, 0xBC, 0x49, 0x71, 0x32, 0x01, 0x15,

View File

@ -61,7 +61,7 @@ namespace
std::vector<unsigned char> decoded_output;
bool received_final_block = false;
codec::callback_type callback = [](const codec::span_type& sp)
auto lambda = [](const codec::span_type& sp)
{
if (sp.empty())
{
@ -73,6 +73,8 @@ namespace
}
};
codec::callback_type callback = lambda;
std::array<unsigned char, 256> input_data =
{
0x3B, 0x27, 0x03, 0x43, 0x2D, 0xFB, 0x28, 0x2A, 0x61, 0xAE, 0xBC, 0x49, 0x71, 0x32, 0x01, 0x15,

View File

@ -61,7 +61,7 @@ namespace
std::vector<unsigned char> decoded_output;
bool received_final_block = false;
codec::callback_type callback = [](const codec::span_type& sp)
auto lambda = [](const codec::span_type& sp)
{
if (sp.empty())
{
@ -73,6 +73,8 @@ namespace
}
};
codec::callback_type callback = lambda;
std::array<unsigned char, 256> input_data =
{
0x3B, 0x27, 0x03, 0x43, 0x2D, 0xFB, 0x28, 0x2A, 0x61, 0xAE, 0xBC, 0x49, 0x71, 0x32, 0x01, 0x15,

View File

@ -62,7 +62,7 @@ namespace
std::string encoded_output;
bool received_final_block = false;
codec::callback_type callback = [](const codec::span_type& sp)
auto lambda = [](const codec::span_type& sp)
{
if (sp.empty())
{
@ -74,6 +74,8 @@ namespace
}
};
codec::callback_type callback = lambda;
std::array<unsigned char, 256> input_data =
{
0x3B, 0x27, 0x03, 0x43, 0x2D, 0xFB, 0x28, 0x2A, 0x61, 0xAE, 0xBC, 0x49, 0x71, 0x32, 0x01, 0x15,

View File

@ -62,7 +62,7 @@ namespace
std::string encoded_output;
bool received_final_block = false;
codec::callback_type callback = [](const codec::span_type& sp)
auto lambda = [](const codec::span_type& sp)
{
if (sp.empty())
{
@ -74,6 +74,8 @@ namespace
}
};
codec::callback_type callback = lambda;
std::array<unsigned char, 256> input_data =
{
0x3B, 0x27, 0x03, 0x43, 0x2D, 0xFB, 0x28, 0x2A, 0x61, 0xAE, 0xBC, 0x49, 0x71, 0x32, 0x01, 0x15,

View File

@ -61,7 +61,7 @@ namespace
std::vector<unsigned char> decoded_output;
bool received_final_block = false;
codec::callback_type callback = [](const codec::span_type& sp)
auto lambda = [](const codec::span_type& sp)
{
if (sp.empty())
{
@ -73,6 +73,8 @@ namespace
}
};
codec::callback_type callback = lambda;
std::array<unsigned char, 256> input_data =
{
0x3B, 0x27, 0x03, 0x43, 0x2D, 0xFB, 0x28, 0x2A, 0x61, 0xAE, 0xBC, 0x49, 0x71, 0x32, 0x01, 0x15,

View File

@ -61,7 +61,7 @@ namespace
std::vector<unsigned char> decoded_output;
bool received_final_block = false;
codec::callback_type callback = [](const codec::span_type& sp)
auto lambda = [](const codec::span_type& sp)
{
if (sp.empty())
{
@ -73,6 +73,8 @@ namespace
}
};
codec::callback_type callback = lambda;
std::array<unsigned char, 256> input_data =
{
0x3B, 0x27, 0x03, 0x43, 0x2D, 0xFB, 0x28, 0x2A, 0x61, 0xAE, 0xBC, 0x49, 0x71, 0x32, 0x01, 0x15,

View File

@ -62,7 +62,7 @@ namespace
std::string encoded_output;
bool received_final_block = false;
codec::callback_type callback = [](const codec::span_type& sp)
auto lambda = [](const codec::span_type& sp)
{
if (sp.empty())
{
@ -74,6 +74,8 @@ namespace
}
};
codec::callback_type callback = lambda;
std::array<unsigned char, 256> input_data =
{
0x3B, 0x27, 0x03, 0x43, 0x2D, 0xFB, 0x28, 0x2A, 0x61, 0xAE, 0xBC, 0x49, 0x71, 0x32, 0x01, 0x15,

View File

@ -61,8 +61,8 @@ namespace
std::string encoded_output;
bool received_final_block = false;
codec::callback_type callback = [](const codec::span_type& sp)
auto lambda = [](const codec::span_type& sp)
{
if (sp.empty())
{
@ -74,6 +74,8 @@ namespace
}
};
codec::callback_type callback = lambda;
std::array<unsigned char, 256> input_data =
{
0x3B, 0x27, 0x03, 0x43, 0x2D, 0xFB, 0x28, 0x2A, 0x61, 0xAE, 0xBC, 0x49, 0x71, 0x32, 0x01, 0x15,

View File

@ -1318,10 +1318,12 @@ namespace
static std::vector<char> result;
etl::byte_stream_writer::callback_type callback([&](etl::byte_stream_writer::callback_parameter_type sp)
{
std::copy(sp.begin(), sp.end(), std::back_inserter(result));
});
auto lambda = [&](etl::byte_stream_writer::callback_parameter_type sp)
{
std::copy(sp.begin(), sp.end(), std::back_inserter(result));
};
etl::byte_stream_writer::callback_type callback(lambda);
etl::byte_stream_writer writer(storage.data(), storage.size(), etl::endian::big, callback);

View File

@ -310,7 +310,9 @@ namespace
//*************************************************************************
TEST_FIXTURE(SetupFixture, test_is_valid_true)
{
etl::delegate<void(void)> d([] {});
auto lambda = [] {};
etl::delegate<void(void)> d(lambda);
CHECK(d.is_valid());
CHECK(d);
@ -320,7 +322,9 @@ namespace
//*************************************************************************
TEST_FIXTURE(SetupFixture, test_is_valid_after_clear)
{
etl::delegate<void(void)> d([] {});
auto lambda = [] {};
etl::delegate<void(void)> d(lambda);
CHECK_TRUE(d.is_valid());
d.clear();
@ -550,7 +554,9 @@ namespace
//*************************************************************************
TEST_FIXTURE(SetupFixture, test_lambda_int)
{
etl::delegate<void(int, int)> d([](int i, int j) { function_called = FunctionCalled::Lambda_Called; parameter_correct = (i == VALUE1) && (j == VALUE2); });
auto lambda = [](int i, int j) { function_called = FunctionCalled::Lambda_Called; parameter_correct = (i == VALUE1) && (j == VALUE2); };
etl::delegate<void(int, int)> d(lambda);
d(VALUE1, VALUE2);