From f594de0081a7a558ba56c2d1fcf467ea8a6f449a Mon Sep 17 00:00:00 2001 From: Michael Scire Date: Thu, 25 Jun 2020 17:32:22 -0700 Subject: [PATCH] ams: add -Wno-format-truncation to flags --- libraries/config/common.mk | 6 +++-- .../source/ams/ams_emummc_api.cpp | 25 ++++++++----------- .../source/patcher/patcher_api.cpp | 3 --- .../source/set_mitm/setsys_mitm_service.cpp | 14 ++++------- stratosphere/erpt/source/erpt_main.cpp | 3 --- 5 files changed, 19 insertions(+), 32 deletions(-) diff --git a/libraries/config/common.mk b/libraries/config/common.mk index ebe9bcfb8..9e8a0af3c 100644 --- a/libraries/config/common.mk +++ b/libraries/config/common.mk @@ -17,8 +17,10 @@ endif export ATMOSPHERE_DEFINES := -DATMOSPHERE export ATMOSPHERE_SETTINGS := -fPIE -g -export ATMOSPHERE_CFLAGS := -Wall -ffunction-sections -fdata-sections -fno-strict-aliasing -fwrapv \ - -fno-asynchronous-unwind-tables -fno-unwind-tables -fno-stack-protector +export ATMOSPHERE_CFLAGS := -Wall -ffunction-sections -fdata-sections -fno-strict-aliasing -fwrapv \ + -fno-asynchronous-unwind-tables -fno-unwind-tables -fno-stack-protector \ + -Wno-format-truncation + export ATMOSPHERE_CXXFLAGS := -fno-rtti -fno-exceptions -std=gnu++20 export ATMOSPHERE_ASFLAGS := diff --git a/libraries/libstratosphere/source/ams/ams_emummc_api.cpp b/libraries/libstratosphere/source/ams/ams_emummc_api.cpp index f1c1c8880..585cac264 100644 --- a/libraries/libstratosphere/source/ams/ams_emummc_api.cpp +++ b/libraries/libstratosphere/source/ams/ams_emummc_api.cpp @@ -86,22 +86,17 @@ namespace ams::emummc { const Storage storage = static_cast(g_exo_config.base_cfg.type); g_is_emummc = g_exo_config.base_cfg.magic == StorageMagic && storage != Storage_Emmc; - /* Format paths. Ignore string format warnings. */ - #pragma GCC diagnostic push - #pragma GCC diagnostic ignored "-Wformat-truncation" - { - if (storage == Storage_SdFile) { - std::snprintf(g_exo_config.file_cfg.path, sizeof(g_exo_config.file_cfg.path), "/%s", paths->file_path); - } - - std::snprintf(g_exo_config.emu_dir_path, sizeof(g_exo_config.emu_dir_path), "/%s", paths->nintendo_path); - - /* If we're emummc, implement default nintendo redirection path. */ - if (g_is_emummc && std::strcmp(g_exo_config.emu_dir_path, "/") == 0) { - std::snprintf(g_exo_config.emu_dir_path, sizeof(g_exo_config.emu_dir_path), "/emummc/Nintendo_%04x", g_exo_config.base_cfg.id); - } + /* Format paths. */ + if (storage == Storage_SdFile) { + std::snprintf(g_exo_config.file_cfg.path, sizeof(g_exo_config.file_cfg.path), "/%s", paths->file_path); + } + + std::snprintf(g_exo_config.emu_dir_path, sizeof(g_exo_config.emu_dir_path), "/%s", paths->nintendo_path); + + /* If we're emummc, implement default nintendo redirection path. */ + if (g_is_emummc && std::strcmp(g_exo_config.emu_dir_path, "/") == 0) { + std::snprintf(g_exo_config.emu_dir_path, sizeof(g_exo_config.emu_dir_path), "/emummc/Nintendo_%04x", g_exo_config.base_cfg.id); } - #pragma GCC diagnostic pop } g_has_cached = true; diff --git a/libraries/libstratosphere/source/patcher/patcher_api.cpp b/libraries/libstratosphere/source/patcher/patcher_api.cpp index c7ec0ab9b..d13fabbaa 100644 --- a/libraries/libstratosphere/source/patcher/patcher_api.cpp +++ b/libraries/libstratosphere/source/patcher/patcher_api.cpp @@ -237,10 +237,7 @@ namespace ams::patcher { } /* Print the path for this directory. */ -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Wformat-truncation" std::snprintf(path + patches_dir_path_len, sizeof(path) - patches_dir_path_len, "/%s", entry.name); -#pragma GCC diagnostic pop const size_t patch_dir_path_len = patches_dir_path_len + 1 + std::strlen(entry.name); /* Open the patch directory. */ diff --git a/stratosphere/ams_mitm/source/set_mitm/setsys_mitm_service.cpp b/stratosphere/ams_mitm/source/set_mitm/setsys_mitm_service.cpp index 130314ce0..7f21d3c28 100644 --- a/stratosphere/ams_mitm/source/set_mitm/setsys_mitm_service.cpp +++ b/stratosphere/ams_mitm/source/set_mitm/setsys_mitm_service.cpp @@ -56,15 +56,11 @@ namespace ams::mitm::settings { const auto api_info = exosphere::GetApiInfo(); const char emummc_char = emummc::IsActive() ? 'E' : 'S'; - /* GCC complains about the following snprintf possibly truncating, but this is not a problem and has been carefully accounted for. */ - #pragma GCC diagnostic push - #pragma GCC diagnostic ignored "-Wformat-truncation" - { - char display_version[sizeof(g_ams_firmware_version.display_version)]; - std::snprintf(display_version, sizeof(display_version), "%s|AMS %u.%u.%u|%c", g_ams_firmware_version.display_version, api_info.GetMajorVersion(), api_info.GetMinorVersion(), api_info.GetMicroVersion(), emummc_char); - std::memcpy(g_ams_firmware_version.display_version, display_version, sizeof(display_version)); - } - #pragma GCC diagnostic pop + /* NOTE: We have carefully accounted for the size of the string we print. */ + /* No truncation occurs assuming two-digits for all version number components. */ + char display_version[sizeof(g_ams_firmware_version.display_version)]; + std::snprintf(display_version, sizeof(display_version), "%s|AMS %u.%u.%u|%c", g_ams_firmware_version.display_version, api_info.GetMajorVersion(), api_info.GetMinorVersion(), api_info.GetMicroVersion(), emummc_char); + std::memcpy(g_ams_firmware_version.display_version, display_version, sizeof(display_version)); } g_cached_firmware_version = true; diff --git a/stratosphere/erpt/source/erpt_main.cpp b/stratosphere/erpt/source/erpt_main.cpp index f777a23ab..52823bb36 100644 --- a/stratosphere/erpt/source/erpt_main.cpp +++ b/stratosphere/erpt/source/erpt_main.cpp @@ -138,10 +138,7 @@ int main(int argc, char **argv) settings::system::GetSerialNumber(std::addressof(serial_number)); char os_private[0x60]; -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Wformat-truncation" const auto os_priv_len = std::snprintf(os_private, sizeof(os_private), "%s (%.8s)", firmware_version.display_name, firmware_version.revision); -#pragma GCC diagnostic pop AMS_ASSERT(static_cast(os_priv_len) < sizeof(os_private)); R_ABORT_UNLESS(erpt::srv::SetSerialNumberAndOsVersion(serial_number.str,