machines-in-motion / shared_memory

realtime interprocess communication
BSD 3-Clause "New" or "Revised" License
5 stars 1 forks source link

Throw error when setting array element of bad size #35

Closed luator closed 1 year ago

luator commented 1 year ago

Description

The array implementation for arbitrary serialisable objects expects the object type to be of fixed size after serialization. This size is determined by creating an object using the default constructor and then serializing it. If later on an object is added that serialises to a different number of bytes (e.g. because it contains dynamically allocated members that differ in size compared to the test-object created by the default constructor), this results in an obscure cereal error later on.

To provide a more understandable error message to the user, check the size of each element when adding it to the array and throw a runtime_error if it does not match the expected size.

Let me know if you think adding fmt just for this is overkill, then I'll remove that part.

How I Tested

I fulfilled the following requirements

luator commented 1 year ago

I would indeed have a preference for not adding dependency (fmt)

Done