Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Compiler Warnings #645

Draft
wants to merge 31 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
3523755
compile launcher with W4
ASpoonPlaysGames Jan 5, 2024
a903638
fix C4267 in main.cpp
ASpoonPlaysGames Jan 5, 2024
58d9c6e
fix C4706
ASpoonPlaysGames Jan 5, 2024
62d5556
disable 4273 because idk how to fix it
ASpoonPlaysGames Jan 5, 2024
497f967
remove unimplemented function
ASpoonPlaysGames Jan 5, 2024
afcba0d
compile Northstar with W4
ASpoonPlaysGames Jan 5, 2024
8fe9fc7
fix C4267
ASpoonPlaysGames Jan 5, 2024
0470021
fix C4100
ASpoonPlaysGames Jan 5, 2024
4e0f621
compile wsock with W4
ASpoonPlaysGames Jan 20, 2024
f2a7971
fix C4267
ASpoonPlaysGames Jan 20, 2024
67a724a
suppress C4565
ASpoonPlaysGames Jan 20, 2024
a6b5ed6
fix C4201
ASpoonPlaysGames Jan 20, 2024
dd5fe6a
fix C5054 (preport change from https://github.com/Tencent/rapidjson/p…
ASpoonPlaysGames Jan 20, 2024
b7fabf9
fix C4245
ASpoonPlaysGames Jan 20, 2024
c65a5df
fix various warnings
ASpoonPlaysGames Jan 21, 2024
6d80d16
fix some C4706
ASpoonPlaysGames Jan 21, 2024
b66a36e
fix more stuff
ASpoonPlaysGames Jan 21, 2024
184d48a
a bit more stuff
ASpoonPlaysGames Jan 21, 2024
25ecd83
Merge branch 'R2Northstar:main' into warnings
ASpoonPlaysGames Jan 21, 2024
19505fd
suppress warnings in the cpp as well as the h
ASpoonPlaysGames Jan 21, 2024
687690c
fix C4099 in Rapidjson. Preports the following:
ASpoonPlaysGames Jan 21, 2024
9b5f24a
i forgot to commit things
ASpoonPlaysGames Jan 21, 2024
3cf4c53
why are there so many
ASpoonPlaysGames Jan 21, 2024
39d2fc2
formatting
ASpoonPlaysGames Jan 21, 2024
7004c7c
formatting
ASpoonPlaysGames Jan 21, 2024
cf96257
i literally didnt change this what the hell
ASpoonPlaysGames Jan 21, 2024
9fc9ed3
wait is this all of them, did i do it?
ASpoonPlaysGames Jan 21, 2024
d33639d
Merge branch 'main' into warnings
ASpoonPlaysGames Jan 21, 2024
88d62dc
Merge branch 'main' into warnings
ASpoonPlaysGames Jan 27, 2024
ba14192
fix conflicts
ASpoonPlaysGames Feb 14, 2024
0b67ecc
again
ASpoonPlaysGames Feb 14, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions primedev/Launcher.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,15 @@ set_target_properties(
NorthstarLauncher PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${NS_BINARY_DIR} LINK_FLAGS
"/MANIFEST:NO /DEBUG /STACK:8000000"
)

if(MSVC)
target_compile_options(NorthstarLauncher PRIVATE /W4 /WX)
else()
target_compile_options(
NorthstarLauncher
PRIVATE -Wall
-Wextra
-Wpedantic
-Werror
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please do not make warnings fatal by default.
what is and isn't a warning can change a lot between compiler versions causing phantom errors that only appear in the CI but not locally or the other way around.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

honestly i dont think this PR is ever gonna get merged, since it should really get split up into a bunch more PRs, so I think that it's ok to have fatal warnings on this branch specifically, so that it sort of "proves" that i didnt miss any.

)
endif()
12 changes: 12 additions & 0 deletions primedev/Northstar.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -201,3 +201,15 @@ set_target_properties(
OUTPUT_NAME Northstar
LINK_FLAGS "/MANIFEST:NO /DEBUG"
)

if(MSVC)
target_compile_options(NorthstarDLL PRIVATE /W4 /WX)
else()
target_compile_options(
NorthstarDLL
PRIVATE -Wall
-Wextra
-Wpedantic
-Werror
)
endif()
13 changes: 13 additions & 0 deletions primedev/WSockProxy.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -47,3 +47,16 @@ set_target_properties(
OUTPUT_NAME wsock32
LINK_FLAGS "/MANIFEST:NO /DEBUG"
)

# COMPILE_LANGUAGE is used here because of the ASM file
if(MSVC)
target_compile_options(loader_wsock32_proxy PRIVATE $<$<COMPILE_LANGUAGE:CXX>:/W4 /WX>)
else()
target_compile_options(
loader_wsock32_proxy
PRIVATE $<$<COMPILE_LANGUAGE:CXX>:-Wall
-Wextra
-Wpedantic
-Werror>
)
endif()
12 changes: 6 additions & 6 deletions primedev/client/audio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -207,14 +207,14 @@ EventOverrideData::EventOverrideData(const std::string& data, const fs::path& pa

// Allocate enough memory for the file.
// blank out the memory for now, then read it later
uint8_t* data = new uint8_t[fileSize];
memcpy(data, EMPTY_WAVE, sizeof(EMPTY_WAVE));
Samples.push_back({fileSize, std::unique_ptr<uint8_t[]>(data)});
uint8_t* fileData = new uint8_t[fileSize];
memcpy(fileData, EMPTY_WAVE, sizeof(EMPTY_WAVE));
Samples.push_back({fileSize, std::unique_ptr<uint8_t[]>(fileData)});

// thread off the file read
// should we spawn one thread per read? or should there be a cap to the number of reads at once?
std::thread readThread(
[pathString, fileSize, data]
[pathString, fileSize, fileData]
{
std::shared_lock lock(g_CustomAudioManager.m_loadingMutex);
std::ifstream wavStream(pathString, std::ios::binary);
Expand All @@ -228,7 +228,7 @@ EventOverrideData::EventOverrideData(const std::string& data, const fs::path& pa

// read from after the header first to preserve the empty header, then read the header last
wavStream.seekg(0, std::ios::beg);
wavStream.read(reinterpret_cast<char*>(data), fileSize);
wavStream.read(reinterpret_cast<char*>(fileData), fileSize);
wavStream.close();

spdlog::info("Finished async read of audio sample {}", pathString);
Expand Down Expand Up @@ -328,7 +328,7 @@ void CustomAudioManager::ClearAudioOverrides()

template <typename Iter, typename RandomGenerator> Iter select_randomly(Iter start, Iter end, RandomGenerator& g)
{
std::uniform_int_distribution<> dis(0, std::distance(start, end) - 1);
std::uniform_int_distribution<__int64> dis(0, std::distance(start, end) - 1);
std::advance(start, dis(g));
return start;
}
Expand Down
4 changes: 2 additions & 2 deletions primedev/client/debugoverlay.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ void, __fastcall, (bool bRender))
OverlayBase_t* pPrevOverlay = nullptr; // rsi
OverlayBase_t* pNextOverlay = nullptr; // rdi

int m_nCreationTick; // eax
// int m_nCreationTick; // eax
bool bShouldDraw; // zf
int m_pUnk; // eax

Expand All @@ -256,7 +256,7 @@ void, __fastcall, (bool bRender))
{
if (pCurrOverlay->m_nCreationTick == -1)
{
m_pUnk = pCurrOverlay->m_pUnk;
m_pUnk = (int)pCurrOverlay->m_pUnk;

if (m_pUnk == -1)
{
Expand Down
6 changes: 3 additions & 3 deletions primedev/client/languagehooks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,9 +100,9 @@ char*, __fastcall, ())
{
spdlog::warn("Caution, audio for this language does NOT exist. You might want to override your game language with -language "
"command line option.");
auto lang = GetAnyInstalledAudioLanguage();
spdlog::warn("Falling back to the first installed audio language: {}", lang.c_str());
strncpy(ingameLang1, lang.c_str(), 256);
auto installedLang = GetAnyInstalledAudioLanguage();
spdlog::warn("Falling back to the first installed audio language: {}", installedLang.c_str());
strncpy(ingameLang1, installedLang.c_str(), 256);
return ingameLang1;
}

Expand Down
4 changes: 2 additions & 2 deletions primedev/client/latencyflex.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@ ON_DLL_LOAD_CLIENT_RELIESON("client.dll", LatencyFlex, ConVar, (CModule module))
// https://ishitatsuyuki.github.io/post/latencyflex/
HMODULE pLfxModule;

if (pLfxModule = LoadLibraryA("latencyflex_layer.dll"))
if ((pLfxModule = LoadLibraryA("latencyflex_layer.dll")) != NULL)
m_winelfx_WaitAndBeginFrame =
reinterpret_cast<void (*)()>(reinterpret_cast<void*>(GetProcAddress(pLfxModule, "lfx_WaitAndBeginFrame")));
else if (pLfxModule = LoadLibraryA("latencyflex_wine.dll"))
else if ((pLfxModule = LoadLibraryA("latencyflex_wine.dll")) != NULL)
m_winelfx_WaitAndBeginFrame =
reinterpret_cast<void (*)()>(reinterpret_cast<void*>(GetProcAddress(pLfxModule, "winelfx_WaitAndBeginFrame")));
else
Expand Down
4 changes: 2 additions & 2 deletions primedev/client/localchatwriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -213,15 +213,15 @@ class AnsiEscapeParser
}
else if (val < 232)
{
unsigned char code = val - 16;
unsigned char code = (unsigned char)(val - 16);
unsigned char blue = code % 6;
unsigned char green = ((code - blue) / 6) % 6;
unsigned char red = (code - blue - (green * 6)) / 36;
m_writer->InsertColorChange(Color {(unsigned char)(red * 51), (unsigned char)(green * 51), (unsigned char)(blue * 51), 255});
}
else if (val < UCHAR_MAX)
{
unsigned char brightness = (val - 232) * 10 + 8;
unsigned char brightness = (unsigned char)(val - 232) * 10 + 8;
m_writer->InsertColorChange(Color {brightness, brightness, brightness, 255});
}

Expand Down
6 changes: 3 additions & 3 deletions primedev/core/convar/convar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,7 @@ void ConVar::SetValue(Color clValue)
// Purpose: changes the ConVar string value.
// Input : *pszTempVal - flOldValue
//-----------------------------------------------------------------------------
void ConVar::ChangeStringValue(const char* pszTempVal, float flOldValue)
void ConVar::ChangeStringValue(const char* pszTempVal, float /*flOldValue*/)
{
assert(!(m_ConCommandBase.m_nFlags & FCVAR_NEVER_AS_STRING));

Expand Down Expand Up @@ -403,8 +403,8 @@ bool ConVar::SetColorFromString(const char* pszValue)
bool bColor = false;

// Try pulling RGBA color values out of the string.
int nRGBA[4] {};
int nParamsRead = sscanf_s(pszValue, "%i %i %i %i", &(nRGBA[0]), &(nRGBA[1]), &(nRGBA[2]), &(nRGBA[3]));
unsigned char nRGBA[4] {};
int nParamsRead = sscanf_s(pszValue, "%hhu %hhu %hhu %hhu", &(nRGBA[0]), &(nRGBA[1]), &(nRGBA[2]), &(nRGBA[3]));

if (nParamsRead >= 3)
{
Expand Down
2 changes: 1 addition & 1 deletion primedev/core/convar/convar.h
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ class ConVar
struct CVValue_t
{
const char* m_pszString;
int64_t m_iStringLength;
uint64_t m_iStringLength;
float m_fValue;
int m_nValue;
};
Expand Down
2 changes: 2 additions & 0 deletions primedev/core/convar/cvar.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ class CCVarIteratorInternal // Fully reversed table, just look at the virtual fu
virtual void Next(void) = 0; // 1
virtual bool IsValid(void) = 0; // 2
virtual ConCommandBase* Get(void) = 0; // 3

virtual ~CCVarIteratorInternal() {}
};

//-----------------------------------------------------------------------------
Expand Down
2 changes: 1 addition & 1 deletion primedev/core/filesystem/filesystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ FileHandle_t, __fastcall, (VPKData* vpkInfo, uint64_t* b, char* filename))
// don't compile here because this is only ever called from OpenEx, which already compiles
if (TryReplaceFile(filename, false))
{
*b = -1;
*b = (uint64_t)-1;
return b;
}

Expand Down
3 changes: 0 additions & 3 deletions primedev/core/hooks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,6 @@ uintptr_t ParseDLLOffsetString(const char* pAddrString)
uintptr_t iOffset = 0;

int iOffsetBegin = iDllNameEnd;
size_t iOffsetEnd = strlen(pAddrString);

// seek until we hit the start of the number offset
for (; !(pAddrString[iOffsetBegin] >= '0' && pAddrString[iOffsetBegin] <= '9') && pAddrString[iOffsetBegin]; iOffsetBegin++)
Expand Down Expand Up @@ -407,8 +406,6 @@ HMODULE, WINAPI, (LPCSTR lpLibFileName, HANDLE hFile, DWORD dwFlags))
{
MessageBoxA(0, "Could not find XInput9_1_0.dll", "Northstar", MB_ICONERROR);
exit(EXIT_FAILURE);

return nullptr;
}
}
else
Expand Down
18 changes: 9 additions & 9 deletions primedev/core/math/bitbuf.h
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ class BFRead : public BitBufferBase
return ret;
}

INLINE u32 ReadUBitLong(i32 numBits)
INLINE u32 ReadUBitLong(u32 numBits)
{
if (m_CachedBitsLeft >= numBits)
{
Expand Down Expand Up @@ -432,7 +432,7 @@ class BFRead : public BitBufferBase
float shift = (float)(GetBitForBitnum(numBits));

i32 i = ReadUBitLong(numBits);
float fReturn = (float)i * (360.0 / shift);
float fReturn = (float)i * (360.0f / shift);

return fReturn;
}
Expand Down Expand Up @@ -531,14 +531,14 @@ class BFRead : public BitBufferBase
// read remaining bytes
while (bitsLeft >= 8)
{
*out = ReadUBitLong(8);
*out = (u8)ReadUBitLong(8);
++out;
bitsLeft -= 8;
}

// read remaining bits
if (bitsLeft)
*out = ReadUBitLong(bitsLeft);
*out = (u8)ReadUBitLong(bitsLeft);
}

INLINE bool ReadBytes(uptr outData, u32 byteLength)
Expand All @@ -554,7 +554,7 @@ class BFRead : public BitBufferBase

while (1)
{
char val = ReadChar();
char val = (char)ReadChar();

if (val == 0)
break;
Expand Down Expand Up @@ -594,7 +594,7 @@ class BFRead : public BitBufferBase

// Now copy into the output and return it;
char* ret = new char[chars + 1];
for (u32 i = 0; i <= chars; i++)
for (int i = 0; i <= chars; i++)
ret[i] = str[i];

return ret;
Expand Down Expand Up @@ -745,7 +745,7 @@ class BFWrite : public BitBufferBase

INLINE int GetNumBitsLeft()
{
return m_OutBitsLeft + (32 * (m_DataEnd - m_DataOut - 1));
return (int)(m_OutBitsLeft + (32 * (m_DataEnd - m_DataOut - 1)));
}

INLINE void Reset()
Expand Down Expand Up @@ -826,7 +826,7 @@ class BFWrite : public BitBufferBase
Flush();
}

INLINE void WriteUBitLong(u32 data, i32 numBits, bool checkRange = true)
INLINE void WriteUBitLong(u32 data, u32 numBits, bool checkRange = true)
{
if (numBits <= m_OutBitsLeft)
{
Expand Down Expand Up @@ -918,7 +918,7 @@ class BFWrite : public BitBufferBase

INLINE i32 GetNumBitsWritten()
{
return (32 - m_OutBitsLeft) + (32 * (m_DataOut - m_Data));
return (i32)((32 - m_OutBitsLeft) + (32 * (m_DataOut - m_Data)));
}

INLINE i32 GetNumBytesWritten()
Expand Down
5 changes: 5 additions & 0 deletions primedev/core/memalloc.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
#include "core/memalloc.h"
#include "core/tier0.h"

// TODO: refactor this entire thing to not cause the suppressed warnings
#pragma warning(push)
#pragma warning(disable : 4273 4565)
// TODO: rename to malloc and free after removing statically compiled .libs

extern "C" void* _malloc_base(size_t n)
Expand Down Expand Up @@ -69,3 +72,5 @@ void operator delete(void* p) noexcept
{
_free_base(p);
} // /FORCE:MULTIPLE

#pragma warning(pop)
4 changes: 3 additions & 1 deletion primedev/core/memalloc.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,14 @@
#include "rapidjson/document.h"
// #include "include/rapidjson/allocators.h"

#pragma warning(push)
#pragma warning(disable : 4273 4565)
extern "C" void* _malloc_base(size_t size);
extern "C" void* _calloc_base(size_t const count, size_t const size);
extern "C" void* _realloc_base(void* block, size_t size);
extern "C" void* _recalloc_base(void* const block, size_t const count, size_t const size);
extern "C" void _free_base(void* const block);
extern "C" char* _strdup_base(const char* src);
#pragma warning(pop)

void* operator new(size_t n);
void operator delete(void* p) noexcept;
Expand Down
14 changes: 7 additions & 7 deletions primedev/core/memory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ inline std::vector<uint8_t> HexBytesToString(const char* pHexString)
std::vector<uint8_t> ret;

size_t size = strlen(pHexString);
for (int i = 0; i < size; i++)
for (size_t i = 0; i < size; i++)
{
// If this is a space character, ignore it
if (isspace(pHexString[i]))
Expand All @@ -115,7 +115,7 @@ inline std::vector<uint8_t> HexBytesToString(const char* pHexString)
BYTE result = 0;
for (int j = 0; j < 2; j++)
{
int val = 0;
BYTE val = 0;
char c = *(pHexString + i + j);
if (c >= 'a')
{
Expand All @@ -132,7 +132,7 @@ inline std::vector<uint8_t> HexBytesToString(const char* pHexString)
else
{
assert_msg(false, "Failed to parse invalid hex string.");
val = -1;
val = 0xFF; // -1
}

result += (j == 0) ? val * 16 : val;
Expand Down Expand Up @@ -244,7 +244,7 @@ CMemoryAddress CModule::FindPattern(const uint8_t* pPattern, const char* pMask)
{
if (pMask[i * 16 + j] == 'x')
{
_bittestandset(reinterpret_cast<LONG*>(&nMasks[i]), j);
_bittestandset(reinterpret_cast<LONG*>(&nMasks[i]), (long)j);
}
}
}
Expand Down Expand Up @@ -290,7 +290,7 @@ inline std::pair<std::vector<uint8_t>, std::string> MaskedBytesFromPattern(const
std::string sMask;

size_t size = strlen(pPatternString);
for (int i = 0; i < size; i++)
for (size_t i = 0; i < size; i++)
{
// If this is a space character, ignore it
if (isspace(pPatternString[i]))
Expand All @@ -307,7 +307,7 @@ inline std::pair<std::vector<uint8_t>, std::string> MaskedBytesFromPattern(const
BYTE result = 0;
for (int j = 0; j < 2; j++)
{
int val = 0;
BYTE val = 0;
char c = *(pPatternString + i + j);
if (c >= 'a')
{
Expand All @@ -324,7 +324,7 @@ inline std::pair<std::vector<uint8_t>, std::string> MaskedBytesFromPattern(const
else
{
assert_msg(false, "Failed to parse invalid pattern string.");
val = -1;
val = 0xFF; // -1
}

result += (j == 0) ? val * 16 : val;
Expand Down
Loading
Loading