Update library directories and improve string handling in source files

- Added 'absl::numeric' to the AdditionalLibraryDirectories in yaze.vcxproj for enhanced functionality.
- Refactored string handling in multiple source files to use std::strncpy for safer string copying and prevent buffer overflows.
- Cleaned up unnecessary whitespace and improved code readability across various files.
This commit is contained in:
scawful
2025-09-27 21:55:01 -04:00
parent a9f1a1637d
commit 332f050cf6
6 changed files with 73 additions and 58 deletions

View File

@@ -276,7 +276,7 @@ std::vector<std::string> FileDialogWrapper::GetSubdirectoriesInFolder(
if (findFileData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) {
if (strcmp(findFileData.cFileName, ".") != 0 &&
strcmp(findFileData.cFileName, "..") != 0) {
subdirectories.push_back(findFileData.cFileName);
subdirectories.emplace_back(findFileData.cFileName);
}
}
} while (FindNextFile(hFind, &findFileData) != 0);
@@ -293,7 +293,7 @@ std::vector<std::string> FileDialogWrapper::GetFilesInFolder(
if (hFind != INVALID_HANDLE_VALUE) {
do {
if (!(findFileData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)) {
files.push_back(findFileData.cFileName);
files.emplace_back(findFileData.cFileName);
}
} while (FindNextFile(hFind, &findFileData) != 0);
FindClose(hFind);

View File

@@ -1,6 +1,7 @@
#include "dungeon_object_selector.h"
#include <iterator>
#include <cstring>
#include "app/core/window.h"
#include "app/gfx/arena.h"
@@ -1045,7 +1046,8 @@ void DungeonObjectSelector::DrawCompactPropertiesEditor() {
static int music_id = 0;
// Copy current values
strncpy(room_name, properties.name.c_str(), sizeof(room_name) - 1);
std::strncpy(room_name, properties.name.c_str(), sizeof(room_name) - 1);
room_name[sizeof(room_name) - 1] = '\0';
dungeon_id = properties.dungeon_id;
floor_level = properties.floor_level;
is_boss_room = properties.is_boss_room;

View File

@@ -1,6 +1,7 @@
#include "editor_manager.h"
#include <chrono>
#include <cstring>
#include "absl/status/status.h"
#include "absl/strings/match.h"
@@ -2253,7 +2254,8 @@ void EditorManager::DrawSessionSwitcher() {
ImGui::SameLine();
if (ImGui::Button("Rename")) {
session_to_rename_ = i;
strncpy(session_rename_buffer_, session.GetDisplayName().c_str(), sizeof(session_rename_buffer_) - 1);
std::strncpy(session_rename_buffer_, session.GetDisplayName().c_str(), sizeof(session_rename_buffer_) - 1);
session_rename_buffer_[sizeof(session_rename_buffer_) - 1] = '\0';
show_session_rename_dialog_ = true;
}
@@ -2429,7 +2431,8 @@ void EditorManager::DrawSessionManager() {
ImGui::SameLine();
if (ImGui::Button("Rename")) {
session_to_rename_ = i;
strncpy(session_rename_buffer_, session.GetDisplayName().c_str(), sizeof(session_rename_buffer_) - 1);
std::strncpy(session_rename_buffer_, session.GetDisplayName().c_str(), sizeof(session_rename_buffer_) - 1);
session_rename_buffer_[sizeof(session_rename_buffer_) - 1] = '\0';
show_session_rename_dialog_ = true;
}

View File

@@ -4,6 +4,7 @@
#include <fstream>
#include <set>
#include <sstream>
#include <cstring>
#include "absl/strings/str_format.h"
#include "absl/strings/str_split.h"
@@ -1777,9 +1778,12 @@ void ThemeManager::ShowSimpleThemeEditor(bool* p_open) {
ImGui::SameLine();
if (ImGui::Button("Reset to Current")) {
edit_theme = current_theme_;
strncpy(theme_name, current_theme_.name.c_str(), sizeof(theme_name));
strncpy(theme_description, current_theme_.description.c_str(), sizeof(theme_description));
strncpy(theme_author, current_theme_.author.c_str(), sizeof(theme_author));
std::strncpy(theme_name, current_theme_.name.c_str(), sizeof(theme_name) - 1);
theme_name[sizeof(theme_name) - 1] = '\0';
std::strncpy(theme_description, current_theme_.description.c_str(), sizeof(theme_description) - 1);
theme_description[sizeof(theme_description) - 1] = '\0';
std::strncpy(theme_author, current_theme_.author.c_str(), sizeof(theme_author) - 1);
theme_author[sizeof(theme_author) - 1] = '\0';
// Reset backup state since we're back to current theme
if (theme_backup_made) {