Merge branch 'error_warning_fixes' into 'main'

fix: Resolve critical memory-safety compiler warnings

See merge request citron/emulator!89
This commit is contained in:
Zephyron
2025-10-07 15:34:58 +10:00
3 changed files with 50 additions and 3 deletions

View File

@@ -399,7 +399,7 @@ if(USE_DISCORD_PRESENCE)
# Check if the target directory exists before trying to patch # Check if the target directory exists before trying to patch
if(EXISTS "${PATCH_TARGET_DIR}") if(EXISTS "${PATCH_TARGET_DIR}")
execute_process( execute_process(
COMMAND git apply --ignore-whitespace "${PATCH_FILE}" COMMAND git apply -p0 --ignore-whitespace "${PATCH_FILE}"
WORKING_DIRECTORY "${PATCH_TARGET_DIR}" WORKING_DIRECTORY "${PATCH_TARGET_DIR}"
RESULT_VARIABLE PATCH_RESULT RESULT_VARIABLE PATCH_RESULT
OUTPUT_QUIET OUTPUT_QUIET
@@ -422,7 +422,7 @@ if(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
if(EXISTS "${MCL_PATCH_TARGET_DIR}") if(EXISTS "${MCL_PATCH_TARGET_DIR}")
execute_process( execute_process(
COMMAND git apply --ignore-whitespace "${MCL_PATCH_FILE}" COMMAND git apply -p0 --ignore-whitespace "${MCL_PATCH_FILE}"
WORKING_DIRECTORY "${MCL_PATCH_TARGET_DIR}" WORKING_DIRECTORY "${MCL_PATCH_TARGET_DIR}"
RESULT_VARIABLE MCL_PATCH_RESULT RESULT_VARIABLE MCL_PATCH_RESULT
OUTPUT_QUIET OUTPUT_QUIET
@@ -437,6 +437,30 @@ if(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
endif() endif()
endif() endif()
# Apply a patch to stb_image.h to fix a string overflow warning with modern compilers
message(STATUS "Applying custom patch to stb_image.h...")
set(STB_PATCH_FILE "${CMAKE_CURRENT_SOURCE_DIR}/patches/stb_image-overflow-fix.patch")
set(STB_PATCH_WORKING_DIR "${CMAKE_CURRENT_SOURCE_DIR}")
# Check if the file to be patched exists before trying to patch
if(EXISTS "${STB_PATCH_WORKING_DIR}/externals/stb/stb_image.h")
execute_process(
COMMAND git apply -p0 --ignore-whitespace "${STB_PATCH_FILE}"
WORKING_DIRECTORY "${STB_PATCH_WORKING_DIR}"
RESULT_VARIABLE PATCH_RESULT
OUTPUT_QUIET
ERROR_QUIET
)
if(NOT PATCH_RESULT EQUAL 0)
message(WARNING "Failed to apply stb_image.h compiler fix patch! This might be okay if it's already applied.")
endif()
else()
message(WARNING "Could not find stb_image.h to patch. It may not have been downloaded yet.")
endif()
if (ENABLE_QT) if (ENABLE_QT)
if (NOT USE_SYSTEM_QT) if (NOT USE_SYSTEM_QT)
download_qt(6.7.3) download_qt(6.7.3)

View File

@@ -0,0 +1,22 @@
diff --git externals/stb/stb_image.h externals/stb/stb_image.h
index 5e807a0a6..725d0ec9e 100644
--- externals/stb/stb_image.h
+++ externals/stb/stb_image.h
@@ -5079,7 +5079,7 @@ static void stbi__de_iphone(stbi__png *z)
static int stbi__parse_png_file(stbi__png *z, int scan, int req_comp)
{
stbi_uc palette[1024], pal_img_n=0;
- stbi_uc has_trans=0, tc[3]={0};
+ stbi_uc has_trans=0, tc[4]={0};
stbi__uint16 tc16[3];
stbi__uint32 ioff=0, idata_limit=0, i, pal_len=0;
int first=1,k,interlace=0, color=0, is_iphone=0;
@@ -5163,7 +5163,7 @@ static int stbi__parse_png_file(stbi__png *z, int scan, int req_comp)
if (z->depth == 16) {
for (k = 0; k < s->img_n; ++k) tc16[k] = (stbi__uint16)stbi__get16be(s); // copy the values as-is
} else {
- for (k = 0; k < s->img_n; ++k) tc[k] = (stbi_uc)(stbi__get16be(s) & 255) * stbi__depth_scale_table[z->depth]; // non 8-bit images will be larger
+ for (k = 0; k < s->img_n && k < 4; ++k) tc[k] = (stbi_uc)(stbi__get16be(s) & 255) * stbi__depth_scale_table[z->depth]; // non 8-bit images will be larger
}
}
break;

View File

@@ -1,4 +1,5 @@
// SPDX-FileCopyrightText: Copyright 2021 yuzu Emulator Project // SPDX-FileCopyrightText: Copyright 2021 yuzu Emulator Project
// SPDX-FileCopyrightText: Copyright 2025 citron Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later // SPDX-License-Identifier: GPL-2.0-or-later
#include <thread> #include <thread>
@@ -65,7 +66,7 @@ void DefaultSoftwareKeyboardApplet::ShowNormalKeyboard() const {
LOG_WARNING(Service_AM, LOG_WARNING(Service_AM,
"(STUBBED) called, backend requested to show the normal software keyboard."); "(STUBBED) called, backend requested to show the normal software keyboard.");
SubmitNormalText(u"citron"); SubmitNormalText(std::u16string(u"citron", 6));
} }
void DefaultSoftwareKeyboardApplet::ShowTextCheckDialog( void DefaultSoftwareKeyboardApplet::ShowTextCheckDialog(