From 22f5fc947c0aaba19292ef617fa483a2ea578dd4 Mon Sep 17 00:00:00 2001 From: Guillaume Jacquemin Date: Thu, 8 Feb 2024 11:08:14 +0100 Subject: [PATCH] Application: use iterators for TextUnformatted calls. Corrade's string views aren't guaranteed to be null-terminated, though most of them come from strings, which _are_ null-terminated. Still, safety first. --- src/Application/Application.cpp | 2 +- src/Application/Application_MainManager.cpp | 7 ++++--- src/Application/Application_MassViewer.cpp | 2 +- src/Application/Application_MassViewer_Weapons.cpp | 4 ++-- src/Application/Application_ProfileManager.cpp | 4 ++-- src/Application/Application_drawAbout.cpp | 2 +- 6 files changed, 11 insertions(+), 10 deletions(-) diff --git a/src/Application/Application.cpp b/src/Application/Application.cpp index ff5efea..c5a25bc 100644 --- a/src/Application/Application.cpp +++ b/src/Application/Application.cpp @@ -421,7 +421,7 @@ Application::drawTooltip(Containers::StringView text, float wrap_pos) { if(wrap_pos > 0.0f) { ImGui::PushTextWrapPos(wrap_pos); } - ImGui::TextUnformatted(text.data()); + ImGui::TextUnformatted(text.cbegin(), text.cend()); if(wrap_pos > 0.0f) { ImGui::PopTextWrapPos(); } diff --git a/src/Application/Application_MainManager.cpp b/src/Application/Application_MainManager.cpp index 0e70234..7fc52b5 100644 --- a/src/Application/Application_MainManager.cpp +++ b/src/Application/Application_MainManager.cpp @@ -360,7 +360,7 @@ Application::drawMaterialRow(Containers::StringView name, std::int32_t tier, Gam ImGui::TableSetColumnIndex(0); ImGui::Text("T%i", tier); ImGui::TableSetColumnIndex(1); - ImGui::TextUnformatted(name.data()); + ImGui::TextUnformatted(name.cbegin(), name.cend()); ImGui::TableSetColumnIndex(2); ImGui::Text("%i", _currentProfile->material(id)); if(conf().cheatMode()) { @@ -387,7 +387,7 @@ Application::drawUnavailableMaterialRow(Containers::StringView name, std::int32_ ImGui::TableSetColumnIndex(0); ImGui::Text("T%i", tier); ImGui::TableSetColumnIndex(1); - ImGui::TextUnformatted(name.begin(), name.end()); + ImGui::TextUnformatted(name.cbegin(), name.cend()); ImGui::TableSetColumnIndex(2); ImGui::TextDisabled("Unavailable as of game version " SAVETOOL_SUPPORTED_GAME_VERSION); } @@ -480,7 +480,8 @@ Application::drawMassManager() { ImGui::TextDisabled(""); break; case GameObjects::Mass::State::Valid: - ImGui::TextUnformatted(_massManager->hangar(i).name().data()); + ImGui::TextUnformatted(_massManager->hangar(i).name().cbegin(), + _massManager->hangar(i).name().cend()); break; } diff --git a/src/Application/Application_MassViewer.cpp b/src/Application/Application_MassViewer.cpp index d4c86c0..d1c6c86 100644 --- a/src/Application/Application_MassViewer.cpp +++ b/src/Application/Application_MassViewer.cpp @@ -319,7 +319,7 @@ Application::drawCustomStyle(GameObjects::CustomStyle& style) { } if(ImGui::BeginMenuBar()) { - ImGui::TextUnformatted(style.name.data()); + ImGui::TextUnformatted(style.name.cbegin(), style.name.cend()); static Containers::StaticArray<33, char> name_buf{ValueInit}; if(ImGui::SmallButton(ICON_FA_EDIT " Rename")) { diff --git a/src/Application/Application_MassViewer_Weapons.cpp b/src/Application/Application_MassViewer_Weapons.cpp index 722b407..014ee91 100644 --- a/src/Application/Application_MassViewer_Weapons.cpp +++ b/src/Application/Application_MassViewer_Weapons.cpp @@ -257,7 +257,7 @@ Application::drawWeaponCategory(Containers::StringView name, Containers::ArrayVi { ImGui::TableNextRow(ImGuiTableRowFlags_Headers); ImGui::TableNextColumn(); - ImGui::TextUnformatted(name.data()); + ImGui::TextUnformatted(name.cbegin(), name.cend()); ImGui::PushID(payload_type.data()); @@ -458,7 +458,7 @@ Application::drawWeaponEditor(GameObjects::Weapon& weapon) { } if(map->find(part.id) != map->cend()) { - ImGui::TextUnformatted(map->at(part.id).data()); + ImGui::TextUnformatted(map->at(part.id).cbegin(), map->at(part.id).cend()); } else if(part.id == -1) { ImGui::TextUnformatted(""); diff --git a/src/Application/Application_ProfileManager.cpp b/src/Application/Application_ProfileManager.cpp index 601b939..a8f4030 100644 --- a/src/Application/Application_ProfileManager.cpp +++ b/src/Application/Application_ProfileManager.cpp @@ -266,11 +266,11 @@ Application::drawBackupListPopup() { ImGui::TableNextRow(); ImGui::TableSetColumnIndex(0); - ImGui::TextUnformatted(backup.company.data()); + ImGui::TextUnformatted(backup.company.cbegin(), backup.company.cend()); if(ImGui::IsItemHovered()) { ImGui::BeginTooltip(); for(const auto& file : backup.includedFiles) { - ImGui::TextUnformatted(file.data()); + ImGui::TextUnformatted(file.cbegin()); } ImGui::EndTooltip(); } diff --git a/src/Application/Application_drawAbout.cpp b/src/Application/Application_drawAbout.cpp index 98e858e..ab52c74 100644 --- a/src/Application/Application_drawAbout.cpp +++ b/src/Application/Application_drawAbout.cpp @@ -92,7 +92,7 @@ Application::drawAbout() { if(ImGui::BeginChild("##GPL", {0.0f, float(windowSize().y()) * 0.3f}, ImGuiChildFlags_Border)) { static auto licence = _rs.getRaw("COPYING"); ImGui::PushFont(ImGui::GetIO().Fonts->Fonts[1]); - ImGui::TextUnformatted(licence.begin(), licence.end()); + ImGui::TextUnformatted(licence.cbegin(), licence.cend()); ImGui::PopFont(); } ImGui::EndChild();