Skip to content

Commit 923661a

Browse files
committed
Silence static analysis issues
Re ECFLOW-1939
1 parent 71ca870 commit 923661a

File tree

12 files changed

+528
-453
lines changed

12 files changed

+528
-453
lines changed

ACore/src/ecflow/core/Str.hpp

+5
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,11 @@ static std::vector<std::string> transform_to_name_vector(const std::vector<T>& i
5656
return o;
5757
}
5858

59+
inline std::string tolower(std::string s) {
60+
std::transform(std::begin(s), std::end(s), std::begin(s), [](unsigned char c) { return std::tolower(c); });
61+
return s;
62+
}
63+
5964
} // namespace algorithm
6065

6166
class Str {

ANattr/src/ecflow/attribute/GenericAttr.hpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ class GenericAttr {
3232
bool empty() const { return name_.empty(); }
3333

3434
const std::string& name() const { return name_; }
35-
const std::vector<std::string>& values() { return values_; }
35+
const std::vector<std::string>& values() const { return values_; }
3636

3737
std::vector<std::string>::const_iterator values_begin() const { return values_.begin(); } // for python
3838
std::vector<std::string>::const_iterator values_end() const { return values_.end(); } // for python

Http/src/ecflow/http/ApiV1.cpp

+35-33
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ void handle_exception(const std::exception& e, const httplib::Request& request,
5454
// if user requests an ecflow script and the script does not exists, should
5555
// 404 be returned (even if the rest api path was correct)?
5656

57-
auto trimr = [](const std::string& str) -> std::string {
57+
auto trimr = [](const std::string& str) {
5858
std::string copy = str;
5959
copy.erase(copy.find_last_not_of(" \n\r") + 1, std::string::npos);
6060
return copy;
@@ -122,9 +122,11 @@ void handle_exception(const HttpServerException& e, const httplib::Request& requ
122122
}
123123

124124
void set_last_request_time() {
125-
struct timeval curtime;
125+
struct timeval curtime
126+
{
127+
};
126128
gettimeofday(&curtime, nullptr);
127-
last_request_time = curtime.tv_sec;
129+
last_request_time = static_cast<unsigned int>(curtime.tv_sec);
128130
}
129131

130132
template <typename T>
@@ -147,8 +149,9 @@ void trycatch(const httplib::Request& request, httplib::Response& response, T&&
147149
ojson filter_json(const ojson& j, const httplib::Request& r) {
148150

149151
const std::string path = r.get_param_value("filter");
150-
if (path.empty())
152+
if (path.empty()) {
151153
return j;
154+
}
152155

153156
// split filter path on dot, and reverse the elements
154157
// the elements are consumed by the dive() function
@@ -157,42 +160,45 @@ ojson filter_json(const ojson& j, const httplib::Request& r) {
157160
ecf::Str::split(path, path_elems, ".");
158161
std::reverse(path_elems.begin(), path_elems.end());
159162

160-
if (path_elems.empty())
163+
if (path_elems.empty()) {
161164
return j;
165+
}
162166

163167
// separate array name and index from a string
164-
auto get_array_info = [](const std::string& str) {
165-
auto start = str.find("["), stop = str.find("]");
166-
const std::string key = str.substr(0, start);
167-
const int index = std::stoi(str.substr(start + 1, stop - start));
168+
auto get_array_info = [](std::string_view str) {
169+
const auto start = str.find("[");
170+
const auto stop = str.find("]");
171+
const auto key = str.substr(0, start);
172+
const int index = std::stoi(std::string{str.substr(start + 1, stop - start)});
168173
return std::make_pair(key, index);
169174
};
170175

171176
// special case: filter is .[INDEX], means that we return the
172177
// correct array element from root json element assuming it's an array
173178
if (path_elems.size() == 1 && path_elems[0][0] == '[' && path_elems[0][path_elems[0].size() - 1] == ']') {
174-
const auto arr = get_array_info(path_elems[0]);
175-
return j[arr.second];
179+
const auto [key, index] = get_array_info(path_elems[0]);
180+
return j[index];
176181
}
177182

178183
// recursively find the correct element inside json document
179-
std::function<ojson(const ojson&, std::vector<std::string>&)> dive =
180-
[&](const ojson& js, std::vector<std::string>& path_elems) -> ojson {
181-
if (path_elems.empty())
184+
std::function<ojson(const ojson&, std::vector<std::string>&)> dive = [&](const ojson& js,
185+
const std::vector<std::string>& elems) {
186+
if (elems.empty()) {
182187
return js;
188+
}
183189

184190
const auto elem = path_elems.back();
185191
path_elems.pop_back();
186192

187193
try {
188194
if (elem.find("[") != std::string::npos && elem.find("]") != std::string::npos) {
189-
const auto arr = get_array_info(elem);
190-
return dive(js.at(arr.first)[arr.second], path_elems);
195+
const auto [key, index] = get_array_info(elem);
196+
return dive(js.at(std::string{key})[index], path_elems);
191197
}
192198

193199
return dive(js.at(elem), path_elems);
194200
}
195-
catch (const ojson::exception& e) {
201+
catch (const ojson::exception& e [[maybe_unused]]) {
196202
// filter path is not found or some other problem with user given path
197203
return ojson();
198204
}
@@ -399,7 +405,7 @@ void node_script_read(const httplib::Request& request, httplib::Response& respon
399405
client->file(path, "job");
400406
j["job"] = client->server_reply().get_string();
401407
}
402-
catch (const std::exception& e) {
408+
catch (const std::exception& e [[maybe_unused]]) {
403409
j["job"] = "";
404410
}
405411

@@ -484,27 +490,22 @@ void server_status_read(const httplib::Request& request, httplib::Response& resp
484490

485491
void server_status_update(const httplib::Request& request, httplib::Response& response) {
486492
trycatch(request, response, [&]() {
487-
const ojson payload = ojson::parse(request.body);
488-
const std::string name = payload.at("action");
489-
490-
auto client = get_client(request);
491-
492-
if (name == "reload_whitelist_file") {
493-
client->reloadwsfile();
493+
auto payload = ojson::parse(request.body);
494+
if (const std::string name = payload.at("action"); name == "reload_whitelist_file") {
495+
get_client(request)->reloadwsfile();
494496
}
495497
else if (name == "reload_passwd_file") {
496-
client->reloadpasswdfile();
498+
get_client(request)->reloadpasswdfile();
497499
}
498500
else if (name == "reload_custom_passwd_file") {
499-
client->reloadcustompasswdfile();
501+
get_client(request)->reloadcustompasswdfile();
500502
}
501503
else {
502504
throw HttpServerException(HttpStatusCode::client_error_bad_request, "Invalid action: " + name);
503505
}
504506

505507
ojson j;
506-
j["message"] = "Server updated successfully";
507-
508+
j["message"] = "Server updated successfully";
508509
response.status = HttpStatusCode::success_ok;
509510
response.set_content(j.dump(), "application/json");
510511
set_cors(response);
@@ -573,14 +574,15 @@ void server_statistics_read(const httplib::Request& request, httplib::Response&
573574
trycatch(request, response, [&]() {
574575
response.status = HttpStatusCode::success_ok;
575576
const std::time_t t = std::chrono::system_clock::to_time_t(api_startup);
576-
char date[80];
577-
const std::tm tm = *gmtime(&t);
578-
strftime(date, 80, "%Y-%m-%dT%H:%M:%SZ", &tm);
577+
std::array<char, 80> date{};
578+
std::tm tm{};
579+
gmtime_r(&t, &tm);
580+
strftime(date.data(), 80, "%Y-%m-%dT%H:%M:%SZ", &tm);
579581

580582
ojson j = {{"num_requests", num_requests.load()},
581583
{"num_errors", num_errors.load()},
582584
{"num_cached_requests", num_cached_requests.load()},
583-
{"since", std::string(date)}};
585+
{"since", std::string{date.data()}}};
584586

585587
j = filter_json(j, request);
586588
response.set_content(j.dump(), "application/json");

0 commit comments

Comments
 (0)