Skip to content

Commit f1906d8

Browse files
committed
fix latest warnings
1 parent f1979e2 commit f1906d8

File tree

2 files changed

+33
-11
lines changed

2 files changed

+33
-11
lines changed

include/behaviortree_cpp/utils/convert_impl.hpp

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -154,13 +154,21 @@ void convertNumber(const SRC& source, DST& target)
154154
throw std::runtime_error("Value is negative and can't be converted to unsigned");
155155
}
156156
}
157-
// these conversions are always safe: // No check needed
158-
if constexpr(is_same<SRC, DST>() || // same type
159-
(is_same<SRC, float>() && is_same<DST, double>()) || // float -> double
160-
(is_convertible_to_bool<SRC>() && is_same<DST, bool>()))
157+
// these conversions are always safe (no check needed):
158+
// - same type
159+
// - float -> double
160+
// - floating point to bool (C-style: any non-zero is true)
161+
if constexpr(is_same<SRC, DST>() || (is_same<SRC, float>() && is_same<DST, double>()) ||
162+
(std::is_floating_point<SRC>::value && is_same<DST, bool>()))
161163
{
162164
target = static_cast<DST>(source);
163165
}
166+
// integer to bool: only 0 and 1 are valid
167+
else if constexpr(is_integer<SRC>() && is_same<DST, bool>())
168+
{
169+
checkLowerLimit<SRC, DST>(source);
170+
target = static_cast<DST>(source);
171+
}
164172
else if constexpr(both_integers)
165173
{
166174
if constexpr(sizeof(SRC) == sizeof(DST) && !is_signed<SRC>() && is_signed<DST>())

include/behaviortree_cpp/utils/simple_string.hpp

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,11 @@ class SimpleString
5050

5151
SimpleString& operator=(SimpleString&& other) noexcept
5252
{
53-
this->~SimpleString();
54-
55-
std::swap(_storage, other._storage);
53+
if(this != &other)
54+
{
55+
this->~SimpleString();
56+
std::swap(_storage, other._storage);
57+
}
5658
return *this;
5759
}
5860

@@ -120,22 +122,34 @@ class SimpleString
120122

121123
bool operator<=(const SimpleString& other) const
122124
{
123-
return std::strcmp(data(), other.data()) <= 0;
125+
return !(*this > other);
124126
}
125127

126128
bool operator>=(const SimpleString& other) const
127129
{
128-
return std::strcmp(data(), other.data()) >= 0;
130+
return !(*this < other);
129131
}
130132

131133
bool operator<(const SimpleString& other) const
132134
{
133-
return std::strcmp(data(), other.data()) < 0;
135+
const size_t min_size = std::min(size(), other.size());
136+
int cmp = std::memcmp(data(), other.data(), min_size);
137+
if(cmp != 0)
138+
{
139+
return cmp < 0;
140+
}
141+
return size() < other.size();
134142
}
135143

136144
bool operator>(const SimpleString& other) const
137145
{
138-
return std::strcmp(data(), other.data()) > 0;
146+
const size_t min_size = std::min(size(), other.size());
147+
int cmp = std::memcmp(data(), other.data(), min_size);
148+
if(cmp != 0)
149+
{
150+
return cmp > 0;
151+
}
152+
return size() > other.size();
139153
}
140154

141155
bool isSOO() const

0 commit comments

Comments
 (0)