mirror of
https://github.com/DarkflameUniverse/DarkflameServer.git
synced 2024-11-28 08:27:22 +00:00
minor updates
This commit is contained in:
parent
7740bbbaab
commit
6fa719c679
@ -4,10 +4,9 @@ project(Darkflame
|
||||
LANGUAGES C CXX
|
||||
)
|
||||
|
||||
# TEMP - Sanitizer flags
|
||||
if (UNIX AND NOT APPLE)
|
||||
# add_compile_options("-fsanitize=address,undefined" "-fvisibility=default")
|
||||
add_compile_options("-fsanitize=undefined" "-fvisibility=default")
|
||||
# Sanitizer flags - TODO: Make CMake preset before finalizing PR
|
||||
if (CMAKE_CXX_COMPILER_ID MATCHES "Clang|GNU")
|
||||
add_compile_options("-fsanitize=undefined")
|
||||
add_link_options("-fsanitize=undefined")
|
||||
|
||||
if (CMAKE_CXX_COMPILER_ID MATCHES "Clang")
|
||||
@ -285,7 +284,7 @@ if(MSVC)
|
||||
# add_compile_options("/W4")
|
||||
# Want to enable warnings eventually, but WAY too much noise right now
|
||||
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()
|
||||
message(WARNING "Unknown compiler: '${CMAKE_CXX_COMPILER_ID}' - No warning flags enabled.")
|
||||
endif()
|
||||
|
@ -1,6 +1,7 @@
|
||||
# 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_CXX_COMPILER clang++-16 | clang++ REQUIRED)
|
||||
find_program(CLANG_CXX_LINKER lld REQUIRED)
|
||||
|
||||
# Debug messages
|
||||
message(DEBUG "CLANG_C_COMPILER = ${CLANG_C_COMPILER}")
|
||||
|
@ -53,9 +53,9 @@ bool static _IsSuffixChar(const uint8_t c) {
|
||||
bool GeneralUtils::details::_NextUTF8Char(std::string_view& slice, uint32_t& out) {
|
||||
const size_t rem = slice.length();
|
||||
if (slice.empty()) return false;
|
||||
const auto* bytes = &slice.front();
|
||||
const char* const bytes = slice.data();
|
||||
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
|
||||
out = static_cast<uint32_t>(first & 0x7F);
|
||||
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
|
||||
} else if (first < 0xE0) { // two byte character
|
||||
if (rem > 1) {
|
||||
const uint8_t second = bytes[1];
|
||||
const uint8_t second = static_cast<uint8_t>(bytes[1]);
|
||||
if (_IsSuffixChar(second)) {
|
||||
out = (static_cast<uint32_t>(first & 0x1F) << 6)
|
||||
+ 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
|
||||
if (rem > 2) {
|
||||
const uint8_t second = bytes[1];
|
||||
const uint8_t third = bytes[2];
|
||||
const uint8_t second = static_cast<uint8_t>(bytes[1]);
|
||||
const uint8_t third = static_cast<uint8_t>(bytes[2]);
|
||||
if (_IsSuffixChar(second) && _IsSuffixChar(third)) {
|
||||
out = (static_cast<uint32_t>(first & 0x0F) << 12)
|
||||
+ (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
|
||||
if (rem > 3) {
|
||||
const uint8_t second = bytes[1];
|
||||
const uint8_t third = bytes[2];
|
||||
const uint8_t fourth = bytes[3];
|
||||
const uint8_t second = static_cast<uint8_t>(bytes[1]);
|
||||
const uint8_t third = static_cast<uint8_t>(bytes[2]);
|
||||
const uint8_t fourth = static_cast<uint8_t>(bytes[3]);
|
||||
if (_IsSuffixChar(second) && _IsSuffixChar(third) && _IsSuffixChar(fourth)) {
|
||||
out = (static_cast<uint32_t>(first & 0x07) << 18)
|
||||
+ (static_cast<uint32_t>(second & 0x3F) << 12)
|
||||
|
@ -1396,7 +1396,7 @@ void HandlePacket(Packet* packet) {
|
||||
}
|
||||
|
||||
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;
|
||||
std::memcpy(&messageId, &packet->data[3], sizeof(MessageType::World));
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user