diff --git a/include/fastdds/dds/core/policy/ParameterTypes.hpp b/include/fastdds/dds/core/policy/ParameterTypes.hpp index 8dd05e7fe97..03a5a62ba0b 100644 --- a/include/fastdds/dds/core/policy/ParameterTypes.hpp +++ b/include/fastdds/dds/core/policy/ParameterTypes.hpp @@ -900,9 +900,9 @@ class ParameterProperty_t uint32_t old_size = size(); uint32_t first_size = (uint32_t)new_value.first.size() + 1; - uint32_t first_alignment = ((first_size + 3) & ~3) - first_size; + uint32_t first_alignment = ((first_size + 3u) & ~3u) - first_size; uint32_t second_size = (uint32_t)new_value.second.size() + 1; - uint32_t second_alignment = ((second_size + 3) & ~3) - second_size; + uint32_t second_alignment = ((second_size + 3u) & ~3u) - second_size; uint32_t new_size = first_size + first_alignment + second_size + second_alignment + 8; if (old_size != new_size) @@ -971,7 +971,7 @@ class ParameterProperty_t { //Size of the element (with alignment) uint32_t size = *(uint32_t*)ptr; - return (4 + ((size + 3) & ~3)); + return (4u + ((size + 3u) & ~3u)); } }; @@ -1302,10 +1302,10 @@ class ParameterPropertyList_t : public Parameter_t { //Realloc if needed; uint32_t size1 = (uint32_t) p.first.length() + 1; - uint32_t alignment1 = ((size1 + 3) & ~3) - size1; + uint32_t alignment1 = ((size1 + 3u) & ~3u) - size1; uint32_t size2 = (uint32_t) p.second.length() + 1; - uint32_t alignment2 = ((size2 + 3) & ~3) - size2; + uint32_t alignment2 = ((size2 + 3u) & ~3u) - size2; if (limit_size_ && (properties_.max_size < properties_.length + size1 + alignment1 + 4 + @@ -1338,8 +1338,8 @@ class ParameterPropertyList_t : public Parameter_t uint32_t str2_size) { //Realloc if needed; - uint32_t alignment1 = ((str1_size + 3) & ~3) - str1_size; - uint32_t alignment2 = ((str2_size + 3) & ~3) - str2_size; + uint32_t alignment1 = ((str1_size + 3u) & ~3u) - str1_size; + uint32_t alignment2 = ((str2_size + 3u) & ~3u) - str2_size; if (limit_size_ && (properties_.max_size < properties_.length + str1_size + alignment1 + 4 + diff --git a/include/fastdds/dds/core/policy/QosPolicies.hpp b/include/fastdds/dds/core/policy/QosPolicies.hpp index cd665409169..c38ab48e0be 100644 --- a/include/fastdds/dds/core/policy/QosPolicies.hpp +++ b/include/fastdds/dds/core/policy/QosPolicies.hpp @@ -787,7 +787,7 @@ class GenericDataQosPolicy : public Parameter_t, public QosPolicy, , ResourceLimitedOctetVector() { assign(data.begin(), data.end()); - length = (size() + 7) & ~3; + length = static_cast((size() + 7u) & ~3u); } virtual RTPS_DllAPI ~GenericDataQosPolicy() = default; @@ -811,7 +811,7 @@ class GenericDataQosPolicy : public Parameter_t, public QosPolicy, //If the object is size limited, already has max_size() allocated //assign() will always stop copying when reaching max_size() assign(b.begin(), b.end()); - length = (size() + 7) & ~3; + length = static_cast((size() + 7u) & ~3u); hasChanged = true; } return *this; @@ -917,7 +917,7 @@ class GenericDataQosPolicy : public Parameter_t, public QosPolicy, if (collection_ != vec) { assign(vec.begin(), vec.end()); - length = (size() + 7) & ~3; + length = static_cast((size() + 7u) & ~3u); hasChanged = true; } } @@ -1332,7 +1332,7 @@ class PartitionQosPolicy : public Parameter_t, public QosPolicy { //Size of the element (with alignment) uint32_t size = *(uint32_t*)ptr_; - ptr_ += (4 + ((size + 3) & ~3)); + ptr_ += (4u + ((size + 3u) & ~3u)); value_ = Partition_t(ptr_); } @@ -1484,7 +1484,7 @@ class PartitionQosPolicy : public Parameter_t, public QosPolicy { //Realloc if needed; uint32_t size = (uint32_t)strlen(name) + 1; - uint32_t alignment = ((size + 3) & ~3) - size; + uint32_t alignment = ((size + 3u) & ~3u) - size; if (max_size_ != 0 && (partitions_.max_size < partitions_.length + size + alignment + 4)) diff --git a/include/fastdds/rtps/common/CacheChange.h b/include/fastdds/rtps/common/CacheChange.h index 38763d3ee38..6fcf3a1bf8a 100644 --- a/include/fastdds/rtps/common/CacheChange.h +++ b/include/fastdds/rtps/common/CacheChange.h @@ -331,7 +331,7 @@ struct RTPS_DllAPI CacheChange_t { size_t offset = fragment_size_; offset *= fragment_index; - offset = (offset + 3) & ~3; + offset = (offset + 3u) & ~3u; return reinterpret_cast(&serializedPayload.data[offset]); } diff --git a/include/fastdds/rtps/common/SequenceNumber.h b/include/fastdds/rtps/common/SequenceNumber.h index 7e4cf537a47..1155f4e2fc2 100644 --- a/include/fastdds/rtps/common/SequenceNumber.h +++ b/include/fastdds/rtps/common/SequenceNumber.h @@ -105,8 +105,9 @@ struct RTPS_DllAPI SequenceNumber_t SequenceNumber_t& operator +=( int inc) noexcept { + assert(inc >= 0); uint32_t aux_low = low; - low += inc; + low += static_cast(inc); if (low < aux_low) { diff --git a/include/fastdds/rtps/messages/CDRMessage.hpp b/include/fastdds/rtps/messages/CDRMessage.hpp index 6aedb2936f8..92f9efd6aac 100644 --- a/include/fastdds/rtps/messages/CDRMessage.hpp +++ b/include/fastdds/rtps/messages/CDRMessage.hpp @@ -112,7 +112,7 @@ inline bool CDRMessage::read_array_with_max_size( return false; } valid &= CDRMessage::readData(msg, arr, datasize); - msg->pos = (msg->pos + 3) & ~3; + msg->pos = (msg->pos + 3u) & ~3u; return valid; } @@ -229,7 +229,7 @@ inline SequenceNumberSet_t CDRMessage::readSequenceNumberSet( valid &= CDRMessage::readUInt32(msg, &numBits); valid &= (numBits <= 256u); - uint32_t n_longs = (numBits + 31ul) / 32ul; + uint32_t n_longs = (numBits + 31u) / 32u; uint32_t bitmap[8]; for (uint32_t i = 0; valid && (i < n_longs); ++i) { @@ -257,7 +257,7 @@ inline bool CDRMessage::readFragmentNumberSet( valid &= CDRMessage::readUInt32(msg, &numBits); valid &= (numBits <= 256u); - uint32_t n_longs = (numBits + 31ul) / 32ul; + uint32_t n_longs = (numBits + 31u) / 32u; uint32_t bitmap[8]; for (uint32_t i = 0; valid && (i < n_longs); ++i) { @@ -372,7 +372,7 @@ inline bool CDRMessage::readOctetVector( bool valid = CDRMessage::readUInt32(msg, &vecsize); ocvec->resize(vecsize); valid &= CDRMessage::readData(msg, ocvec->data(), vecsize); - msg->pos = (msg->pos + 3) & ~3; + msg->pos = (msg->pos + 3u) & ~3u; return valid; } @@ -394,11 +394,11 @@ inline bool CDRMessage::readString( stri->resize(str_size - 1); for (uint32_t i = 0; i < str_size - 1; i++) { - stri->at(i) = msg->buffer[msg->pos + i]; + stri->at(i) = static_cast(msg->buffer[msg->pos + i]); } } msg->pos += str_size; - msg->pos = (msg->pos + 3) & ~3; + msg->pos = (msg->pos + 3u) & ~3u; return valid; } @@ -421,9 +421,7 @@ inline bool CDRMessage::readString( *stri = (const char*) &(msg->buffer[msg->pos]); } msg->pos += str_size; - int rest = (str_size) % 4; - rest = rest == 0 ? 0 : 4 - rest; - msg->pos += rest; + msg->pos = (msg->pos + 3u) & ~3u; return valid; } diff --git a/include/fastrtps/types/AnnotationParameterValue.h b/include/fastrtps/types/AnnotationParameterValue.h index eda4e9f01cf..8f752689871 100644 --- a/include/fastrtps/types/AnnotationParameterValue.h +++ b/include/fastrtps/types/AnnotationParameterValue.h @@ -760,7 +760,7 @@ class AnnotationParameterValue case TK_ENUM: { // TODO Translate from enum value name to integer value - enumerated_value(static_cast(std::stoul(value))); + enumerated_value(static_cast(std::stoul(value))); } break; default: diff --git a/include/fastrtps/utils/collections/ResourceLimitedVector.hpp b/include/fastrtps/utils/collections/ResourceLimitedVector.hpp index 12fc4da87e8..2b377988014 100644 --- a/include/fastrtps/utils/collections/ResourceLimitedVector.hpp +++ b/include/fastrtps/utils/collections/ResourceLimitedVector.hpp @@ -247,9 +247,11 @@ class ResourceLimitedVector InputIterator first, InputIterator last) { - size_type n = std::distance(first, last); + size_type n = static_cast(std::distance(first, last)); n = std::min(n, configuration_.maximum); - collection_.assign(first, first + n); + InputIterator value = first; + std::advance(value, n); + collection_.assign(first, value); } /** diff --git a/include/fastrtps/utils/fixed_size_bitmap.hpp b/include/fastrtps/utils/fixed_size_bitmap.hpp index fd9b753e6e7..9111eb65aa9 100644 --- a/include/fastrtps/utils/fixed_size_bitmap.hpp +++ b/include/fastrtps/utils/fixed_size_bitmap.hpp @@ -38,10 +38,8 @@ using std::uint32_t; template struct DiffFunction { - constexpr auto operator () ( - T a, - T b) const - -> decltype(a - b) + constexpr auto operator () (T a, T b) const + -> decltype(a - b) { return a - b; } @@ -61,7 +59,7 @@ struct DiffFunction template, uint32_t NBITS = 256> class BitmapRange { - #define NITEMS ((NBITS + 31ul) / 32ul) + #define NITEMS ((NBITS + 31u) / 32u) public: @@ -184,7 +182,7 @@ class BitmapRange { // Traverse through the significant items on the bitmap T item = base_; - uint32_t n_longs = (num_bits_ + 31UL) / 32UL; + uint32_t n_longs = (num_bits_ + 31u) / 32u; for (uint32_t i = 0; i < n_longs; i++) { // Check if item has at least one bit set @@ -197,17 +195,17 @@ class BitmapRange #if _MSC_VER unsigned long bit; _BitScanReverse(&bit, bits); - uint32_t offset = 31UL ^ bit; + uint32_t offset = 31u ^ bit; #else - uint32_t offset = __builtin_clz(bits); -#endif // if _MSC_VER + uint32_t offset = static_cast(__builtin_clz(bits)); +#endif // Found first bit set in bitmap return item + offset; } // There are 32 items on each bitmap item. - item = item + 32UL; + item = item + 32u; } return base_; @@ -259,8 +257,8 @@ class BitmapRange uint32_t diff = d_func(item, base_); num_bits_ = std::max(diff + 1, num_bits_); uint32_t pos = diff >> 5; - diff &= 31UL; - bitmap_[pos] |= (1UL << (31UL - diff)); + diff &= 31u; + bitmap_[pos] |= (1u << (31u - diff) ); return true; } @@ -300,10 +298,10 @@ class BitmapRange num_bits_ = std::max(num_bits_, offset + n_bits); uint32_t pos = offset >> 5; // Item position - offset &= 31UL; // Bit position inside item + offset &= 31u; // Bit position inside item uint32_t mask = full_mask; // Mask with all bits set mask >>= offset; // Remove first 'offset' bits from mask - uint32_t bits_in_mask = 32UL - offset; // Take note of number of set bits in mask + uint32_t bits_in_mask = 32u - offset; // Take note of number of set bits in mask // This loop enters whenever the whole mask should be added while (n_bits >= bits_in_mask) @@ -339,8 +337,8 @@ class BitmapRange Diff d_func; uint32_t diff = d_func(item, base_); uint32_t pos = diff >> 5; - diff &= 31UL; - bitmap_[pos] &= ~(1UL << (31UL - diff)); + diff &= 31u; + bitmap_[pos] &= ~(1u << (31u - diff)); if (item == max_value) { @@ -363,7 +361,7 @@ class BitmapRange uint32_t& num_longs_used) const noexcept { num_bits = num_bits_; - num_longs_used = (num_bits_ + 31UL) / 32UL; + num_longs_used = (num_bits_ + 31u) / 32u; bitmap = bitmap_; } @@ -379,9 +377,9 @@ class BitmapRange const uint32_t* bitmap) noexcept { num_bits_ = std::min(num_bits, NBITS); - uint32_t num_items = ((num_bits_ + 31UL) / 32UL); - uint32_t num_bytes = num_items * sizeof(uint32_t); - bitmap_.fill(0UL); + uint32_t num_items = ((num_bits_ + 31u) / 32u); + uint32_t num_bytes = num_items * static_cast(sizeof(uint32_t)); + bitmap_.fill(0u); memcpy(bitmap_.data(), bitmap, num_bytes); if (0 < num_bits) { @@ -402,7 +400,7 @@ class BitmapRange T item = base_; // Traverse through the significant items on the bitmap - uint32_t n_longs = (num_bits_ + 31UL) / 32UL; + uint32_t n_longs = (num_bits_ + 31u) / 32u; for (uint32_t i = 0; i < n_longs; i++) { // Traverse through the bits set on the item, msb first. @@ -416,21 +414,21 @@ class BitmapRange #if _MSC_VER unsigned long bit; _BitScanReverse(&bit, bits); - uint32_t offset = 31UL ^ bit; + uint32_t offset = 31u ^ bit; #else - uint32_t offset = __builtin_clz(bits); - uint32_t bit = 31UL ^ offset; -#endif // if _MSC_VER + uint32_t offset = static_cast(__builtin_clz(bits)); + uint32_t bit = 31u ^ offset; +#endif // Call the function for the corresponding item f(item + offset); // Clear the most significant bit - bits &= ~(1UL << bit); + bits &= ~(1u << bit); } // There are 32 items on each bitmap item. - item = item + 32UL; + item = item + 32u; } } @@ -474,7 +472,7 @@ class BitmapRange // bbbbbccc bbbbbbbb cccccccc dddddddd // bbbbbccc cccccddd ddddd000 dddddddd // bbbbbccc cccccddd ddddd000 00000000 - uint32_t overflow_bits = 32UL - n_bits; + uint32_t overflow_bits = 32u - n_bits; size_t last_index = NITEMS - 1u; for (size_t i = 0, n = n_items; n < last_index; i++, n++) { @@ -522,7 +520,7 @@ class BitmapRange // aaaaaaaa bbbbbbbb aaabbbbb bbbccccc // aaaaaaaa 000aaaaa aaabbbbb bbbccccc // 00000000 000aaaaa aaabbbbb bbbccccc - uint32_t overflow_bits = 32UL - n_bits; + uint32_t overflow_bits = 32u - n_bits; size_t last_index = NITEMS - 1u; for (size_t i = last_index, n = last_index - n_items; n > 0; i--, n--) { @@ -557,16 +555,15 @@ class BitmapRange #if _MSC_VER unsigned long bit; _BitScanReverse(&bit, bits); - uint32_t offset = (31UL ^ bit) + 1; + uint32_t offset = (31u ^ bit) + 1; #else - uint32_t offset = __builtin_clz(bits) + 1; -#endif // if _MSC_VER - num_bits_ = (i << 5UL) + offset; + uint32_t offset = static_cast(__builtin_clz(bits)) + 1u; +#endif + num_bits_ = (i << 5u) + offset; break; } } } - }; } // namespace fastrtps diff --git a/src/cpp/dynamic-types/DynamicTypeBuilderFactory.cpp b/src/cpp/dynamic-types/DynamicTypeBuilderFactory.cpp index 233055e2abc..87ac70ae033 100644 --- a/src/cpp/dynamic-types/DynamicTypeBuilderFactory.cpp +++ b/src/cpp/dynamic-types/DynamicTypeBuilderFactory.cpp @@ -2552,7 +2552,7 @@ void DynamicTypeBuilderFactory::set_annotation_default_value( case TK_ENUM: { // TODO Translate from enum value name to integer value - apv.enumerated_value(static_cast(std::stoul(member->get_default_value()))); + apv.enumerated_value(static_cast(std::stoul(member->get_default_value()))); } break; default: diff --git a/src/cpp/fastdds/core/policy/ParameterSerializer.hpp b/src/cpp/fastdds/core/policy/ParameterSerializer.hpp index 33b8898605c..65c032ed941 100644 --- a/src/cpp/fastdds/core/policy/ParameterSerializer.hpp +++ b/src/cpp/fastdds/core/policy/ParameterSerializer.hpp @@ -167,9 +167,9 @@ class ParameterSerializer // Size including NUL char at the end uint32_t str_siz = static_cast(str.size()) + 1; // Align to next 4 byte - str_siz = (str_siz + 3) & ~3; + str_siz = (str_siz + 3u) & ~3u; // p_id + p_length + str_length + str_data - return 2 + 2 + 4 + str_siz; + return 2u + 2u + 4u + str_siz; } static inline uint32_t cdr_serialized_size( @@ -652,7 +652,7 @@ inline bool ParameterSerializer::read_content_from_cdr_ return false; } str1_pos = cdr_message->pos; - alignment1 = ((property1_size + 3) & ~3) - property1_size; + alignment1 = ((property1_size + 3u) & ~3u) - property1_size; cdr_message->pos += (property1_size + alignment1); valid &= fastrtps::rtps::CDRMessage::readUInt32(cdr_message, &property2_size); if (!valid) @@ -663,7 +663,7 @@ inline bool ParameterSerializer::read_content_from_cdr_ &cdr_message->buffer[str1_pos], property1_size, &cdr_message->buffer[cdr_message->pos], property2_size); - alignment2 = ((property2_size + 3) & ~3) - property2_size; + alignment2 = ((property2_size + 3u) & ~3u) - property2_size; cdr_message->pos += (property2_size + alignment2); } //Nproperties_ = num_properties; diff --git a/src/cpp/fastdds/core/policy/QosPoliciesSerializer.hpp b/src/cpp/fastdds/core/policy/QosPoliciesSerializer.hpp index 008b4da3a14..914453420bd 100644 --- a/src/cpp/fastdds/core/policy/QosPoliciesSerializer.hpp +++ b/src/cpp/fastdds/core/policy/QosPoliciesSerializer.hpp @@ -487,7 +487,7 @@ inline bool QosPoliciesSerializer::read_content_from_cdr_mes } qos_policy.push_back ((const char*)&cdr_message->buffer[cdr_message->pos]); - alignment = ((partition_size + 3) & ~3) - partition_size; + alignment = ((partition_size + 3u) & ~3u) - partition_size; cdr_message->pos += (partition_size + alignment); } //qos_policy.Npartitions_ = num_partitions; @@ -1063,7 +1063,7 @@ inline bool QosPoliciesSerializer::read_content_from_cdr_m } // Skip padding - cdr_message->pos += ( (len + 3) & ~3) - len; + cdr_message->pos += ( (len + 3u) & ~3u) - len; // Should have consumed whole size diff --git a/test/mock/dds/QosPolicies/fastdds/dds/core/policy/QosPolicies.hpp b/test/mock/dds/QosPolicies/fastdds/dds/core/policy/QosPolicies.hpp index 7ad67e92ec1..1ab678df2e6 100644 --- a/test/mock/dds/QosPolicies/fastdds/dds/core/policy/QosPolicies.hpp +++ b/test/mock/dds/QosPolicies/fastdds/dds/core/policy/QosPolicies.hpp @@ -522,7 +522,7 @@ class GenericDataQosPolicy : public Parameter_t, public QosPolicy, , ResourceLimitedOctetVector() { assign(data.begin(), data.end()); - length = (size() + 7) & ~3; + length = static_cast((size() + 7u) & ~3u); } virtual RTPS_DllAPI ~GenericDataQosPolicy()