1
Fork 0
mirror of https://github.com/SapphireServer/Sapphire.git synced 2025-05-06 02:37:47 +00:00

Removing C style casts round 1

Was told that though removing warnings was good for build, to avoid C
style casts.
This commit is contained in:
Reyli 2024-06-22 18:17:58 -05:00
parent 5c7d90ff84
commit ed156c4286
11 changed files with 40 additions and 39 deletions

View file

@ -292,7 +292,7 @@ namespace xiv::dat
DatBlockHeader block_header = extract< DatBlockHeader >( m_handle ); DatBlockHeader block_header = extract< DatBlockHeader >( m_handle );
// Resizing the vector to write directly into it // Resizing the vector to write directly into it
const uint32_t data_size = (uint32_t)o_data.size(); const uint32_t data_size = static_cast<uint32_t>(o_data.size());
o_data.resize( data_size + block_header.uncompressed_size ); o_data.resize( data_size + block_header.uncompressed_size );
// 32000 in compressed_size means it is not compressed so take uncompressed_size // 32000 in compressed_size means it is not compressed so take uncompressed_size
@ -308,7 +308,7 @@ namespace xiv::dat
m_handle.read( temp_buffer.data(), block_header.compressed_size ); m_handle.read( temp_buffer.data(), block_header.compressed_size );
utils::zlib::no_header_decompress( reinterpret_cast<uint8_t*>(temp_buffer.data()), utils::zlib::no_header_decompress( reinterpret_cast<uint8_t*>(temp_buffer.data()),
(uint32_t)temp_buffer.size(), static_cast<uint32_t>(temp_buffer.size()),
reinterpret_cast<uint8_t*>(o_data.data() + data_size), reinterpret_cast<uint8_t*>(o_data.data() + data_size),
block_header.uncompressed_size ); block_header.uncompressed_size );
} }

View file

