Skip to content

Commit

Permalink
Changed Undefined behavior sanitizer options to avoid false positives…
Browse files Browse the repository at this point in the history
…; fixed a small bug during item grid index assignment.
  • Loading branch information
cbnolok committed Oct 7, 2023
1 parent 44a5a19 commit f739b2d
Show file tree
Hide file tree
Showing 8 changed files with 22 additions and 17 deletions.
2 changes: 1 addition & 1 deletion Changelog.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3346,7 +3346,7 @@ Additionally, the problem of zig-zag issue following in the South direction has
- Fixed: Client Linger Timer is 3600 seconds on stoned players. (Issue #1081)

23-09-2023, Jhobean
Fixed: When deleting account, f_onchar_delete was not call on char and char's item was not remove causing warning on next server boot. ( Issue #1029)
- Fixed: When deleting account, f_onchar_delete was not call on char and char's item was not removed causing warning on next server boot. (Issue #1029)

07-10-2023, Nolok
- Added: FUNC keyword to item templates and template-triggers with special parsing (@Create, @CreateLoot, @NPCRestock). It allows to call a function with arguments on the last created ITEM.
Expand Down
3 changes: 2 additions & 1 deletion cmake/toolchains/Linux-Clang_common.inc.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ function (toolchain_exe_stuff_common)
IF (${USE_UBSAN})
SET (UBSAN_FLAGS "-fsanitize=undefined,\
shift,integer-divide-by-zero,vla-bound,null,signed-integer-overflow,bounds-strict,\
float-divide-by-zero,float-cast-overflow,pointer-overflow")
float-divide-by-zero,float-cast-overflow,pointer-overflow \
-fno-sanitize=enum")
SET (C_FLAGS_EXTRA "${C_FLAGS_EXTRA} ${UBSAN_FLAGS}")
SET (CXX_FLAGS_EXTRA "${CXX_FLAGS_EXTRA} ${UBSAN_FLAGS} -fsanitize=return,vptr")
SET (ENABLED_SANITIZER true)
Expand Down
3 changes: 2 additions & 1 deletion cmake/toolchains/Linux-GNU_common.inc.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ function (toolchain_exe_stuff_common)
IF (${USE_UBSAN})
SET (UBSAN_FLAGS "-fsanitize=undefined,\
shift,integer-divide-by-zero,vla-bound,null,signed-integer-overflow,bounds-strict,\
float-divide-by-zero,float-cast-overflow,pointer-overflow")
float-divide-by-zero,float-cast-overflow,pointer-overflow \
-fno-sanitize=enum")
SET (C_FLAGS_EXTRA "${C_FLAGS_EXTRA} ${UBSAN_FLAGS}")
SET (CXX_FLAGS_EXTRA "${CXX_FLAGS_EXTRA} ${UBSAN_FLAGS} -fsanitize=return,vptr")
SET (ENABLED_SANITIZER true)
Expand Down
3 changes: 2 additions & 1 deletion cmake/toolchains/OSX-AppleClang_common.inc.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ function (toolchain_exe_stuff_common)
IF (${USE_UBSAN})
SET (UBSAN_FLAGS "-fsanitize=undefined,\
shift,integer-divide-by-zero,vla-bound,null,signed-integer-overflow,bounds-strict,\
float-divide-by-zero,float-cast-overflow,pointer-overflow")
float-divide-by-zero,float-cast-overflow,pointer-overflow \
-fno-sanitize=enum")
SET (C_FLAGS_EXTRA "${C_FLAGS_EXTRA} ${UBSAN_FLAGS}")
SET (CXX_FLAGS_EXTRA "${CXX_FLAGS_EXTRA} ${UBSAN_FLAGS} -fsanitize=return,vptr")
SET (ENABLED_SANITIZER true)
Expand Down
15 changes: 8 additions & 7 deletions cmake/toolchains/Windows-Clang_common.inc.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,13 @@ function (toolchain_exe_stuff_common)
SET (EXE_LINKER_EXTRA "")

IF (CLANG_USE_GCC_LINKER)
SET (CLANG_SUBSYSTEM_PREFIX "-m")
SET (CLANG_SUBSYSTEM_PREFIX "-m --entry=WinMainCRTStartup")
ELSE ()
SET (CLANG_SUBSYSTEM_PREFIX "-Xlinker /subsystem:")
ENDIF()

IF (${WIN32_SPAWN_CONSOLE} EQUAL TRUE)
SET (EXE_LINKER_EXTRA "${EXE_LINKER_EXTRA} ${CLANG_SUBSYSTEM_PREFIX}console")
IF (${WIN32_SPAWN_CONSOLE})
SET (EXE_LINKER_EXTRA "${EXE_LINKER_EXTRA} ${CLANG_SUBSYSTEM_PREFIX}console -Xlinker /ENTRY:WinMainCRTStartup")
SET (PREPROCESSOR_DEFS_EXTRA "_WINDOWS_CONSOLE")
ELSE ()
SET (EXE_LINKER_EXTRA "${EXE_LINKER_EXTRA} ${CLANG_SUBSYSTEM_PREFIX}windows")
Expand All @@ -48,14 +48,15 @@ function (toolchain_exe_stuff_common)
ENDIF ()
IF (${USE_UBSAN})
SET (UBSAN_FLAGS "-fsanitize=undefined,\
#shift,integer-divide-by-zero,vla-bound,null,signed-integer-overflow,bounds-strict,\
#float-divide-by-zero,float-cast-overflow,pointer-overflow")
shift,integer-divide-by-zero,vla-bound,null,signed-integer-overflow,bounds,\
float-divide-by-zero,float-cast-overflow,pointer-overflow \
-fno-sanitize=enum")
SET (C_FLAGS_EXTRA "${C_FLAGS_EXTRA} ${UBSAN_FLAGS}")
SET (CXX_FLAGS_EXTRA "${CXX_FLAGS_EXTRA} ${UBSAN_FLAGS} -fsanitize=return,vptr")
SET (CXX_FLAGS_EXTRA "${CXX_FLAGS_EXTRA} ${UBSAN_FLAGS} -fsanitize=return")
SET (ENABLED_SANITIZER true)
ENDIF ()
IF (${ENABLED_SANITIZER})
SET (PREPROCESSOR_DEFS_EXTRA "${PREPROCESSOR_DEFS_EXTRA} _SANITIZERS")
SET (PREPROCESSOR_DEFS_EXTRA ${PREPROCESSOR_DEFS_EXTRA} _SANITIZERS)
ENDIF ()


Expand Down
5 changes: 3 additions & 2 deletions cmake/toolchains/Windows-GNU_common.inc.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ endfunction ()

function (toolchain_exe_stuff_common)
SET (EXE_LINKER_EXTRA "")
IF (${WIN32_SPAWN_CONSOLE} EQUAL TRUE)
IF (${WIN32_SPAWN_CONSOLE})
SET (EXE_LINKER_EXTRA "${EXE_LINKER_EXTRA} -mconsole")
SET (PREPROCESSOR_DEFS_EXTRA "_WINDOWS_CONSOLE")
#ELSE ()
Expand All @@ -35,7 +35,8 @@ function (toolchain_exe_stuff_common)
MESSAGE (FATAL_ERROR "MinGW-GCC doesn't yet support UBSAN")
#SET (UBSAN_FLAGS "-fsanitize=undefined,\
#shift,integer-divide-by-zero,vla-bound,null,signed-integer-overflow,bounds-strict,\
#float-divide-by-zero,float-cast-overflow,pointer-overflow")
#float-divide-by-zero,float-cast-overflow,pointer-overflow \
#-fno-sanitize=enum")
#SET (C_FLAGS_EXTRA "${C_FLAGS_EXTRA} ${UBSAN_FLAGS}")
#SET (CXX_FLAGS_EXTRA "${CXX_FLAGS_EXTRA} ${UBSAN_FLAGS} -fsanitize=return,vptr")
#SET (ENABLED_SANITIZER true)
Expand Down
4 changes: 2 additions & 2 deletions src/game/clients/CClientMsg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -290,14 +290,14 @@ void CClient::closeUIWindow( const CObjBase* pObj, PacketCloseUIWindow::UIWindow

void CClient::addObjectRemove( const CUID& uid ) const
{
ADDTOCALLSTACK("CClient::addObjectRemove");
ADDTOCALLSTACK("CClient::addObjectRemove (CUID)");
// Tell the client to remove the item or char
new PacketRemoveObject(this, uid);
}

void CClient::addObjectRemove( const CObjBase * pObj ) const
{
ADDTOCALLSTACK("CClient::addObjectRemove");
ADDTOCALLSTACK("CClient::addObjectRemove (CObjBase)");
addObjectRemove( pObj->GetUID());
}

Expand Down
4 changes: 2 additions & 2 deletions src/game/items/CItemContainer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -586,7 +586,7 @@ void CItemContainer::ContentAdd( CItem *pItem, CPointMap pt, bool bForceNoStack,

// Try drop it on given container grid index (if not available, drop it on next free index)
{
bool fGridCellUsed[UCHAR_MAX] {false};
bool fGridCellUsed[UCHAR_MAX + 1] {false};
for (const CSObjContRec* pObjRec : *this)
{
const CItem* pTry = static_cast<const CItem*>(pObjRec);
Expand All @@ -600,7 +600,7 @@ void CItemContainer::ContentAdd( CItem *pItem, CPointMap pt, bool bForceNoStack,
if (fGridCellUsed[gridIndex])
{
gridIndex = 0;
for (uint i = 0; i < UCHAR_MAX; ++i)
for (uint i = 0; (i < UCHAR_MAX) && (gridIndex < UCHAR_MAX); ++i)
{
if (!fGridCellUsed[i])
break;
Expand Down

0 comments on commit f739b2d

Please sign in to comment.