Skip to content

Commit 19f9183

Browse files
committed
fiw last warnings
1 parent ad74f34 commit 19f9183

3 files changed

Lines changed: 55 additions & 41 deletions

File tree

‎src/basic_types.cpp‎

Lines changed: 51 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#include <cstring>
77
#include <clocale>
88
#include <charconv>
9+
#include <tuple>
910

1011
namespace BT
1112
{
@@ -46,31 +47,28 @@ std::string toStr(NodeStatus status, bool colored)
4647
{
4748
return toStr(status);
4849
}
49-
else
50+
switch(status)
5051
{
51-
switch(status)
52-
{
53-
case NodeStatus::SUCCESS:
54-
return "\x1b[32m"
55-
"SUCCESS"
56-
"\x1b[0m"; // RED
57-
case NodeStatus::FAILURE:
58-
return "\x1b[31m"
59-
"FAILURE"
60-
"\x1b[0m"; // GREEN
61-
case NodeStatus::RUNNING:
62-
return "\x1b[33m"
63-
"RUNNING"
64-
"\x1b[0m"; // YELLOW
65-
case NodeStatus::SKIPPED:
66-
return "\x1b[34m"
67-
"SKIPPED"
68-
"\x1b[0m"; // BLUE
69-
case NodeStatus::IDLE:
70-
return "\x1b[36m"
71-
"IDLE"
72-
"\x1b[0m"; // CYAN
73-
}
52+
case NodeStatus::SUCCESS:
53+
return "\x1b[32m"
54+
"SUCCESS"
55+
"\x1b[0m"; // RED
56+
case NodeStatus::FAILURE:
57+
return "\x1b[31m"
58+
"FAILURE"
59+
"\x1b[0m"; // GREEN
60+
case NodeStatus::RUNNING:
61+
return "\x1b[33m"
62+
"RUNNING"
63+
"\x1b[0m"; // YELLOW
64+
case NodeStatus::SKIPPED:
65+
return "\x1b[34m"
66+
"SKIPPED"
67+
"\x1b[0m"; // BLUE
68+
case NodeStatus::IDLE:
69+
return "\x1b[36m"
70+
"IDLE"
71+
"\x1b[0m"; // CYAN
7472
}
7573
return "Undefined";
7674
}
@@ -120,7 +118,8 @@ template <>
120118
int64_t convertFromString<int64_t>(StringView str)
121119
{
122120
long result = 0;
123-
auto [ptr, ec] = std::from_chars(str.data(), str.data() + str.size(), result);
121+
const auto [ptr, ec] = std::from_chars(str.data(), str.data() + str.size(), result);
122+
std::ignore = ptr;
124123
if(ec != std::errc())
125124
{
126125
throw RuntimeError(StrCat("Can't convert string [", str, "] to integer"));
@@ -132,7 +131,8 @@ template <>
132131
uint64_t convertFromString<uint64_t>(StringView str)
133132
{
134133
unsigned long result = 0;
135-
auto [ptr, ec] = std::from_chars(str.data(), str.data() + str.size(), result);
134+
const auto [ptr, ec] = std::from_chars(str.data(), str.data() + str.size(), result);
135+
std::ignore = ptr;
136136
if(ec != std::errc())
137137
{
138138
throw RuntimeError(StrCat("Can't convert string [", str, "] to integer"));
@@ -194,21 +194,23 @@ double convertFromString<double>(StringView str)
194194
// see issue #120
195195
// http://quick-bench.com/DWaXRWnxtxvwIMvZy2DxVPEKJnE
196196

197-
std::string old_locale = setlocale(LC_NUMERIC, nullptr);
198-
setlocale(LC_NUMERIC, "C");
199-
double val = std::stod(str.data());
200-
setlocale(LC_NUMERIC, old_locale.c_str());
197+
const std::string old_locale = setlocale(LC_NUMERIC, nullptr);
198+
std::ignore = setlocale(LC_NUMERIC, "C");
199+
const std::string str_copy(str.data(), str.size());
200+
const double val = std::stod(str_copy);
201+
std::ignore = setlocale(LC_NUMERIC, old_locale.c_str());
201202
return val;
202203
}
203204

204205
template <>
205206
float convertFromString<float>(StringView str)
206207
{
207-
std::string old_locale = setlocale(LC_NUMERIC, nullptr);
208-
setlocale(LC_NUMERIC, "C");
209-
float val = std::stof(str.data());
210-
setlocale(LC_NUMERIC, old_locale.c_str());
211-
return val;
208+
const std::string old_locale = setlocale(LC_NUMERIC, nullptr);
209+
std::ignore = setlocale(LC_NUMERIC, "C");
210+
const std::string str_copy(str.data(), str.size());
211+
const double val = std::stod(str_copy);
212+
std::ignore = setlocale(LC_NUMERIC, old_locale.c_str());
213+
return static_cast<float>(val);
212214
}
213215

214216
template <>
@@ -439,7 +441,7 @@ bool IsAllowedPortName(StringView str)
439441
return false;
440442
}
441443
const char first_char = str.data()[0];
442-
if(!std::isalpha(first_char))
444+
if(std::isalpha(static_cast<unsigned char>(first_char)) == 0)
443445
{
444446
return false;
445447
}
@@ -467,7 +469,7 @@ bool IsReservedAttribute(StringView str)
467469

468470
Any convertFromJSON(StringView json_text, std::type_index type)
469471
{
470-
nlohmann::json json = nlohmann::json::parse(json_text);
472+
const nlohmann::json json = nlohmann::json::parse(json_text);
471473
auto res = JsonExporter::get().fromJson(json, type);
472474
if(!res)
473475
{
@@ -488,8 +490,18 @@ Expected<std::string> toJsonString(const Any& value)
488490

489491
bool StartWith(StringView str, StringView prefix)
490492
{
491-
return str.size() >= prefix.size() &&
492-
strncmp(str.data(), prefix.data(), prefix.size()) == 0;
493+
if(str.size() < prefix.size())
494+
{
495+
return false;
496+
}
497+
for(size_t i = 0; i < prefix.size(); ++i)
498+
{
499+
if(str[i] != prefix[i])
500+
{
501+
return false;
502+
}
503+
}
504+
return true;
493505
}
494506

495507
bool StartWith(StringView str, char prefix)

‎src/controls/reactive_fallback.cpp‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
namespace BT
1616
{
1717

18+
// NOLINTNEXTLINE(cppcoreguidelines-avoid-non-const-global-variables)
1819
bool ReactiveFallback::throw_if_multiple_running = false;
1920

2021
void ReactiveFallback::EnableException(bool enable)
@@ -55,7 +56,7 @@ NodeStatus ReactiveFallback::tick()
5556
{
5657
running_child_ = int(index);
5758
}
58-
else if(throw_if_multiple_running && running_child_ != int(index))
59+
else if(throw_if_multiple_running && running_child_ != static_cast<int>(index))
5960
{
6061
throw LogicError("[ReactiveFallback]: only a single child can return RUNNING.\n"
6162
"This throw can be disabled with "

‎src/controls/reactive_sequence.cpp‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
namespace BT
1616
{
1717

18+
// NOLINTNEXTLINE(cppcoreguidelines-avoid-non-const-global-variables)
1819
bool ReactiveSequence::throw_if_multiple_running = false;
1920

2021
void ReactiveSequence::EnableException(bool enable)
@@ -55,7 +56,7 @@ NodeStatus ReactiveSequence::tick()
5556
{
5657
running_child_ = int(index);
5758
}
58-
else if(throw_if_multiple_running && running_child_ != int(index))
59+
else if(throw_if_multiple_running && running_child_ != static_cast<int>(index))
5960
{
6061
throw LogicError("[ReactiveSequence]: only a single child can return RUNNING.\n"
6162
"This throw can be disabled with "

0 commit comments

Comments
 (0)