Enhance CMake configuration and improve string safety in source files
- Updated CMakeLists.txt to silence C++23 deprecation warnings and added definitions for intrinsic int128 support. - Modified GitHub Actions workflow to handle missing asset directories gracefully and ensure correct versioning in Info.plist. - Refactored string handling in multiple source files to use std::memcpy for safer string copying, preventing potential buffer overflows. - Improved font loading logic and ensured consistent handling of theme properties in the editor.
This commit is contained in:
@@ -3,6 +3,11 @@
|
||||
#include <filesystem>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <cstring>
|
||||
#include <algorithm>
|
||||
#include <cmath>
|
||||
#
|
||||
|
||||
|
||||
#include "absl/status/status.h"
|
||||
#include "absl/strings/str_cat.h"
|
||||
@@ -98,11 +103,11 @@ absl::Status LoadPackageFonts() {
|
||||
if (font_registry.fonts.empty()) {
|
||||
// Initialize the font names and sizes
|
||||
font_registry.fonts = {
|
||||
{KARLA_REGULAR, FONT_SIZE_DEFAULT},
|
||||
{ROBOTO_MEDIUM, FONT_SIZE_DEFAULT},
|
||||
{COUSINE_REGULAR, FONT_SIZE_DEFAULT},
|
||||
{IBM_PLEX_JP, FONT_SIZE_DEFAULT},
|
||||
{DROID_SANS, FONT_SIZE_DROID_SANS},
|
||||
FontConfig{KARLA_REGULAR, FONT_SIZE_DEFAULT},
|
||||
FontConfig{ROBOTO_MEDIUM, FONT_SIZE_DEFAULT},
|
||||
FontConfig{COUSINE_REGULAR, FONT_SIZE_DEFAULT},
|
||||
FontConfig{IBM_PLEX_JP, FONT_SIZE_DEFAULT},
|
||||
FontConfig{DROID_SANS, FONT_SIZE_DROID_SANS},
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
#include "dungeon_object_selector.h"
|
||||
|
||||
#include <algorithm>
|
||||
#include <iterator>
|
||||
#include <cstring>
|
||||
|
||||
@@ -1046,8 +1047,10 @@ void DungeonObjectSelector::DrawCompactPropertiesEditor() {
|
||||
static int music_id = 0;
|
||||
|
||||
// Copy current values
|
||||
std::strncpy(room_name, properties.name.c_str(), sizeof(room_name) - 1);
|
||||
room_name[sizeof(room_name) - 1] = '\0';
|
||||
// Safe string copy with bounds checking
|
||||
size_t name_len = std::min(properties.name.length(), sizeof(room_name) - 1);
|
||||
std::memcpy(room_name, properties.name.c_str(), name_len);
|
||||
room_name[name_len] = '\0';
|
||||
dungeon_id = properties.dungeon_id;
|
||||
floor_level = properties.floor_level;
|
||||
is_boss_room = properties.is_boss_room;
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
#include "editor_manager.h"
|
||||
|
||||
#include <algorithm>
|
||||
#include <chrono>
|
||||
#include <cstring>
|
||||
|
||||
@@ -2254,8 +2255,11 @@ void EditorManager::DrawSessionSwitcher() {
|
||||
ImGui::SameLine();
|
||||
if (ImGui::Button("Rename")) {
|
||||
session_to_rename_ = i;
|
||||
std::strncpy(session_rename_buffer_, session.GetDisplayName().c_str(), sizeof(session_rename_buffer_) - 1);
|
||||
session_rename_buffer_[sizeof(session_rename_buffer_) - 1] = '\0';
|
||||
// Safe string copy with bounds checking
|
||||
const std::string& name = session.GetDisplayName();
|
||||
size_t copy_len = std::min(name.length(), sizeof(session_rename_buffer_) - 1);
|
||||
std::memcpy(session_rename_buffer_, name.c_str(), copy_len);
|
||||
session_rename_buffer_[copy_len] = '\0';
|
||||
show_session_rename_dialog_ = true;
|
||||
}
|
||||
|
||||
@@ -2431,8 +2435,11 @@ void EditorManager::DrawSessionManager() {
|
||||
ImGui::SameLine();
|
||||
if (ImGui::Button("Rename")) {
|
||||
session_to_rename_ = i;
|
||||
std::strncpy(session_rename_buffer_, session.GetDisplayName().c_str(), sizeof(session_rename_buffer_) - 1);
|
||||
session_rename_buffer_[sizeof(session_rename_buffer_) - 1] = '\0';
|
||||
// Safe string copy with bounds checking
|
||||
const std::string& name = session.GetDisplayName();
|
||||
size_t copy_len = std::min(name.length(), sizeof(session_rename_buffer_) - 1);
|
||||
std::memcpy(session_rename_buffer_, name.c_str(), copy_len);
|
||||
session_rename_buffer_[copy_len] = '\0';
|
||||
show_session_rename_dialog_ = true;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
#include "theme_manager.h"
|
||||
|
||||
#include <algorithm>
|
||||
#include <cctype>
|
||||
#include <fstream>
|
||||
#include <set>
|
||||
@@ -1778,12 +1779,18 @@ void ThemeManager::ShowSimpleThemeEditor(bool* p_open) {
|
||||
ImGui::SameLine();
|
||||
if (ImGui::Button("Reset to Current")) {
|
||||
edit_theme = current_theme_;
|
||||
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';
|
||||
// Safe string copy with bounds checking
|
||||
size_t name_len = std::min(current_theme_.name.length(), sizeof(theme_name) - 1);
|
||||
std::memcpy(theme_name, current_theme_.name.c_str(), name_len);
|
||||
theme_name[name_len] = '\0';
|
||||
|
||||
size_t desc_len = std::min(current_theme_.description.length(), sizeof(theme_description) - 1);
|
||||
std::memcpy(theme_description, current_theme_.description.c_str(), desc_len);
|
||||
theme_description[desc_len] = '\0';
|
||||
|
||||
size_t author_len = std::min(current_theme_.author.length(), sizeof(theme_author) - 1);
|
||||
std::memcpy(theme_author, current_theme_.author.c_str(), author_len);
|
||||
theme_author[author_len] = '\0';
|
||||
|
||||
// Reset backup state since we're back to current theme
|
||||
if (theme_backup_made) {
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
#include "yaze.h"
|
||||
|
||||
#include <algorithm>
|
||||
#include <cstring>
|
||||
#include <iostream>
|
||||
#include <memory>
|
||||
@@ -292,8 +293,8 @@ yaze_status yaze_load_messages(const zelda3_rom* rom, zelda3_message** messages,
|
||||
std::memcpy((*messages)[i].raw_data, msg.Data.data(), msg.Data.size());
|
||||
|
||||
(*messages)[i].parsed_text = new char[msg.ContentsParsed.length() + 1];
|
||||
std::strncpy((*messages)[i].parsed_text, msg.ContentsParsed.c_str(),
|
||||
msg.ContentsParsed.length());
|
||||
// Safe string copy with bounds checking
|
||||
std::memcpy((*messages)[i].parsed_text, msg.ContentsParsed.c_str(), msg.ContentsParsed.length());
|
||||
(*messages)[i].parsed_text[msg.ContentsParsed.length()] = '\0';
|
||||
|
||||
(*messages)[i].is_compressed = false; // TODO: Detect compression
|
||||
|
||||
Reference in New Issue
Block a user