From 814ae29df241b381123504d31c88976ba571ad90 Mon Sep 17 00:00:00 2001 From: Jesus Lopez Date: Mon, 1 Jul 2024 09:43:56 -0700 Subject: [PATCH 1/2] build: do not use threads on macOS builds Avoids compile issue due to lack of `pthread_getattr_np` function. --- src/asar/CMakeLists.txt | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/asar/CMakeLists.txt b/src/asar/CMakeLists.txt index df7d0e86..4b6c80c3 100644 --- a/src/asar/CMakeLists.txt +++ b/src/asar/CMakeLists.txt @@ -7,11 +7,20 @@ option(ASAR_GEN_EXE "Build Asar standalone application" ON) option(ASAR_GEN_DLL "Build Asar shared library" ON) option(ASAR_GEN_LIB "Build Asar static library" ON) option(ASAR_COVERAGE "Build Asar with coverage tracking support" OFF) -option(ASAR_USE_THREADS "Run Asar in a new thread to alleviate stack usage problems" ON) if (MSVC) message(STATUS "In MSVC you can override MSVC_LIB_TYPE, valid values are D for dynamic and T for static") endif() +# Determine default value based on the operating system +if(APPLE) + set(ASAR_USE_THREADS_DEFAULT OFF) +else() + set(ASAR_USE_THREADS_DEFAULT ON) +endif() + +# Define the option with the determined default value +option(ASAR_USE_THREADS "Run Asar in a new thread to alleviate stack usage problems" ${ASAR_USE_THREADS_DEFAULT}) + set (CMAKE_CXX_STANDARD 17) From 1d726a8c862d17474fc13272f5bc98cc07cabcb4 Mon Sep 17 00:00:00 2001 From: Jesus Lopez Date: Mon, 1 Jul 2024 09:35:02 -0700 Subject: [PATCH 2/2] build: fix macOS compile warnings --- .gitignore | 3 +++ src/asar/interface-cli.cpp | 3 +++ src/asar/libstr.h | 16 ++++++++-------- 3 files changed, 14 insertions(+), 8 deletions(-) diff --git a/.gitignore b/.gitignore index b2f731e6..4247b505 100644 --- a/.gitignore +++ b/.gitignore @@ -49,6 +49,9 @@ cmake_install.cmake Project.sln CMakeCache.txt +# Build files on macOS +Makefile + # Test folders tests_tmp_dll/ tests_tmp_app/ diff --git a/src/asar/interface-cli.cpp b/src/asar/interface-cli.cpp index fcc9d640..deffd474 100644 --- a/src/asar/interface-cli.cpp +++ b/src/asar/interface-cli.cpp @@ -494,7 +494,10 @@ int main(int argc, const char * argv[]) } if (!openrom(romname, false)) { + #pragma GCC diagnostic push + #pragma GCC diagnostic ignored "-Wformat-security" asar_throw_error(pass, error_type_null, openromerror); + #pragma GCC diagnostic pop pause(err); return 1; } diff --git a/src/asar/libstr.h b/src/asar/libstr.h index 80c98caf..1791342b 100644 --- a/src/asar/libstr.h +++ b/src/asar/libstr.h @@ -347,24 +347,24 @@ inline string hex(unsigned int value) { char buffer[64]; if(0); - else if (value<=0x000000FF) sprintf(buffer, "%.2X", value); - else if (value<=0x0000FFFF) sprintf(buffer, "%.4X", value); - else if (value<=0x00FFFFFF) sprintf(buffer, "%.6X", value); - else sprintf(buffer, "%.8X", value); + else if (value<=0x000000FF) snprintf(buffer, sizeof(buffer), "%.2X", value); + else if (value<=0x0000FFFF) snprintf(buffer, sizeof(buffer), "%.4X", value); + else if (value<=0x00FFFFFF) snprintf(buffer, sizeof(buffer), "%.6X", value); + else snprintf(buffer, sizeof(buffer), "%.8X", value); return buffer; } inline string hex(unsigned int value, int width) { char buffer[64]; - sprintf(buffer, "%.*X", width, value); + snprintf(buffer, sizeof(buffer), "%.*X", width, value); return buffer; } inline string dec(int value) { char buffer[64]; - sprintf(buffer, "%i", value); + snprintf(buffer, sizeof(buffer), "%i", value); return buffer; } @@ -375,7 +375,7 @@ inline string ftostr(double value) char rval[512]; // RPG Hacker: Ridiculously high precision, I know, but we're working with doubles // here and can afford it, so no need to waste any precision - sprintf(rval, "%.100f", value); + snprintf(rval, sizeof(rval), "%.100f", value); if (strchr(rval, '.'))//nuke useless zeroes { char * end=strrchr(rval, '\0')-1; @@ -398,7 +398,7 @@ inline string ftostrvar(double value, int precision) // see above char rval[512]; - sprintf(rval, "%.*f", clampedprecision, (double)value); + snprintf(rval, sizeof(rval), "%.*f", clampedprecision, (double)value); if (strchr(rval, '.'))//nuke useless zeroes { char * end = strrchr(rval, '\0') - 1;