minor updates

This commit is contained in:
jadebenn 2024-11-23 13:56:47 -08:00
parent 7740bbbaab
commit 6fa719c679
4 changed files with 14 additions and 14 deletions

View File

@ -4,10 +4,9 @@ project(Darkflame
LANGUAGES C CXX LANGUAGES C CXX
) )
# TEMP - Sanitizer flags # Sanitizer flags - TODO: Make CMake preset before finalizing PR
if (UNIX AND NOT APPLE) if (CMAKE_CXX_COMPILER_ID MATCHES "Clang|GNU")
# add_compile_options("-fsanitize=address,undefined" "-fvisibility=default") add_compile_options("-fsanitize=undefined")
add_compile_options("-fsanitize=undefined" "-fvisibility=default")
add_link_options("-fsanitize=undefined") add_link_options("-fsanitize=undefined")
if (CMAKE_CXX_COMPILER_ID MATCHES "Clang") if (CMAKE_CXX_COMPILER_ID MATCHES "Clang")
@ -285,7 +284,7 @@ if(MSVC)
# add_compile_options("/W4") # add_compile_options("/W4")
# Want to enable warnings eventually, but WAY too much noise right now # Want to enable warnings eventually, but WAY too much noise right now
elseif(CMAKE_CXX_COMPILER_ID MATCHES "Clang|GNU") elseif(CMAKE_CXX_COMPILER_ID MATCHES "Clang|GNU")
add_compile_options("-Wuninitialized" "-Wold-style-cast" "-Wstrict-aliasing") add_compile_options("-Wuninitialized" "-Wold-style-cast" "-Wstrict-aliasing=01")
else() else()
message(WARNING "Unknown compiler: '${CMAKE_CXX_COMPILER_ID}' - No warning flags enabled.") message(WARNING "Unknown compiler: '${CMAKE_CXX_COMPILER_ID}' - No warning flags enabled.")
endif() endif()

View File

@ -1,6 +1,7 @@
# Try and find a clang-16 install, falling back to a generic clang install otherwise # Try and find a clang-16 install, falling back to a generic clang install otherwise
find_program(CLANG_C_COMPILER clang-16 | clang REQUIRED) find_program(CLANG_C_COMPILER clang-16 | clang REQUIRED)
find_program(CLANG_CXX_COMPILER clang++-16 | clang++ REQUIRED) find_program(CLANG_CXX_COMPILER clang++-16 | clang++ REQUIRED)
find_program(CLANG_CXX_LINKER lld REQUIRED)
# Debug messages # Debug messages
message(DEBUG "CLANG_C_COMPILER = ${CLANG_C_COMPILER}") message(DEBUG "CLANG_C_COMPILER = ${CLANG_C_COMPILER}")

View File

@ -53,9 +53,9 @@ bool static _IsSuffixChar(const uint8_t c) {
bool GeneralUtils::details::_NextUTF8Char(std::string_view& slice, uint32_t& out) { bool GeneralUtils::details::_NextUTF8Char(std::string_view& slice, uint32_t& out) {
const size_t rem = slice.length(); const size_t rem = slice.length();
if (slice.empty()) return false; if (slice.empty()) return false;
const auto* bytes = &slice.front(); const char* const bytes = slice.data();
if (rem > 0) { if (rem > 0) {
const uint8_t first = bytes[0]; const uint8_t first = static_cast<uint8_t>(bytes[0]);
if (first < 0x80) { // 1 byte character if (first < 0x80) { // 1 byte character
out = static_cast<uint32_t>(first & 0x7F); out = static_cast<uint32_t>(first & 0x7F);
slice.remove_prefix(1); slice.remove_prefix(1);
@ -64,7 +64,7 @@ bool GeneralUtils::details::_NextUTF8Char(std::string_view& slice, uint32_t& out
// middle byte, not valid at start, fall through // middle byte, not valid at start, fall through
} else if (first < 0xE0) { // two byte character } else if (first < 0xE0) { // two byte character
if (rem > 1) { if (rem > 1) {
const uint8_t second = bytes[1]; const uint8_t second = static_cast<uint8_t>(bytes[1]);
if (_IsSuffixChar(second)) { if (_IsSuffixChar(second)) {
out = (static_cast<uint32_t>(first & 0x1F) << 6) out = (static_cast<uint32_t>(first & 0x1F) << 6)
+ static_cast<uint32_t>(second & 0x3F); + static_cast<uint32_t>(second & 0x3F);
@ -74,8 +74,8 @@ bool GeneralUtils::details::_NextUTF8Char(std::string_view& slice, uint32_t& out
} }
} else if (first < 0xF0) { // three byte character } else if (first < 0xF0) { // three byte character
if (rem > 2) { if (rem > 2) {
const uint8_t second = bytes[1]; const uint8_t second = static_cast<uint8_t>(bytes[1]);
const uint8_t third = bytes[2]; const uint8_t third = static_cast<uint8_t>(bytes[2]);
if (_IsSuffixChar(second) && _IsSuffixChar(third)) { if (_IsSuffixChar(second) && _IsSuffixChar(third)) {
out = (static_cast<uint32_t>(first & 0x0F) << 12) out = (static_cast<uint32_t>(first & 0x0F) << 12)
+ (static_cast<uint32_t>(second & 0x3F) << 6) + (static_cast<uint32_t>(second & 0x3F) << 6)
@ -86,9 +86,9 @@ bool GeneralUtils::details::_NextUTF8Char(std::string_view& slice, uint32_t& out
} }
} else if (first < 0xF8) { // four byte character } else if (first < 0xF8) { // four byte character
if (rem > 3) { if (rem > 3) {
const uint8_t second = bytes[1]; const uint8_t second = static_cast<uint8_t>(bytes[1]);
const uint8_t third = bytes[2]; const uint8_t third = static_cast<uint8_t>(bytes[2]);
const uint8_t fourth = bytes[3]; const uint8_t fourth = static_cast<uint8_t>(bytes[3]);
if (_IsSuffixChar(second) && _IsSuffixChar(third) && _IsSuffixChar(fourth)) { if (_IsSuffixChar(second) && _IsSuffixChar(third) && _IsSuffixChar(fourth)) {
out = (static_cast<uint32_t>(first & 0x07) << 18) out = (static_cast<uint32_t>(first & 0x07) << 18)
+ (static_cast<uint32_t>(second & 0x3F) << 12) + (static_cast<uint32_t>(second & 0x3F) << 12)

View File

@ -1396,7 +1396,7 @@ void HandlePacket(Packet* packet) {
} }
default: default:
// Need to use memcpy instead of reinterpret_cast to avoid UB // Need to use memcpy instead of reinterpret_cast to avoid misaligned reads, which are UB
auto messageId = MessageType::World::INVALID; auto messageId = MessageType::World::INVALID;
std::memcpy(&messageId, &packet->data[3], sizeof(MessageType::World)); std::memcpy(&messageId, &packet->data[3], sizeof(MessageType::World));