Skip to content

Commit

Permalink
Fixed type-casting-related warnings.
Browse files Browse the repository at this point in the history
  • Loading branch information
madmaxoft committed Aug 24, 2016
1 parent 6c57cc3 commit d2e8643
Show file tree
Hide file tree
Showing 42 changed files with 145 additions and 211 deletions.
9 changes: 1 addition & 8 deletions Tools/GrownBiomeGenVisualiser/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,9 @@ set_flags()
set_lib_flags()
enable_profile()

if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
add_flags_cxx("-Wno-error=sign-conversion -Wno-error=conversion -Wno-error=shorten-64-to-32")
add_flags_cxx("-Wno-error=old-style-cast")
if ("${CLANG_VERSION}" VERSION_GREATER 3.5)
add_flags_cxx("-Wno-error=keyword-macro")
endif()
endif()

# Set include paths to the used libraries:
include_directories("../../lib")
include_directories(SYSTEM "../../lib")
include_directories("../../src")


Expand Down
10 changes: 1 addition & 9 deletions Tools/MCADefrag/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,8 @@ set_flags()
set_lib_flags()
enable_profile()

if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
add_flags_cxx("-Wno-error=sign-conversion -Wno-error=conversion -Wno-error=shorten-64-to-32")
add_flags_cxx("-Wno-error=old-style-cast")
if ("${CLANG_VERSION}" VERSION_GREATER 3.5)
add_flags_cxx("-Wno-error=keyword-macro")
endif()
endif()

# Set include paths to the used libraries:
include_directories("../../lib")
include_directories(SYSTEM "../../lib")
include_directories("../../src")


Expand Down
6 changes: 0 additions & 6 deletions Tools/MCADefrag/Globals.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,6 @@
// TODO: Can GCC explicitly mark classes as abstract (no instances can be created)?
#define abstract

// TODO: Can GCC mark virtual methods as overriding (forcing them to have a virtual function of the same signature in the base class)
#define override

#define OBSOLETE __attribute__((deprecated))

#define ALIGN_8 __attribute__((aligned(8)))
Expand All @@ -64,9 +61,6 @@
// Explicitly mark classes as abstract (no instances can be created)
#define abstract
// Mark virtual methods as overriding (forcing them to have a virtual function of the same signature in the base class)
#define override
// Mark functions as obsolete, so that their usage results in a compile-time warning
#define OBSOLETE
Expand Down
35 changes: 20 additions & 15 deletions Tools/MCADefrag/MCADefrag.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,10 @@ bool cMCADefrag::cThread::ReadChunk(cFile & a_File, const Byte * a_LocationRaw)
int SizeInSectors = a_LocationRaw[3] * (4 KiB);
if (a_File.Seek(SectorNum * (4 KiB)) < 0)
{
LOGWARNING("Failed to seek to chunk data - file pos %llu (%d KiB, %.02f MiB)!", (Int64)SectorNum * (4 KiB), SectorNum * 4, ((double)SectorNum) / 256);
LOGWARNING("Failed to seek to chunk data - file pos %llu (%d KiB, %.02f MiB)!",
static_cast<Int64>(SectorNum) * (4 KiB), SectorNum * 4,
static_cast<double>(SectorNum) / 256
);
return false;
}

Expand All @@ -276,7 +279,7 @@ bool cMCADefrag::cThread::ReadChunk(cFile & a_File, const Byte * a_LocationRaw)
}

// Read the data:
if (a_File.Read(m_CompressedChunkData, m_CompressedChunkDataSize) != m_CompressedChunkDataSize)
if (a_File.Read(m_CompressedChunkData, static_cast<size_t>(m_CompressedChunkDataSize)) != m_CompressedChunkDataSize)
{
LOGWARNING("Failed to read chunk data!");
return false;
Expand Down Expand Up @@ -311,15 +314,15 @@ bool cMCADefrag::cThread::WriteChunk(cFile & a_File, Byte * a_LocationRaw)
}

