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 Nov 3, 2020
1 parent 601fd3f commit 4d0d804
Show file tree
Hide file tree
Showing 12 changed files with 66 additions and 68 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
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 @@ -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 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
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
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
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
65 changes: 31 additions & 34 deletions include/fastrtps/utils/fixed_size_bitmap.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,8 @@ using std::uint32_t;
template <class T>
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;
}
Expand All @@ -61,7 +59,7 @@ struct DiffFunction
template<class T, class Diff = DiffFunction<T>, uint32_t NBITS = 256>
class BitmapRange
{
#define NITEMS ((NBITS + 31ul) / 32ul)
#define NITEMS ((NBITS + 31u) / 32u)

public:

Expand Down Expand Up @@ -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
Expand All @@ -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<uint32_t>(__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_;
Expand Down Expand Up @@ -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;
}

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

Expand All @@ -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<uint32_t>(sizeof(uint32_t));
bitmap_.fill(0u);
memcpy(bitmap_.data(), bitmap, num_bytes);
if (0 < num_bits)
{
Expand All @@ -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.
Expand All @@ -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<uint32_t>(__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;
}
}

Expand Down Expand Up @@ -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++)
{
Expand Down Expand Up @@ -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--)
{
Expand Down Expand Up @@ -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<uint32_t>(__builtin_clz(bits)) + 1u;
#endif
num_bits_ = (i << 5u) + offset;
break;
}
}
}

};

} // namespace fastrtps
Expand Down
2 changes: 1 addition & 1 deletion src/cpp/dynamic-types/DynamicTypeBuilderFactory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<uint32_t>(std::stoul(member->get_default_value())));
apv.enumerated_value(static_cast<int32_t>(std::stoul(member->get_default_value())));
}
break;
default:
Expand Down
Loading

0 comments on commit 4d0d804

Please sign in to comment.