fix: cppcheck (21 troballes)

This commit is contained in:
2026-05-16 13:52:31 +02:00
parent a48fe51f73
commit bf7be3a7f1
13 changed files with 96 additions and 117 deletions
+13 -15
View File
@@ -3,6 +3,7 @@
#include <sys/stat.h>
#include <unistd.h>
#include <algorithm>
#include <filesystem>
#include <fstream>
#include <string>
@@ -90,11 +91,10 @@ void file_setconfigfolder(const char* foldername) {
homedir = "/tmp";
}
config_folder = std::string(homedir) + "/.config/" + foldername;
#else
config_folder = std::string("/tmp/jailgames_config/") + foldername;
#endif
if (config_folder.empty()) {
config_folder = "/tmp/jailgames_config";
}
std::error_code ec;
std::filesystem::create_directories(config_folder, ec);
// A emscripten/MEMFS create_directories pot fallar (p.ex. parent
@@ -112,12 +112,11 @@ auto file_getconfigvalue(const char* key) -> const char* {
if (config.empty()) {
load_config_values();
}
for (const auto& pair : config) {
if (pair.key == key) {
thread_local std::string value_cache;
value_cache = pair.value;
return value_cache.c_str();
}
const auto it = std::find_if(config.begin(), config.end(), [key](const keyvalue& pair) { return pair.key == key; });
if (it != config.end()) {
thread_local std::string value_cache;
value_cache = it->value;
return value_cache.c_str();
}
return nullptr;
}
@@ -126,12 +125,11 @@ void file_setconfigvalue(const char* key, const char* value) {
if (config.empty()) {
load_config_values();
}
for (auto& pair : config) {
if (pair.key == key) {
pair.value = value;
save_config_values();
return;
}
const auto it = std::find_if(config.begin(), config.end(), [key](const keyvalue& pair) { return pair.key == key; });
if (it != config.end()) {
it->value = value;
save_config_values();
return;
}
config.push_back({std::string(key), std::string(value)});
save_config_values();