// Update the Location:
a_LocationRaw[0] = m_CurrentSectorOut >> 16;
a_LocationRaw[0] = static_cast<Byte>(m_CurrentSectorOut >> 16);
a_LocationRaw[1] = (m_CurrentSectorOut >> 8) & 0xff;
a_LocationRaw[2] = m_CurrentSectorOut & 0xff;
a_LocationRaw[3] = (m_CompressedChunkDataSize + (4 KiB) + 3) / (4 KiB); // +3 because the m_CompressedChunkDataSize doesn't include the exact-length
a_LocationRaw[3] = static_cast<Byte>((m_CompressedChunkDataSize + (4 KiB) + 3) / (4 KiB)); // +3 because the m_CompressedChunkDataSize doesn't include the exact-length
m_CurrentSectorOut += a_LocationRaw[3];

// Write the data length:
Byte Buf[4];
Buf[0] = m_CompressedChunkDataSize >> 24;
Buf[0] = static_cast<Byte>(m_CompressedChunkDataSize >> 24);
Buf[1] = (m_CompressedChunkDataSize >> 16) & 0xff;
Buf[2] = (m_CompressedChunkDataSize >> 8) & 0xff;
Buf[3] = m_CompressedChunkDataSize & 0xff;
Expand All @@ -330,7 +333,7 @@ bool cMCADefrag::cThread::WriteChunk(cFile & a_File, Byte * a_LocationRaw)
}

