diff --git a/src/common/settings_enums.h b/src/common/settings_enums.h index da142e8e1c..0254b1df01 100644 --- a/src/common/settings_enums.h +++ b/src/common/settings_enums.h @@ -75,7 +75,7 @@ struct EnumMetadata { #define PP_HEAD(A, ...) A #define ENUM(NAME, ...) \ - enum class NAME : u32 { __VA_ARGS__ }; \ + enum class NAME : u32 { __VA_ARGS__, Count }; \ template<> inline std::vector> EnumMetadata::Canonicalizations() { \ return {PAIR(NAME, __VA_ARGS__)}; \ } \ diff --git a/src/common/settings_setting.h b/src/common/settings_setting.h index 2ee8b0cd20..6b5fb4053b 100644 --- a/src/common/settings_setting.h +++ b/src/common/settings_setting.h @@ -11,6 +11,7 @@ #include #include #include +#include #include #include #include @@ -371,7 +372,13 @@ public: * @param val The new value */ void SetValue(const Type& val) override final { - Type temp{ranged ? std::clamp(val, this->minimum, this->maximum) : val}; + // Enums have a maximal range which they're allowed + Type temp{}; + if constexpr (std::is_enum_v) { + temp = Type(std::clamp(std::underlying_type_t(val), std::underlying_type_t(0), std::underlying_type_t(Type::Count) - 1)); + } else { + temp = ranged ? std::clamp(val, this->minimum, this->maximum) : val; + } if (use_global) { std::swap(this->value, temp); } else { diff --git a/src/frontend_common/config.cpp b/src/frontend_common/config.cpp index 809021fad0..b44a146b38 100644 --- a/src/frontend_common/config.cpp +++ b/src/frontend_common/config.cpp @@ -238,28 +238,22 @@ void Config::ReadControlValues() { void Config::ReadMotionTouchValues() { Settings::values.touch_from_button_maps.clear(); int num_touch_from_button_maps = BeginArray(std::string("touch_from_button_maps")); - if (num_touch_from_button_maps > 0) { for (int i = 0; i < num_touch_from_button_maps; ++i) { SetArrayIndex(i); - Settings::TouchFromButtonMap map; map.name = ReadStringSetting(std::string("name"), std::string("default")); int const num_touch_maps = BeginArray(std::string("entries")); - if (num_touch_maps > 0) { - map.buttons.reserve(num_touch_maps); - for (int j = 0; j < num_touch_maps; j++) { - SetArrayIndex(j); - std::string touch_mapping = ReadStringSetting(std::string("bind")); - map.buttons.emplace_back(std::move(touch_mapping)); - } + map.buttons.resize(num_touch_maps); + for (int j = 0; j < num_touch_maps; j++) { + SetArrayIndex(j); + map.buttons[j] = ReadStringSetting(std::string("bind")); } EndArray(); // entries Settings::values.touch_from_button_maps.emplace_back(std::move(map)); } } else { - Settings::values.touch_from_button_maps.emplace_back( - Settings::TouchFromButtonMap{"default", {}}); + Settings::values.touch_from_button_maps.emplace_back(Settings::TouchFromButtonMap{"default", {}}); num_touch_from_button_maps = 1; } EndArray(); // touch_from_button_maps @@ -501,15 +495,12 @@ void Config::SaveMotionTouchValues() { BeginArray(std::string("touch_from_button_maps")); for (std::size_t p = 0; p < Settings::values.touch_from_button_maps.size(); ++p) { SetArrayIndex(int(p)); - WriteStringSetting(std::string("name"), Settings::values.touch_from_button_maps[p].name, - std::make_optional(std::string("default"))); - + WriteStringSetting(std::string("name"), Settings::values.touch_from_button_maps[p].name, std::make_optional(std::string("default"))); BeginArray(std::string("entries")); for (std::size_t q = 0; q < Settings::values.touch_from_button_maps[p].buttons.size(); ++q) { SetArrayIndex(int(q)); - WriteStringSetting(std::string("bind"), - Settings::values.touch_from_button_maps[p].buttons[q]); + WriteStringSetting(std::string("bind"), Settings::values.touch_from_button_maps[p].buttons[q]); } EndArray(); // entries } @@ -638,8 +629,7 @@ void Config::SaveDisabledAddOnValues() { BeginArray(std::string("disabled")); for (std::size_t j = 0; j < elem.second.size(); ++j) { SetArrayIndex(int(j)); - WriteStringSetting(std::string("d"), elem.second[j], - std::make_optional(std::string(""))); + WriteStringSetting(std::string("d"), elem.second[j], std::make_optional(std::string(""))); } EndArray(); // disabled ++i; @@ -733,21 +723,18 @@ s64 Config::ReadIntegerSetting(const std::string& key, const std::optional std::string full_key = GetFullKey(key, false); if (!default_value.has_value()) { try { - return std::stoll( - std::string(config->GetValue(GetSection().c_str(), full_key.c_str(), "0"))); + return std::stoll(std::string(config->GetValue(GetSection().c_str(), full_key.c_str(), "0"))); } catch (...) { return 0; } } s64 result = 0; - if (config->GetBoolValue(GetSection().c_str(), - std::string(full_key).append("\\default").c_str(), true)) { + if (config->GetBoolValue(GetSection().c_str(), std::string(full_key).append("\\default").c_str(), true)) { result = default_value.value(); } else { try { - result = std::stoll(std::string(config->GetValue( - GetSection().c_str(), full_key.c_str(), ToString(default_value.value()).c_str()))); + result = std::stoll(std::string(config->GetValue(GetSection().c_str(), full_key.c_str(), ToString(default_value.value()).c_str()))); } catch (...) { result = default_value.value(); } @@ -919,14 +906,12 @@ void Config::ReadSettingGeneric(Settings::BasicSetting* const setting) { bool use_global = true; if (setting->Switchable() && !global) { - use_global = - ReadBooleanSetting(std::string(key).append("\\use_global"), std::make_optional(true)); + use_global = ReadBooleanSetting(std::string(key).append("\\use_global"), std::make_optional(true)); setting->SetGlobal(use_global); } if (global || !use_global) { - const bool is_default = - ReadBooleanSetting(std::string(key).append("\\default"), std::make_optional(true)); + const bool is_default = ReadBooleanSetting(std::string(key).append("\\default"), std::make_optional(true)); if (!is_default) { setting->LoadString(ReadStringSetting(key, default_value)); } else { @@ -1051,8 +1036,8 @@ std::string Config::GetFullKey(const std::string& key, bool skipArrayIndex) { int Config::BeginArray(const std::string& array) { array_stack.push_back(ConfigArray{AdjustKey(array), 0, 0}); const int size = config->GetLongValue(GetSection().c_str(), GetFullKey(std::string("size"), true).c_str(), 0); - array_stack.back().size = size; - return size; + array_stack.back().size = (std::max)(0, size); + return array_stack.back().size; } void Config::EndArray() { @@ -1070,7 +1055,7 @@ void Config::EndArray() { // Edge-case where the first array created doesn't have a name config->SetValue(GetSection().c_str(), std::string("size").c_str(), ToString(size).c_str()); } else { - const auto key = GetFullKey(std::string("size"), true); + auto const key = GetFullKey(std::string("size"), true); config->SetValue(GetSection().c_str(), key.c_str(), ToString(size).c_str()); } diff --git a/src/input_common/drivers/udp_client.cpp b/src/input_common/drivers/udp_client.cpp index fc216e3c9f..7566e6040c 100644 --- a/src/input_common/drivers/udp_client.cpp +++ b/src/input_common/drivers/udp_client.cpp @@ -31,8 +31,10 @@ public: using clock = std::chrono::system_clock; explicit Socket(const std::string& host, u16 port, SocketCallback callback_) - : callback(std::move(callback_)), timer(io_context), - socket(io_context, udp::endpoint(udp::v4(), 0)), client_id(Common::Random::Random32(0)) { + : callback(std::move(callback_)), timer(io_context) + , socket(io_context, udp::endpoint(udp::v4(), 0)) + , client_id(Common::Random::Random32(0)) + { boost::system::error_code ec{}; auto ipv4 = boost::asio::ip::make_address_v4(host, ec); if (ec.value() != boost::system::errc::success) { @@ -353,8 +355,13 @@ PadIdentifier UDPClient::GetPadIdentifier(std::size_t pad_index) const { } Common::UUID UDPClient::GetHostUUID(const std::string& host) const { - const auto ip = boost::asio::ip::make_address_v4(host); - const auto hex_host = fmt::format("00000000-0000-0000-0000-0000{:06x}", ip.to_uint()); + boost::system::error_code ec{}; + auto ip = boost::asio::ip::make_address_v4(host, ec); + if (ec.value() != boost::system::errc::success) { + LOG_ERROR(Input, "Invalid IPv4 address \"{}\" provided", host); + ip = boost::asio::ip::address_v4{}; + } + auto const hex_host = fmt::format("00000000-0000-0000-0000-0000{:06x}", ip.to_uint()); return Common::UUID{hex_host}; } diff --git a/src/yuzu/game/game_list.cpp b/src/yuzu/game/game_list.cpp index 63267ddec6..521c5607f5 100644 --- a/src/yuzu/game/game_list.cpp +++ b/src/yuzu/game/game_list.cpp @@ -183,7 +183,7 @@ void GameList::ResetViewMode() { tree_view->setVisible(false); break; default: - break; + UNREACHABLE(); } auto view = m_currentView->viewport(); @@ -196,10 +196,8 @@ void GameList::ResetViewMode() { auto scroller = QScroller::scroller(view); QScrollerProperties props; - props.setScrollMetric(QScrollerProperties::HorizontalOvershootPolicy, - QScrollerProperties::OvershootAlwaysOff); - props.setScrollMetric(QScrollerProperties::VerticalOvershootPolicy, - QScrollerProperties::OvershootAlwaysOff); + props.setScrollMetric(QScrollerProperties::HorizontalOvershootPolicy, QScrollerProperties::OvershootAlwaysOff); + props.setScrollMetric(QScrollerProperties::VerticalOvershootPolicy, QScrollerProperties::OvershootAlwaysOff); scroller->setScrollerProperties(props); if (m_isTreeMode != newTreeMode) { diff --git a/tools/README.md b/tools/README.md index 367a00f246..d4f5aa1baa 100644 --- a/tools/README.md +++ b/tools/README.md @@ -28,6 +28,8 @@ Tools for Eden and other subprojects. When adding new scripts please use `#!/bin - `clang-format.sh`: Runs `clang-format` on the entire codebase. * Requires: clang - `find-unused-strings.sh`: Find any unused strings in the Android app (XML -> Kotlin). +- `cpp-lint.sh`: Homemade dumb C++ linter. +- `fuzzsettings.cpp`: Fuzz settings files. ## Android It's recommended to run these scritps after almost any Android change, as they are relatively fast and important both for APK bloat and CI. diff --git a/tools/fuzzsettings.cpp b/tools/fuzzsettings.cpp index 2d62f3302f..e9685ce9f4 100644 --- a/tools/fuzzsettings.cpp +++ b/tools/fuzzsettings.cpp @@ -30,7 +30,9 @@ int main(int argc, char *argv[]) { if (value == "true" || value == "false") { new_line += std::string{} + "=TreufLAlse857874FJJakshjryiu475" + '\n'; } else if (std::isdigit(value[0])) { - if (new_line == "size" || std::strstr(new_line.c_str(), "entries\\size") != nullptr) { + if (new_line == "size" + || std::strstr(new_line.c_str(), "entries\\size") != nullptr + || std::strstr(new_line.c_str(), "\\size")) { new_line += "=-1\n"; } else { new_line += '=' + std::to_string(int(std::rand())) + '\n'; @@ -46,7 +48,12 @@ int main(int argc, char *argv[]) { } std::printf("%s", new_line.c_str()); } else { - std::printf("%s", line); + // yes default + *p = '\0'; + std::string new_line{line}; + std::string value{p + 1}; + new_line += "=false\n"; + std::printf("%s", new_line.c_str()); } } }