mirror of
https://github.com/monero-project/monero.git
synced 2025-08-02 08:56:06 -04:00
serialization: protect blob serialization from undefined behavior
There is currently no compiler protection when someone tries to do (for example) `BLOB_SERIALIZER(std::vector<int>)`. You just get runtime allocation errors. This has already eaten up dev time before, so this PR adds a static assertion that the type must be trivially copyable, as defined by the C++ standard. Types can override this if applicable if they use `BLOB_SERIALIZER_FORCED`.
This commit is contained in:
parent
059028a30a
commit
9d101d5ea0
4 changed files with 31 additions and 4 deletions
|
@ -51,6 +51,11 @@
|
|||
using namespace std;
|
||||
using namespace crypto;
|
||||
|
||||
static_assert(!std::is_trivially_copyable<std::vector<unsigned char>>(),
|
||||
"should fail to compile when applying blob serializer");
|
||||
static_assert(!std::is_trivially_copyable<std::string>(),
|
||||
"should fail to compile when applying blob serializer");
|
||||
|
||||
struct Struct
|
||||
{
|
||||
int32_t a;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue