Skip to content

Commit

Permalink
fixed warnings (#1357)
Browse files Browse the repository at this point in the history
* fixed warnings

Signed-off-by: ahcorde <[email protected]>

* Added cosmetic suggestions

Signed-off-by: ahcorde <[email protected]>

* Refs 9193. Uncrustify

Signed-off-by: Miguel Company <[email protected]>

* Refs 9193. Fixed additional warnings.

Signed-off-by: Miguel Company <[email protected]>

Co-authored-by: Alejandro Hernández Cordero <[email protected]>
  • Loading branch information
MiguelCompany and ahcorde authored Nov 5, 2020
1 parent fc51f9f commit cdd0bcf
Show file tree
Hide file tree
Showing 12 changed files with 86 additions and 82 deletions.
14 changes: 7 additions & 7 deletions include/fastdds/dds/core/policy/ParameterTypes.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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));
}

};
Expand Down Expand Up @@ -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 +
Expand Down Expand Up @@ -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 +
Expand Down
12 changes: 6 additions & 6 deletions include/fastdds/dds/core/policy/QosPolicies.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -787,7 +787,7 @@ class GenericDataQosPolicy : public Parameter_t, public QosPolicy,
, ResourceLimitedOctetVector()
{
assign(data.begin(), data.end());
length = (size() + 7) & ~3;
length = static_cast<uint16_t>((size() + 7u) & ~3u);
}

virtual RTPS_DllAPI ~GenericDataQosPolicy() = default;
Expand All @@ -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<uint16_t>((size() + 7u) & ~3u);
hasChanged = true;
}
return *this;
Expand Down Expand Up @@ -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<uint16_t>((size() + 7u) & ~3u);
hasChanged = true;
}
}
Expand Down Expand Up @@ -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_);
}

Expand Down Expand Up @@ -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))
Expand Down Expand Up @@ -2659,7 +2659,7 @@ class TransportConfigQos : public QosPolicy
}

//!User defined transports to use alongside or in place of builtins.
std::vector<std::shared_ptr<fastdds::rtps::TransportDescriptorInterface> > user_transports;
std::vector<std::shared_ptr<fastdds::rtps::TransportDescriptorInterface>> user_transports;

//!Set as false to disable the default UDPv4 implementation. <br> By default, true.
bool use_builtin_transports;
Expand Down
4 changes: 2 additions & 2 deletions include/fastdds/rtps/common/CacheChange.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<uint32_t*>(&serializedPayload.data[offset]);
}

Expand All @@ -350,7 +350,7 @@ struct RTPS_DllAPI CacheChange_t
{
bool at_least_one_changed = false;

if ( (fragment_size_ > 0) && (initial_fragment < fragment_count_) )
if ((fragment_size_ > 0) && (initial_fragment < fragment_count_))
{
uint32_t last_fragment = initial_fragment + num_of_fragments;
if (last_fragment > fragment_count_)
Expand Down
3 changes: 2 additions & 1 deletion include/fastdds/rtps/common/SequenceNumber.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<uint32_t>(inc);

if (low < aux_low)
{
Expand Down
20 changes: 9 additions & 11 deletions include/fastdds/rtps/messages/CDRMessage.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down Expand Up @@ -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)
{
Expand Down Expand Up @@ -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)
{
Expand Down Expand Up @@ -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;
}

Expand All @@ -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<char>(msg->buffer[msg->pos + i]);
}
}
msg->pos += str_size;
msg->pos = (msg->pos + 3) & ~3;
msg->pos = (msg->pos + 3u) & ~3u;

return valid;
}
Expand All @@ -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;
}
Expand Down Expand Up @@ -915,7 +913,7 @@ inline bool CDRMessage::addBinaryPropertySeq(
--number_to_serialize;
returnedValue =
CDRMessage::addBinaryProperty(msg, *it,
add_final_padding || (number_to_serialize != 0) );
add_final_padding || (number_to_serialize != 0));
}
}
}
Expand Down Expand Up @@ -955,7 +953,7 @@ inline bool CDRMessage::addBinaryPropertySeq(
--number_to_serialize;
returnedValue =
CDRMessage::addBinaryProperty(msg, *it,
add_final_padding || (number_to_serialize != 0) );
add_final_padding || (number_to_serialize != 0));
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion include/fastrtps/types/AnnotationParameterValue.h
Original file line number Diff line number Diff line change
Expand Up @@ -760,7 +760,7 @@ class AnnotationParameterValue
case TK_ENUM:
{
// TODO Translate from enum value name to integer value
enumerated_value(static_cast<uint32_t>(std::stoul(value)));
enumerated_value(static_cast<int32_t>(std::stoul(value)));
}
break;
default:
Expand Down
13 changes: 9 additions & 4 deletions include/fastrtps/utils/collections/ResourceLimitedVector.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ template <
typename _KeepOrderEnabler = std::false_type,
typename _LimitsConfig = ResourceLimitedContainerConfig,
typename _Alloc = std::allocator<_Ty>,
typename _Collection = std::vector<_Ty, _Alloc> >
typename _Collection = std::vector<_Ty, _Alloc>>
class ResourceLimitedVector
{
public:
Expand Down Expand Up @@ -247,9 +247,11 @@ class ResourceLimitedVector
InputIterator first,
InputIterator last)
{
size_type n = std::distance(first, last);
size_type n = static_cast<size_type>(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);
}

/**
Expand Down Expand Up @@ -459,7 +461,10 @@ class ResourceLimitedVector
*
* @return const reference to the underlying collection.
*/
operator const collection_type& () const noexcept { return collection_; }
operator const collection_type& () const noexcept
{
return collection_;
}

protected:

Expand Down
Loading

0 comments on commit cdd0bcf

Please sign in to comment.