// Write the data:
if (a_File.Write(m_CompressedChunkData, m_CompressedChunkDataSize) != m_CompressedChunkDataSize)
if (a_File.Write(m_CompressedChunkData, static_cast<size_t>(m_CompressedChunkDataSize)) != m_CompressedChunkDataSize)
{
LOGWARNING("Failed to write chunk data!");
return false;
Expand All @@ -339,7 +342,7 @@ bool cMCADefrag::cThread::WriteChunk(cFile & a_File, Byte * a_LocationRaw)
// Pad onto the next sector:
int NumPadding = a_LocationRaw[3] * 4096 - (m_CompressedChunkDataSize + 4);
ASSERT(NumPadding >= 0);
if ((NumPadding > 0) && (a_File.Write(g_Zeroes, NumPadding) != NumPadding))
if ((NumPadding > 0) && (a_File.Write(g_Zeroes, static_cast<size_t>(NumPadding)) != NumPadding))
{
LOGWARNING("Failed to write padding");
return false;
Expand Down Expand Up @@ -382,22 +385,23 @@ bool cMCADefrag::cThread::UncompressChunkZlib(void)
{
// Uncompress the data:
z_stream strm;
strm.zalloc = (alloc_func)NULL;
strm.zfree = (free_func)NULL;
strm.opaque = NULL;
strm.zalloc = nullptr;
strm.zfree = nullptr;
strm.opaque = nullptr;
inflateInit(&strm);
strm.next_out = m_RawChunkData;
strm.avail_out = sizeof(m_RawChunkData);
strm.next_in = m_CompressedChunkData + 1; // The first byte is the compression method, skip it
strm.avail_in = m_CompressedChunkDataSize;
strm.avail_in = static_cast<uInt>(m_CompressedChunkDataSize);
int res = inflate(&strm, Z_FINISH);
inflateEnd(&strm);
if (res != Z_STREAM_END)
{
LOGWARNING("Failed to uncompress chunk data: %s", strm.msg);
return false;
}
m_RawChunkDataSize = strm.total_out;
ASSERT(strm.total_out < static_cast<uLong>(std::numeric_limits<int>::max()));
m_RawChunkDataSize = static_cast<int>(strm.total_out);

return true;
}
Expand All @@ -409,22 +413,23 @@ bool cMCADefrag::cThread::UncompressChunkZlib(void)
bool cMCADefrag::cThread::CompressChunk(void)
{
// Check that the compressed data can fit:
uLongf CompressedSize = compressBound(m_RawChunkDataSize);
uLongf CompressedSize = compressBound(static_cast<uLong>(m_RawChunkDataSize));
if (CompressedSize > sizeof(m_CompressedChunkData))
{
LOGINFO("Too much data for the internal compression buffer!");
return false;
}

// Compress the data using the highest compression factor:
int errorcode = compress2(m_CompressedChunkData + 1, &CompressedSize, m_RawChunkData, m_RawChunkDataSize, Z_BEST_COMPRESSION);
int errorcode = compress2(m_CompressedChunkData + 1, &CompressedSize, m_RawChunkData, static_cast<uLong>(m_RawChunkDataSize), Z_BEST_COMPRESSION);
if (errorcode != Z_OK)
{
LOGINFO("Recompression failed: %d", errorcode);
return false;
}
m_CompressedChunkData[0] = COMPRESSION_ZLIB;
m_CompressedChunkDataSize = CompressedSize + 1;
ASSERT(CompressedSize < static_cast<uLong>(std::numeric_limits<int>::max()));
m_CompressedChunkDataSize = static_cast<int>(CompressedSize + 1);
return true;
}

Expand Down
12 changes: 2 additions & 10 deletions Tools/ProtoProxy/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,10 @@ set_lib_flags()


# Set include paths to the used libraries:
include_directories("../../lib")
include_directories("../../lib/polarssl/include")
include_directories(SYSTEM "../../lib")
include_directories(SYSTEM "../../lib/polarssl/include")
include_directories("../../src")

if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
add_flags_cxx("-Wno-error=sign-conversion -Wno-error=conversion -Wno-error=shorten-64-to-32")
add_flags_cxx("-Wno-error=old-style-cast")
if ("${CLANG_VERSION}" VERSION_GREATER 3.5)
add_flags_cxx("-Wno-error=keyword-macro")
endif()
endif()

function(flatten_files arg1)
set(res "")
foreach(f ${${arg1}})
Expand Down
14 changes: 7 additions & 7 deletions Tools/ProtoProxy/Connection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ AString PrintableAbsIntTriplet(int a_X, int a_Y, int a_Z, double a_Divisor)
{
return Printf("<%d, %d, %d> ~ {%.02f, %.02f, %.02f}",
a_X, a_Y, a_Z,
(double)a_X / a_Divisor, (double)a_Y / a_Divisor, (double)a_Z / a_Divisor
static_cast<double>(a_X) / a_Divisor, static_cast<double>(a_Y) / a_Divisor, static_cast<double>(a_Z) / a_Divisor
);
}

Expand Down Expand Up @@ -212,7 +212,7 @@ cConnection::cConnection(SOCKET a_ClientSocket, cServer & a_Server) :
mkdir("Logs", 0777);
#endif

Printf(m_LogNameBase, "Logs/Log_%d_%d", (int)time(NULL), a_ClientSocket);
Printf(m_LogNameBase, "Logs/Log_%d_%d", static_cast<int>(time(nullptr)), static_cast<int>(a_ClientSocket));
AString fnam(m_LogNameBase);
fnam.append(".log");
#ifdef _WIN32
Expand Down Expand Up @@ -352,7 +352,7 @@ bool cConnection::ConnectToServer(void)
localhost.sin_family = AF_INET;
localhost.sin_port = htons(m_Server.GetConnectPort());
localhost.sin_addr.s_addr = htonl(0x7f000001); // localhost
if (connect(m_ServerSocket, (sockaddr *)&localhost, sizeof(localhost)) != 0)
if (connect(m_ServerSocket, reinterpret_cast<const sockaddr *>(&localhost), sizeof(localhost)) != 0)
{
printf("connection to server failed: %d\n", SocketError);
return false;
Expand Down Expand Up @@ -485,13 +485,13 @@ bool cConnection::SendData(SOCKET a_Socket, cByteBuffer & a_Data, const char * a
bool cConnection::SendEncryptedData(SOCKET a_Socket, cAesCfb128Encryptor & a_Encryptor, const char * a_Data, size_t a_Size, const char * a_Peer)
{
DataLog(a_Data, a_Size, "Encrypting %d bytes to %s", a_Size, a_Peer);
const Byte * Data = (const Byte *)a_Data;
const Byte * Data = reinterpret_cast<const Byte *>(a_Data);
while (a_Size > 0)
{
Byte Buffer[64 KiB];
size_t NumBytes = (a_Size > sizeof(Buffer)) ? sizeof(Buffer) : a_Size;
a_Encryptor.ProcessData(Buffer, Data, NumBytes);
bool res = SendData(a_Socket, (const char *)Buffer, NumBytes, a_Peer);
bool res = SendData(a_Socket, reinterpret_cast<const char *>(Buffer), NumBytes, a_Peer);
if (!res)
{
return false;
Expand Down Expand Up @@ -1313,7 +1313,7 @@ bool cConnection::HandleServerLoginEncryptionKeyRequest(void)
}
Log("Got PACKET_ENCRYPTION_KEY_REQUEST from the SERVER:");
Log(" ServerID = %s", ServerID.c_str());
DataLog(PublicKey.data(), PublicKey.size(), " Public key (%u bytes)", (unsigned)PublicKey.size());
DataLog(PublicKey.data(), PublicKey.size(), " Public key (%u bytes)", static_cast<unsigned>(PublicKey.size()));

// Reply to the server:
SendEncryptionKeyResponse(PublicKey, Nonce);
Expand Down Expand Up @@ -2942,7 +2942,7 @@ void cConnection::SendEncryptionKeyResponse(const AString & a_ServerPublicKey, c

// Encrypt the nonce:
Byte EncryptedNonce[128];
res = PubKey.Encrypt((const Byte *)a_Nonce.data(), a_Nonce.size(), EncryptedNonce, sizeof(EncryptedNonce));
res = PubKey.Encrypt(reinterpret_cast<const Byte *>(a_Nonce.data()), a_Nonce.size(), EncryptedNonce, sizeof(EncryptedNonce));
if (res < 0)
{
Log("Nonce encryption failed: %d (0x%x)", res, res);
Expand Down
6 changes: 0 additions & 6 deletions Tools/ProtoProxy/Globals.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,6 @@
// TODO: Can GCC explicitly mark classes as abstract (no instances can be created)?
#define abstract

// TODO: Can GCC mark virtual methods as overriding (forcing them to have a virtual function of the same signature in the base class)
#define override

#define OBSOLETE __attribute__((deprecated))

#define ALIGN_8 __attribute__((aligned(8)))
Expand All @@ -52,9 +49,6 @@
// Explicitly mark classes as abstract (no instances can be created)
#define abstract
// Mark virtual methods as overriding (forcing them to have a virtual function of the same signature in the base class)
#define override
// Mark functions as obsolete, so that their usage results in a compile-time warning
#define OBSOLETE
Expand Down
23 changes: 19 additions & 4 deletions Tools/ProtoProxy/ProtoProxy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,29 @@ int main(int argc, char ** argv)

cLogger::InitiateMultithreading();

int ListenPort = (argc > 1) ? atoi(argv[1]) : 25564;
int ConnectPort = (argc > 2) ? atoi(argv[2]) : 25565;
printf("Initializing ProtoProxy. Listen port %d, connect port %d.\n", ListenPort, ConnectPort);
UInt16 ListenPort = 25564;
UInt16 ConnectPort = 25565;
if (argc > 1)
{
if (!StringToInteger(argv[1], ListenPort))
{
LOGERROR("Invalid argument 1, expected port number, got \"%s\". Aborting.", argv[1]);
return 1;
}
if (argc > 2)
{
if (!StringToInteger(argv[2], ConnectPort))
{
LOGERROR("Invalid argument 2, expected port number, got \"%s\". Aborting.", argv[2]);
return 2;
}
}
}
cServer Server;
int res = Server.Init(ListenPort, ConnectPort);
if (res != 0)
{
printf("Server initialization failed: %d", res);
LOGERROR("Server initialization failed: %d", res);
return res;
}

Expand Down
8 changes: 4 additions & 4 deletions Tools/ProtoProxy/Server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ cServer::cServer(void)



int cServer::Init(short a_ListenPort, short a_ConnectPort)
int cServer::Init(UInt16 a_ListenPort, UInt16 a_ConnectPort)
{
m_ConnectPort = a_ConnectPort;

Expand Down Expand Up @@ -50,7 +50,7 @@ int cServer::Init(short a_ListenPort, short a_ConnectPort)
local.sin_family = AF_INET;
local.sin_addr.s_addr = INADDR_ANY; // All interfaces
local.sin_port = htons(a_ListenPort);
if (bind(m_ListenSocket, (sockaddr *)&local, sizeof(local)) != 0)
if (bind(m_ListenSocket, reinterpret_cast<const sockaddr *>(&local), sizeof(local)) != 0)
{
#ifdef _WIN32
int err = WSAGetLastError();
Expand All @@ -70,7 +70,7 @@ int cServer::Init(short a_ListenPort, short a_ConnectPort)
printf("Failed to listen on socket: %d\n", err);
return err;
}
LOGINFO("Listening on port %d, connecting to localhost:%d", a_ListenPort, a_ConnectPort);
LOGINFO("Listening for client connections on port %d, connecting to server at localhost:%d", a_ListenPort, a_ConnectPort);

LOGINFO("Generating protocol encryption keypair...");
m_PrivateKey.Generate();
Expand All @@ -91,7 +91,7 @@ void cServer::Run(void)
sockaddr_in Addr;
memset(&Addr, 0, sizeof(Addr));
socklen_t AddrSize = sizeof(Addr);
SOCKET client = accept(m_ListenSocket, (sockaddr *)&Addr, &AddrSize);
SOCKET client = accept(m_ListenSocket, reinterpret_cast<sockaddr *>(&Addr), &AddrSize);
if (client == INVALID_SOCKET)
{
printf("accept returned an error: %d; bailing out.\n", SocketError);
Expand Down
2 changes: 1 addition & 1 deletion Tools/ProtoProxy/Server.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class cServer
public:
cServer(void);

int Init(short a_ListenPort, short a_ConnectPort);
int Init(UInt16 a_ListenPort, UInt16 a_ConnectPort);
void Run(void);

cRsaPrivateKey & GetPrivateKey(void) { return m_PrivateKey; }
Expand Down
6 changes: 3 additions & 3 deletions src/BlockArea.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -632,9 +632,9 @@ void cBlockArea::DumpToRawFile(const AString & a_FileName)
LOGWARNING("cBlockArea: Cannot open file \"%s\" for raw dump", a_FileName.c_str());
return;
}
UInt32 SizeX = ntohl(m_Size.x);
UInt32 SizeY = ntohl(m_Size.y);
UInt32 SizeZ = ntohl(m_Size.z);
UInt32 SizeX = ntohl(static_cast<UInt32>(m_Size.x));
UInt32 SizeY = ntohl(static_cast<UInt32>(m_Size.y));
UInt32 SizeZ = ntohl(static_cast<UInt32>(m_Size.z));
f.Write(&SizeX, 4);
f.Write(&SizeY, 4);
f.Write(&SizeZ, 4);
Expand Down
3 changes: 1 addition & 2 deletions src/BlockEntities/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,7 @@ SET (HDRS
)

if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
set_source_files_properties(BeaconEntity.cpp PROPERTIES COMPILE_FLAGS "-Wno-error=conversion -Wno-error=switch-enum")
set_source_files_properties(NoteEntity.cpp PROPERTIES COMPILE_FLAGS "-Wno-error=conversion -Wno-error=sign-conversion")
set_source_files_properties(BeaconEntity.cpp PROPERTIES COMPILE_FLAGS "-Wno-error=switch-enum")
endif()

if(NOT MSVC)
Expand Down
Loading

0 comments on commit d2e8643

Please sign in to comment.