From d4ac6fd639a064e46ad8c30e078bbabdb700c178 Mon Sep 17 00:00:00 2001 From: Pavel Kirienko Date: Fri, 10 Jul 2015 19:34:07 +0300 Subject: [PATCH] Array fix - avoiding boolean as array size type --- libuavcan/include/uavcan/marshal/array.hpp | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/libuavcan/include/uavcan/marshal/array.hpp b/libuavcan/include/uavcan/marshal/array.hpp index c80f683252..9a51fb131e 100644 --- a/libuavcan/include/uavcan/marshal/array.hpp +++ b/libuavcan/include/uavcan/marshal/array.hpp @@ -171,12 +171,13 @@ template class UAVCAN_EXPORT StaticArrayBase { protected: - typedef IntegerSpec::Result, SignednessUnsigned, CastModeSaturate> RawSizeType; + typedef IntegerSpec::Result, SignednessUnsigned, CastModeSaturate> RawEncodedSizeType; public: enum { SizeBitLen = 0 }; - typedef typename StorageType::Type SizeType; + typedef typename StorageType::Result>::Result, + SignednessUnsigned, CastModeSaturate> >::Type SizeType; SizeType size() const { return SizeType(Size); } SizeType capacity() const { return SizeType(Size); } @@ -205,9 +206,10 @@ template class UAVCAN_EXPORT DynamicArrayBase { protected: - typedef IntegerSpec::Result, SignednessUnsigned, CastModeSaturate> RawSizeType; + typedef IntegerSpec::Result, SignednessUnsigned, CastModeSaturate> RawEncodedSizeType; public: - typedef typename StorageType::Type SizeType; + typedef typename StorageType::Result>::Result, + SignednessUnsigned, CastModeSaturate> >::Type SizeType; private: SizeType size_; @@ -251,7 +253,7 @@ protected: } public: - enum { SizeBitLen = RawSizeType::BitLen }; + enum { SizeBitLen = RawEncodedSizeType::BitLen }; SizeType size() const { @@ -450,7 +452,9 @@ class UAVCAN_EXPORT Array : public ArrayImpl const bool self_tao_enabled = isOptimizedTailArray(tao_mode); if (!self_tao_enabled) { - const int res_sz = Base::RawSizeType::encode(size(), codec, TailArrayOptDisabled); + const int res_sz = + Base::RawEncodedSizeType::encode(typename StorageType::Type(size()), + codec, TailArrayOptDisabled); if (res_sz <= 0) { return res_sz; @@ -511,8 +515,8 @@ class UAVCAN_EXPORT Array : public ArrayImpl } else { - typename StorageType::Type sz = 0; - const int res_sz = Base::RawSizeType::decode(sz, codec, TailArrayOptDisabled); + typename StorageType::Type sz = 0; + const int res_sz = Base::RawEncodedSizeType::decode(sz, codec, TailArrayOptDisabled); if (res_sz <= 0) { return res_sz;