From c5005719c120b2eddd7a4456b1cffeb4a860cac8 Mon Sep 17 00:00:00 2001 From: David Li Date: Mon, 30 Dec 2024 20:24:51 -0800 Subject: [PATCH] fix: Compiler warnings, OSX+Android Build Signed-off-by: David Li --- .github/workflows/android.yml | 2 +- .github/workflows/osx.yml | 2 +- src/compress.cpp | 2 +- src/world.cpp | 21 +++++++++++---------- 4 files changed, 14 insertions(+), 13 deletions(-) diff --git a/.github/workflows/android.yml b/.github/workflows/android.yml index 90297c45ac73..6da29c42a6ea 100644 --- a/.github/workflows/android.yml +++ b/.github/workflows/android.yml @@ -42,7 +42,7 @@ jobs: - name: Setup build and dependencies run: | sudo apt-get update - sudo apt-get install gettext + sudo apt-get install gettext libsqlite3-dev zlib1g-dev - name: Build working-directory: ./android diff --git a/.github/workflows/osx.yml b/.github/workflows/osx.yml index 9b0160a76fba..9bd25b5e02ec 100644 --- a/.github/workflows/osx.yml +++ b/.github/workflows/osx.yml @@ -80,7 +80,7 @@ jobs: - name: Install build dependencies run: | - HOMEBREW_NO_AUTO_UPDATE=yes HOMEBREW_NO_INSTALL_CLEANUP=yes brew install sdl2 sdl2_image sdl2_ttf sdl2_mixer gettext ccache parallel llvm astyle + HOMEBREW_NO_AUTO_UPDATE=yes HOMEBREW_NO_INSTALL_CLEANUP=yes brew install sdl2 sdl2_image sdl2_ttf sdl2_mixer gettext ccache parallel llvm astyle sqlite3 zlib python3 -m venv ./venv source ./venv/bin/activate pip3 install mac_alias==2.2.0 dmgbuild==1.6.1 biplist polib luaparser diff --git a/src/compress.cpp b/src/compress.cpp index e8d8ddaa3a7e..f9156a2ab42f 100644 --- a/src/compress.cpp +++ b/src/compress.cpp @@ -29,7 +29,7 @@ void zlib_compress( const std::string &input, std::vector &output ) void zlib_decompress( const void *compressed_data, int compressed_size, std::string &output ) { // We need to guess at the decompressed size - we expect things to compress fairly well. - uLongf decompressedSize = compressed_size * 8; + uLongf decompressedSize = static_cast( compressed_size ) * 8; output.resize( decompressedSize ); int result; diff --git a/src/world.cpp b/src/world.cpp index 04b732916196..10cbfd7de6dc 100644 --- a/src/world.cpp +++ b/src/world.cpp @@ -18,19 +18,19 @@ #include "compress.h" #define dbg(x) DebugLogFL((x),DC::Main) - static sqlite3 *open_db( const std::string &path ) { sqlite3 *db = nullptr; int ret; - if( SQLITE_OK != ( ret = sqlite3_initialize() ) ) { + ret = sqlite3_initialize(); + if( ret != SQLITE_OK ) { dbg( DL::Error ) << "Failed to initialize sqlite3 (Error " << ret << ")"; throw std::runtime_error( "Failed to initialize sqlite3" ); } - if( SQLITE_OK != ( ret = sqlite3_open_v2( path.c_str(), &db, - SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE, NULL ) ) ) { + ret = sqlite3_open_v2( path.c_str(), &db, SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE, NULL ); + if( ret != SQLITE_OK ) { dbg( DL::Error ) << "Failed to open db" << path << " (Error " << ret << ")"; throw std::runtime_error( "Failed to open db" ); } @@ -45,7 +45,8 @@ static sqlite3 *open_db( const std::string &path ) )sql"; char *sqlErrMsg = 0; - if( SQLITE_OK != ( ret = sqlite3_exec( db, sql, NULL, NULL, &sqlErrMsg ) ) ) { + ret = sqlite3_exec( db, sql, NULL, NULL, &sqlErrMsg ); + if( ret != SQLITE_OK ) { dbg( DL::Error ) << "Failed to init db" << path << " (" << sqlErrMsg << ")"; throw std::runtime_error( "Failed to open db" ); } @@ -569,7 +570,7 @@ bool world::read_overmap( const point_abs_om &p, file_read_fn reader ) const bool world::read_overmap_player_visibility( const point_abs_om &p, file_read_fn reader ) { if( info->world_save_format == save_format::V2_COMPRESSED_SQLITE3 ) { - auto playerdb = get_player_db(); + sqlite3 *playerdb = get_player_db(); return read_from_db( playerdb, overmap_player_filename( p ), reader, true ); } else { return read_from_player_file( overmap_player_filename( p ), reader, true ); @@ -589,7 +590,7 @@ bool world::write_overmap( const point_abs_om &p, file_write_fn writer ) const bool world::write_overmap_player_visibility( const point_abs_om &p, file_write_fn writer ) { if( info->world_save_format == save_format::V2_COMPRESSED_SQLITE3 ) { - auto playerdb = get_player_db(); + sqlite3 *playerdb = get_player_db(); write_to_db( playerdb, overmap_player_filename( p ), writer ); return true; } else { @@ -608,7 +609,7 @@ static std::string get_mm_filename( const tripoint &p ) bool world::read_player_mm_quad( const tripoint &p, file_read_json_fn reader ) { if( info->world_save_format == save_format::V2_COMPRESSED_SQLITE3 ) { - auto playerdb = get_player_db(); + sqlite3 *playerdb = get_player_db(); return read_from_db_json( playerdb, get_mm_filename( p ), reader, true ); } else { return read_from_player_file_json( ".mm1/" + get_mm_filename( p ), reader, true ); @@ -618,7 +619,7 @@ bool world::read_player_mm_quad( const tripoint &p, file_read_json_fn reader ) bool world::write_player_mm_quad( const tripoint &p, file_write_fn writer ) { if( info->world_save_format == save_format::V2_COMPRESSED_SQLITE3 ) { - auto playerdb = get_player_db(); + sqlite3 *playerdb = get_player_db(); write_to_db( playerdb, get_mm_filename( p ), writer ); return true; } else { @@ -709,7 +710,7 @@ bool world::read_from_file_json( const std::string &path, file_read_json_fn read return ::read_from_file_json( info->folder_path() + "/" + path, reader, optional ); } -void replaceBackslashes( std::string &input ) +static void replaceBackslashes( std::string &input ) { std::size_t pos = 0; while( ( pos = input.find( '\\', pos ) ) != std::string::npos ) {