@ -238,7 +238,7 @@ namespace xiv::exd
std::map< ExdRow, std::vector< Field >, exdRowSort > data; std::map< ExdRow, std::vector< Field >, exdRowSort > data;
// Iterates over all the cached ids // Iterates over all the cached ids
const uint32_t memberCount = (uint32_t)_exh->get_members().size(); const uint32_t memberCount = static_cast<uint32_t>(_exh->get_members().size());
for( auto& cacheEntry : _idCache ) for( auto& cacheEntry : _idCache )
{ {
std::vector< char > dataCpy = cacheEntry.second.file->get_data_sections().front(); std::vector< char > dataCpy = cacheEntry.second.file->get_data_sections().front();
@ -249,7 +249,7 @@ namespace xiv::exd
for( int32_t i = 0; i < cacheEntry.second.subRows; i++ ) for( int32_t i = 0; i < cacheEntry.second.subRows; i++ )
{ {
// Get the vector fields for the given record and preallocate it // Get the vector fields for the given record and preallocate it
ExdRow row = { cacheEntry.first, (uint8_t)i }; ExdRow row = { cacheEntry.first, static_cast<uint8_t>(i) };
auto& fields = data[ row ]; auto& fields = data[ row ];
fields.reserve( memberCount ); fields.reserve( memberCount );

View file

@ -273,8 +273,8 @@ namespace xiv::dat
std::string filenamePart = pathLower.substr( lastSlashPos + 1 ); std::string filenamePart = pathLower.substr( lastSlashPos + 1 );
// Get the crc32 values from zlib, to compensate the final XOR 0xFFFFFFFF that isnot done in the exe we just reXOR // Get the crc32 values from zlib, to compensate the final XOR 0xFFFFFFFF that isnot done in the exe we just reXOR
dirHash = crc32( 0, reinterpret_cast<const uint8_t*>( dirPart.data() ), (uInt)dirPart.size() ) ^ 0xFFFFFFFF; dirHash = crc32( 0, reinterpret_cast<const uint8_t*>( dirPart.data() ), static_cast<uInt>(dirPart.size()) ) ^ 0xFFFFFFFF;
filenameHash = crc32( 0, reinterpret_cast<const uint8_t*>( filenamePart.data() ), (uInt)filenamePart.size() ) ^ 0xFFFFFFFF; filenameHash = crc32( 0, reinterpret_cast<const uint8_t*>( filenamePart.data() ), static_cast<uInt>(filenamePart.size()) ) ^ 0xFFFFFFFF;
} }
void GameData::createCategory( uint32_t catNum ) void GameData::createCategory( uint32_t catNum )

View file

@ -101,7 +101,7 @@ namespace xiv::utils::crc32
void generate_hashes_1( std::string& i_format, const uint32_t i_first_index, std::vector< uint32_t >& o_hashes ) void generate_hashes_1( std::string& i_format, const uint32_t i_first_index, std::vector< uint32_t >& o_hashes )
{ {
char* str = const_cast<char*>(i_format.data()); char* str = const_cast<char*>(i_format.data());
const uint32_t str_size = (uint32_t)i_format.size(); const uint32_t str_size = static_cast<uint32_t>(i_format.size());
o_hashes.resize( 10000 ); o_hashes.resize( 10000 );
@ -130,7 +130,7 @@ namespace xiv::utils::crc32
std::vector< uint32_t >& o_hashes ) std::vector< uint32_t >& o_hashes )
{ {
char* str = const_cast<char*>(i_format.data()); char* str = const_cast<char*>(i_format.data());
const uint32_t str_size = (uint32_t)i_format.size(); const uint32_t str_size = static_cast<uint32_t>(i_format.size());
o_hashes.resize( 100000000 ); o_hashes.resize( 100000000 );

View file

@ -14,7 +14,7 @@ namespace xiv::utils::zlib
out.resize( out_size ); out.resize( out_size );
auto ret = compress2( reinterpret_cast<uint8_t*>(out.data()), &out_size, auto ret = compress2( reinterpret_cast<uint8_t*>(out.data()), &out_size,
reinterpret_cast<const uint8_t*>(in.data()), (uLong)in.size(), Z_BEST_COMPRESSION ); reinterpret_cast<const uint8_t*>(in.data()), static_cast<uLong>(in.size()), Z_BEST_COMPRESSION );
if( ret != Z_OK ) if( ret != Z_OK )
{ {

View file

@ -29,7 +29,8 @@ Mysql::Connection::Connection( std::shared_ptr< MySqlBase > pBase,
const std::string& password, const std::string& password,
const optionMap& options, const optionMap& options,
uint16_t port ) : uint16_t port ) :
m_pBase( pBase ) m_pBase( pBase ),
m_bConnected( false )
{ {
m_pRawCon = mysql_init( nullptr ); m_pRawCon = mysql_init( nullptr );
// Different mysql versions support different options, for now whatever was unsupporter here was commented out // Different mysql versions support different options, for now whatever was unsupporter here was commented out
@ -165,7 +166,7 @@ bool Mysql::Connection::getAutoCommit()
{ {
// TODO: should be replaced with wrapped sql query function once available // TODO: should be replaced with wrapped sql query function once available
std::string query("SELECT @@autocommit"); std::string query("SELECT @@autocommit");
auto res = mysql_real_query( m_pRawCon, query.c_str(), (unsigned long)query.length() ); auto res = mysql_real_query( m_pRawCon, query.c_str(), static_cast<unsigned long>(query.length()) );
if( res != 0 ) if( res != 0 )
throw std::runtime_error( "Query failed!" ); throw std::runtime_error( "Query failed!" );
@ -237,7 +238,7 @@ std::shared_ptr< Mysql::PreparedStatement > Mysql::Connection::prepareStatement(
if( !stmt ) if( !stmt )
throw std::runtime_error( "Could not init prepared statement: " + getError() ); throw std::runtime_error( "Could not init prepared statement: " + getError() );
if( mysql_stmt_prepare( stmt, sql.c_str(), (unsigned long)sql.size() ) ) if( mysql_stmt_prepare( stmt, sql.c_str(), static_cast<unsigned long>(sql.size()) ) )
throw std::runtime_error( "Could not prepare statement: " + getError() ); throw std::runtime_error( "Could not prepare statement: " + getError() );
return std::make_shared< PreparedStatement >( stmt, shared_from_this() ); return std::make_shared< PreparedStatement >( stmt, shared_from_this() );

View file

@ -18,7 +18,7 @@ struct LongDataSender
{ {
unsigned position; unsigned position;
MYSQL_STMT* m_pStmt; MYSQL_STMT* m_pStmt;
LongDataSender() LongDataSender() : position( 0 ), m_pStmt(nullptr)
{} {}
@ -77,9 +77,9 @@ struct LongDataSender
while( sent < str->length() ) while( sent < str->length() )
{ {
chunkSize = (uint32_t)( sent + MAX_SEND_LONGDATA_CHUNK > str->length() chunkSize = static_cast<uint32_t>(( sent + MAX_SEND_LONGDATA_CHUNK > str->length()
? str->length() - sent ? str->length() - sent
: MAX_SEND_LONGDATA_CHUNK ); : MAX_SEND_LONGDATA_CHUNK ));
if( mysql_stmt_send_long_data( m_pStmt, position, str->c_str() + sent, chunkSize ) ) if( mysql_stmt_send_long_data( m_pStmt, position, str->c_str() + sent, chunkSize ) )
{ {
@ -307,7 +307,7 @@ public:
} }
Mysql::PreparedStatement::PreparedStatement( MYSQL_STMT* pStmt, std::shared_ptr< Mysql::Connection > pConn ) Mysql::PreparedStatement::PreparedStatement( MYSQL_STMT* pStmt, std::shared_ptr< Mysql::Connection > pConn )
: Statement( pConn ) : Statement( pConn ), m_paramCount( 0 ), resultSetConcurrency ( 0 ), resultSetType( 0 ), warningsCount( 0 )
{ {
m_pStmt = pStmt; m_pStmt = pStmt;
m_pConnection = pConn; m_pConnection = pConn;

View file

@ -10,14 +10,14 @@ std::shared_ptr< Mysql::Connection > Mysql::Statement::getConnection()
} }
Mysql::Statement::Statement( std::shared_ptr< Mysql::Connection > conn ) : Mysql::Statement::Statement( std::shared_ptr< Mysql::Connection > conn ) :
m_pConnection( conn ) m_pConnection( conn ), m_lastUpdateCount( 0 ), m_warningsCount( 0 )
{ {
} }
void Mysql::Statement::doQuery( const std::string &q ) void Mysql::Statement::doQuery( const std::string &q )
{ {
mysql_real_query( m_pConnection->getRawCon(), q.c_str(), (unsigned long)q.length() ); mysql_real_query( m_pConnection->getRawCon(), q.c_str(), static_cast<unsigned long>(q.length()) );
if( errNo() ) if( errNo() )
throw std::runtime_error( m_pConnection->getError() ); throw std::runtime_error( m_pConnection->getError() );

View file

@ -114,7 +114,7 @@ int SapphireApi::createCharacter( const uint32_t accountId, const std::string& n
const char* ptr = infoJson.c_str() + 50; const char* ptr = infoJson.c_str() + 50;
std::string lookPart( ptr ); std::string lookPart( ptr );
int32_t pos = (int32_t)lookPart.find_first_of( "]" ); int32_t pos = static_cast<int32_t>(lookPart.find_first_of( "]" ));
if( pos != std::string::npos ) if( pos != std::string::npos )
{ {
lookPart = lookPart.substr( 0, pos + 1 ); lookPart = lookPart.substr( 0, pos + 1 );

View file

@ -242,7 +242,7 @@ namespace SimpleWeb {
std::shared_ptr<Request> request(new Request(*socket)); std::shared_ptr<Request> request(new Request(*socket));
//Set timeout on the following asio::async-read or write function //Set timeout on the following asio::async-read or write function
auto timer=this->get_timeout_timer(socket, (long)config.timeout_request); auto timer=this->get_timeout_timer(socket, static_cast<long>(config.timeout_request));
asio::async_read_until(*socket, request->streambuf, "\r\n\r\n", asio::async_read_until(*socket, request->streambuf, "\r\n\r\n",
[this, socket, request, timer](const std::error_code& ec, size_t bytes_transferred) { [this, socket, request, timer](const std::error_code& ec, size_t bytes_transferred) {
@ -272,7 +272,7 @@ namespace SimpleWeb {
} }
if(content_length>num_additional_bytes) { if(content_length>num_additional_bytes) {
//Set timeout on the following asio::async-read or write function //Set timeout on the following asio::async-read or write function
auto timer=this->get_timeout_timer(socket, (long)config.timeout_content); auto timer=this->get_timeout_timer(socket, static_cast<long>(config.timeout_content));
asio::async_read(*socket, request->streambuf, asio::async_read(*socket, request->streambuf,
asio::transfer_exactly(static_cast< size_t >(content_length-num_additional_bytes)), asio::transfer_exactly(static_cast< size_t >(content_length-num_additional_bytes)),
[this, socket, request, timer] [this, socket, request, timer]
@ -368,7 +368,7 @@ namespace SimpleWeb {
std::function<void(std::shared_ptr<typename ServerBase<socket_type>::Response>, std::function<void(std::shared_ptr<typename ServerBase<socket_type>::Response>,
std::shared_ptr<typename ServerBase<socket_type>::Request>)>& resource_function) { std::shared_ptr<typename ServerBase<socket_type>::Request>)>& resource_function) {
//Set timeout on the following asio::async-read or write function //Set timeout on the following asio::async-read or write function
auto timer=this->get_timeout_timer(socket, (long)config.timeout_content); auto timer=this->get_timeout_timer(socket, static_cast<long>(config.timeout_content));
auto response=std::shared_ptr<Response>(new Response(socket), [this, request, timer](Response *response_ptr) { auto response=std::shared_ptr<Response>(new Response(socket), [this, request, timer](Response *response_ptr) {
auto response=std::shared_ptr<Response>(response_ptr); auto response=std::shared_ptr<Response>(response_ptr);

View file

@ -26,32 +26,32 @@ namespace Sapphire::World::Manager
struct LandCacheEntry struct LandCacheEntry
{ {
// land table // land table
uint64_t m_landSetId; uint64_t m_landSetId{};
uint16_t m_landId; uint16_t m_landId{};
Common::LandType m_type; Common::LandType m_type{};
Common::HouseSize m_size; Common::HouseSize m_size{};
Common::HouseStatus m_status; Common::HouseStatus m_status{};
uint64_t m_currentPrice; uint64_t m_currentPrice{};
uint64_t m_updateTime; uint64_t m_updateTime{};
uint64_t m_ownerId; uint64_t m_ownerId{};
uint64_t m_houseId; uint64_t m_houseId{};
// house table // house table
std::string m_estateWelcome; std::string m_estateWelcome{};
std::string m_estateComment; std::string m_estateComment{};
std::string m_estateName; std::string m_estateName{};
bool m_hasAetheryte; bool m_hasAetheryte{};
uint64_t m_buildTime; uint64_t m_buildTime{};
uint64_t m_endorsements; uint64_t m_endorsements{};
uint16_t m_maxPlacedExternalItems; uint16_t m_maxPlacedExternalItems{};
uint16_t m_maxPlacedInternalItems; uint16_t m_maxPlacedInternalItems{};
}; };
/*! /*!