diff --git a/include/fastcdr/Cdr.h b/include/fastcdr/Cdr.h index a582e6a2..b2389785 100644 --- a/include/fastcdr/Cdr.h +++ b/include/fastcdr/Cdr.h @@ -720,7 +720,7 @@ class Cdr * @exception exception::NotEnoughMemoryException This exception is thrown when trying to encode into a buffer * position that exceeds the internal memory size. */ - template + template Cdr& serialize( const fixed_string& value) { @@ -1787,7 +1787,7 @@ class Cdr * @exception exception::NotEnoughMemoryException This exception is thrown when trying to decode from a buffer * position that exceeds the internal memory size. */ - template + template Cdr& deserialize( fixed_string& value) { @@ -2973,6 +2973,10 @@ class Cdr const std::array<_T, _Size>* array_t, size_t num_elements) { + if (num_elements == 0 || array_t == nullptr) + { + return *this; + } return serialize_array(array_t->data(), num_elements * array_t->size()); } @@ -2988,6 +2992,10 @@ class Cdr std::array<_T, _Size>* array_t, size_t num_elements) { + if (num_elements == 0 || array_t == nullptr) + { + return *this; + } return deserialize_array(array_t->data(), num_elements * array_t->size()); } @@ -3005,6 +3013,10 @@ class Cdr size_t num_elements, Endianness endianness) { + if (num_elements == 0 || array_t == nullptr) + { + return *this; + } return deserialize_array(array_t->data(), num_elements * array_t->size(), endianness); } diff --git a/include/fastcdr/CdrSizeCalculator.hpp b/include/fastcdr/CdrSizeCalculator.hpp index 9b1caea5..c46d9854 100644 --- a/include/fastcdr/CdrSizeCalculator.hpp +++ b/include/fastcdr/CdrSizeCalculator.hpp @@ -480,7 +480,7 @@ class CdrSizeCalculator * @param[inout] current_alignment Current alignment in the encoding. * @return Encoded size of the instance. */ - template + template size_t calculate_serialized_size( const fixed_string& data, size_t& current_alignment) @@ -1065,7 +1065,11 @@ class CdrSizeCalculator size_t num_elements, size_t& current_alignment) { - return calculate_array_serialized_size(data->data(), num_elements * data->size(), current_alignment); + if (num_elements == 0 || data == nullptr) + { + return 0; + } + return calculate_array_serialized_size(data->data(), num_elements * _N, current_alignment); } /*! diff --git a/include/fastcdr/FastCdr.h b/include/fastcdr/FastCdr.h index 4cce3920..d96f989d 100644 --- a/include/fastcdr/FastCdr.h +++ b/include/fastcdr/FastCdr.h @@ -655,7 +655,8 @@ class Cdr_DllAPI FastCdr return *this; } - throw exception::NotEnoughMemoryException(exception::NotEnoughMemoryException::NOT_ENOUGH_MEMORY_MESSAGE_DEFAULT); + throw exception::NotEnoughMemoryException( + exception::NotEnoughMemoryException::NOT_ENOUGH_MEMORY_MESSAGE_DEFAULT); } /*! @@ -702,7 +703,8 @@ class Cdr_DllAPI FastCdr return *this; } - throw exception::NotEnoughMemoryException(exception::NotEnoughMemoryException::NOT_ENOUGH_MEMORY_MESSAGE_DEFAULT); + throw exception::NotEnoughMemoryException( + exception::NotEnoughMemoryException::NOT_ENOUGH_MEMORY_MESSAGE_DEFAULT); } /*! @@ -736,7 +738,8 @@ class Cdr_DllAPI FastCdr return *this; } - throw exception::NotEnoughMemoryException(exception::NotEnoughMemoryException::NOT_ENOUGH_MEMORY_MESSAGE_DEFAULT); + throw exception::NotEnoughMemoryException( + exception::NotEnoughMemoryException::NOT_ENOUGH_MEMORY_MESSAGE_DEFAULT); } /*! @@ -783,7 +786,8 @@ class Cdr_DllAPI FastCdr return *this; } - throw exception::NotEnoughMemoryException(exception::NotEnoughMemoryException::NOT_ENOUGH_MEMORY_MESSAGE_DEFAULT); + throw exception::NotEnoughMemoryException( + exception::NotEnoughMemoryException::NOT_ENOUGH_MEMORY_MESSAGE_DEFAULT); } /*! @@ -804,7 +808,8 @@ class Cdr_DllAPI FastCdr return *this; } - throw exception::NotEnoughMemoryException(exception::NotEnoughMemoryException::NOT_ENOUGH_MEMORY_MESSAGE_DEFAULT); + throw exception::NotEnoughMemoryException( + exception::NotEnoughMemoryException::NOT_ENOUGH_MEMORY_MESSAGE_DEFAULT); } /*! @@ -825,7 +830,8 @@ class Cdr_DllAPI FastCdr return *this; } - throw exception::NotEnoughMemoryException(exception::NotEnoughMemoryException::NOT_ENOUGH_MEMORY_MESSAGE_DEFAULT); + throw exception::NotEnoughMemoryException( + exception::NotEnoughMemoryException::NOT_ENOUGH_MEMORY_MESSAGE_DEFAULT); } /*! @@ -850,7 +856,8 @@ class Cdr_DllAPI FastCdr return *this; } - throw exception::NotEnoughMemoryException(exception::NotEnoughMemoryException::NOT_ENOUGH_MEMORY_MESSAGE_DEFAULT); + throw exception::NotEnoughMemoryException( + exception::NotEnoughMemoryException::NOT_ENOUGH_MEMORY_MESSAGE_DEFAULT); } /*! @@ -1306,7 +1313,8 @@ class Cdr_DllAPI FastCdr return *this; } - throw exception::NotEnoughMemoryException(exception::NotEnoughMemoryException::NOT_ENOUGH_MEMORY_MESSAGE_DEFAULT); + throw exception::NotEnoughMemoryException( + exception::NotEnoughMemoryException::NOT_ENOUGH_MEMORY_MESSAGE_DEFAULT); } /*! @@ -1353,7 +1361,8 @@ class Cdr_DllAPI FastCdr return *this; } - throw exception::NotEnoughMemoryException(exception::NotEnoughMemoryException::NOT_ENOUGH_MEMORY_MESSAGE_DEFAULT); + throw exception::NotEnoughMemoryException( + exception::NotEnoughMemoryException::NOT_ENOUGH_MEMORY_MESSAGE_DEFAULT); } /*! @@ -1387,7 +1396,8 @@ class Cdr_DllAPI FastCdr return *this; } - throw exception::NotEnoughMemoryException(exception::NotEnoughMemoryException::NOT_ENOUGH_MEMORY_MESSAGE_DEFAULT); + throw exception::NotEnoughMemoryException( + exception::NotEnoughMemoryException::NOT_ENOUGH_MEMORY_MESSAGE_DEFAULT); } /*! @@ -1437,7 +1447,8 @@ class Cdr_DllAPI FastCdr return *this; } - throw exception::NotEnoughMemoryException(exception::NotEnoughMemoryException::NOT_ENOUGH_MEMORY_MESSAGE_DEFAULT); + throw exception::NotEnoughMemoryException( + exception::NotEnoughMemoryException::NOT_ENOUGH_MEMORY_MESSAGE_DEFAULT); } /*! @@ -1458,7 +1469,8 @@ class Cdr_DllAPI FastCdr return *this; } - throw exception::NotEnoughMemoryException(exception::NotEnoughMemoryException::NOT_ENOUGH_MEMORY_MESSAGE_DEFAULT); + throw exception::NotEnoughMemoryException( + exception::NotEnoughMemoryException::NOT_ENOUGH_MEMORY_MESSAGE_DEFAULT); } /*! @@ -1479,7 +1491,8 @@ class Cdr_DllAPI FastCdr return *this; } - throw exception::NotEnoughMemoryException(exception::NotEnoughMemoryException::NOT_ENOUGH_MEMORY_MESSAGE_DEFAULT); + throw exception::NotEnoughMemoryException( + exception::NotEnoughMemoryException::NOT_ENOUGH_MEMORY_MESSAGE_DEFAULT); } /*! @@ -1503,7 +1516,8 @@ class Cdr_DllAPI FastCdr return *this; } - throw exception::NotEnoughMemoryException(exception::NotEnoughMemoryException::NOT_ENOUGH_MEMORY_MESSAGE_DEFAULT); + throw exception::NotEnoughMemoryException( + exception::NotEnoughMemoryException::NOT_ENOUGH_MEMORY_MESSAGE_DEFAULT); } /*! @@ -2047,6 +2061,10 @@ class Cdr_DllAPI FastCdr const std::array<_T, _Size>* array_t, size_t num_elements) { + if (num_elements == 0 || array_t == nullptr) + { + return *this; + } return serialize_array(array_t->data(), num_elements * array_t->size()); } @@ -2062,6 +2080,10 @@ class Cdr_DllAPI FastCdr std::array<_T, _Size>* array_t, size_t num_elements) { + if (num_elements == 0 || array_t == nullptr) + { + return *this; + } return deserialize_array(array_t->data(), num_elements * array_t->size()); }