Skip to content

Commit

Permalink
fixed warnings (#1290)
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]>
  • Loading branch information
ahcorde authored and MiguelCompany committed Sep 16, 2020
1 parent 8093300 commit 01f449e
Show file tree
Hide file tree
Showing 12 changed files with 76 additions and 75 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 @@ -1278,10 +1278,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 @@ -1314,8 +1314,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
10 changes: 5 additions & 5 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
2 changes: 1 addition & 1 deletion include/fastdds/rtps/common/CacheChange.h
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,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 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 @@ -93,8 +93,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
16 changes: 7 additions & 9 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
4 changes: 2 additions & 2 deletions include/fastrtps/types/AnnotationParameterValue.h
Original file line number Diff line number Diff line change
Expand Up @@ -636,7 +636,7 @@ class AnnotationParameterValue
case TK_BOOLEAN:
{
std::string val_ = value;
std::transform(val_.begin(), val_.end(), val_.begin(),
std::transform(val_.begin(), val_.end(), val_.begin(),
[](unsigned char c){ return static_cast<char>(std::tolower(c));});
boolean_value(val_.compare("0") != 0 || val_.compare(CONST_TRUE) == 0);
}
Expand Down Expand Up @@ -717,7 +717,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
6 changes: 4 additions & 2 deletions include/fastrtps/utils/collections/ResourceLimitedVector.hpp
Original file line number Diff line number Diff line change
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
Loading

0 comments on commit 01f449e

Please sign in to comment.