Skip to content

Commit

Permalink
Fixed RemoveFromView and moongate teleport regressions.
Browse files Browse the repository at this point in the history
Fixed a couple more undefined behaviors.
  • Loading branch information
cbnolok committed Aug 2, 2024
1 parent 7c815bf commit 1defff8
Show file tree
Hide file tree
Showing 19 changed files with 236 additions and 238 deletions.
22 changes: 12 additions & 10 deletions .clang-format
Original file line number Diff line number Diff line change
Expand Up @@ -23,21 +23,23 @@ PointerAlignment: Right
AllowShortBlocksOnASingleLine: false
AllowShortCaseLabelsOnASingleLine: false
AllowShortFunctionsOnASingleLine: None
AllowShortIfStatementsOnASingleLine: false
AllowShortIfStatementsOnASingleLine: Never
AllowShortLambdasOnASingleLine: Inline
AllowShortLoopsOnASingleLine: false

##-- Braces
BreakBeforeBraces: Custom
BreakBeforeBraces: Custom #Allman
BraceWrapping:
#Allman
AfterControlStatement: MultiLine
AfterEnum: false
AfterFunction: false
AfterNamespace: false
AfterStruct: false
AfterUnion: false
BeforeCatch: false
AfterCaseLabel: true
AfterClass: false
AfterControlStatement: Always
AfterEnum: true
AfterFunction: true
AfterNamespace: true
AfterStruct: true
AfterUnion: true
BeforeCatch: true
BeforeElse: true
BeforeLambdaBody: true
IndentBraces: false
SplitEmptyFunction: false
Expand Down
8 changes: 4 additions & 4 deletions src/common/CPointBase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ int CPointBase::GetDistBase( const CPointBase & pt ) const noexcept // Distance
// This is even faster.
const int dx = (m_x > pt.m_x) * (m_x - pt.m_x) + (m_x < pt.m_x) * (pt.m_x - m_x);
const int dy = (m_y > pt.m_y) * (m_y - pt.m_y) + (m_y < pt.m_y) * (pt.m_y - m_y);
return (dx > dy) * dx + (dx < dy) * dy;
return (dx >= dy) * dx + (dx < dy) * dy;

}
case DISTANCE_FORMULA_DIAGONAL_NOZ:
Expand Down Expand Up @@ -221,7 +221,7 @@ int CPointBase::GetDistSightBase( const CPointBase & pt ) const noexcept // Dist
//return maximum(dx, dy);
const int dx = (m_x > pt.m_x) * (m_x - pt.m_x) + (m_x < pt.m_x) * (pt.m_x - m_x);
const int dy = (m_y > pt.m_y) * (m_y - pt.m_y) + (m_y < pt.m_y) * (pt.m_y - m_y);
return (dx > dy) * dx + (dx < dy) * dy;
return (dx >= dy) * dx + (dx < dy) * dy;
}

int CPointBase::GetDistSight( const CPointBase & pt ) const noexcept // Distance between points based on UO sight
Expand All @@ -238,7 +238,7 @@ int CPointBase::GetDistSight( const CPointBase & pt ) const noexcept // Distance
//return maximum(dx, dy);
const int dx = (m_x > pt.m_x) * (m_x - pt.m_x) + (m_x < pt.m_x) * (pt.m_x - m_x);
const int dy = (m_y > pt.m_y) * (m_y - pt.m_y) + (m_y < pt.m_y) * (pt.m_y - m_y);
return (dx > dy) * dx + (dx < dy) * dy;
return (dx >= dy) * dx + (dx < dy) * dy;
}

int CPointBase::GetDist3D( const CPointBase & pt ) const noexcept // Distance between points
Expand All @@ -258,7 +258,7 @@ int CPointBase::GetDist3D( const CPointBase & pt ) const noexcept // Distance be
dz /= (PLAYER_HEIGHT / 2); // Take player height into consideration

//return maximum(dz, dist);
return (dz > dist) * dz + (dz < dist) * dist;
return (dz >= dist) * dz + (dz < dist) * dist;
}
case DISTANCE_FORMULA_DIAGONAL_Z:
{
Expand Down
8 changes: 7 additions & 1 deletion src/common/CScriptObj.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2043,7 +2043,10 @@ size_t CScriptObj::ParseScriptText(tchar * ptcResponse, CTextConsole * pSrc, int
ptcDest = ptcResponse + iBegin;
memcpy(ptcDest, sVal.GetBuffer(), iWriteValLen);

i = iBegin + iWriteValLen - 1;
//i = iBegin + iWriteValLen - 1;
i = iBegin + iWriteValLen;
if (i != 0)
i -= 1;

if (fNoRecurseBrackets) // just do this one then bail out.
{
Expand Down Expand Up @@ -2623,6 +2626,9 @@ TRIGRET_TYPE CScriptObj::OnTriggerLoopGeneric(CScript& s, int iType, CTextConsol
if (rid.IsValidUID())
{
const dword dwTotal = g_World.GetUIDCount();
if (dwTotal == 0)
return TRIGRET_ENDIF;

dword dwCount = dwTotal - 1;
dword dwTotalInstances = 0; // Will acquire the correct value for this during the loop
dword dwUID = 0;
Expand Down
2 changes: 1 addition & 1 deletion src/common/sphere_library/CSQueue.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ byte * CSQueueBytes::AddNewDataLock( size_t iLen )
// re-alloc a bigger buffer. as needed.

ASSERT(m_iDataQty<=m_Mem.GetDataLength());
m_Mem.Resize( ( iLenNew + 0x1000 ) &~ 0xFFF );
m_Mem.Resize( ( iLenNew + 0x1000u ) & (size_t)~0xFFF );
}

return ( m_Mem.GetData() + m_iDataQty );
Expand Down
5 changes: 4 additions & 1 deletion src/common/sphere_library/sstring.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -454,6 +454,9 @@ size_t Str_LengthUTF8(const char* strInUTF8MB) noexcept
// Adapted from: OpenBSD: strlcpy.c,v 1.11 2006/05/05 15:27:38
size_t Str_ConcatLimitNull(tchar *dst, const tchar *src, size_t siz) noexcept
{
if (siz == 0)
return 0;

tchar *d = dst;
size_t n = siz;
size_t dlen;
Expand Down Expand Up @@ -489,7 +492,7 @@ size_t Str_ConcatLimitNull(tchar *dst, const tchar *src, size_t siz) noexcept

tchar* Str_FindSubstring(tchar* str, const tchar* substr, size_t str_len, size_t substr_len) noexcept
{
if (substr_len == 0)
if (str_len == 0 || substr_len == 0)
return nullptr;

tchar c, sc;
Expand Down
2 changes: 1 addition & 1 deletion src/game/CObjBase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ void CObjBase::DeletePrepare()
CObjBase::_GoSleep(); // virtual, but superclass methods are called in their ::DeletePrepare methods

const SERVMODE_TYPE servMode = g_Serv.GetServerMode();
const bool fDestroyingWorld = (servMode != SERVMODE_Exiting && servMode != SERVMODE_Loading);
const bool fDestroyingWorld = (servMode == SERVMODE_Exiting || servMode == SERVMODE_Loading);
if (!fDestroyingWorld)
{
RemoveFromView();
Expand Down
2 changes: 1 addition & 1 deletion src/game/CObjBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -603,7 +603,7 @@ public: virtual bool IsDeleted() const override;
public:

/**
* @fn virtual bool CObjBase::MoveTo(CPointMap pt, bool fCheckLocation = true, bool fForceFix = false) = 0;
* @fn virtual bool CObjBase::MoveTo(CPointMap pt, bool fCheckLocationEffects = true, bool fForceFix = false) = 0;
*
* @brief Move To Location.
*
Expand Down
4 changes: 2 additions & 2 deletions src/game/CSector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1077,8 +1077,8 @@ void CSector::Close(bool fClosingWorld)
m_Chars_Active.ClearContainer(fClosingWorld);
m_Chars_Disconnect.ClearContainer(fClosingWorld);

// These are resource type things.
//m_Teleports.clear();
// These are resource type things, loaded from scripts, not save files. Do not delete them.
//m_Teleports.ClearFree();
//m_RegionLinks.clear();
}

Expand Down
2 changes: 1 addition & 1 deletion src/game/CServerConfig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3975,7 +3975,7 @@ CResourceID CServerConfig::ResourceGetNewID( RES_TYPE restype, lpctstr pszName,
{
// For a book the page is... the page number
// For a REGIONTYPE block, the page (pArg2) is the landtile type associated with the REGIONTYPE
int iArgPage = ResGetIndex(Exp_GetVal(pArg2));
int iArgPage = ResGetIndex(Exp_GetDWVal(pArg2));
if ( iArgPage < RES_PAGE_MAX )
wPage = (word)iArgPage;
else
Expand Down
4 changes: 2 additions & 2 deletions src/game/chars/CChar.h
Original file line number Diff line number Diff line change
Expand Up @@ -490,7 +490,7 @@ public: void StatFlag_Mod(uint64 uiStatFlag, bool fMod) noexcept;
bool MoveToRegion(CRegionWorld* pNewArea, bool fAllowReject);

bool MoveToRegionReTest( dword dwType );
bool MoveToChar(const CPointMap& pt, bool fStanding = true, bool fCheckLocation = true, bool fForceFix = false, bool fAllowReject = true);
bool MoveToChar(const CPointMap& pt, bool fStanding = true, bool fCheckLocationEffects = true, bool fForceFix = false, bool fAllowReject = true);
virtual bool MoveTo(const CPointMap& pt, bool fForceFix = false) override;
virtual void SetTopZ( char z ) override;
virtual bool MoveNearObj( const CObjBaseTemplate *pObj, ushort iSteps = 0 ) override;
Expand All @@ -502,7 +502,7 @@ public: void StatFlag_Mod(uint64 uiStatFlag, bool fMod) noexcept;
bool CanStandAt(CPointMap *ptDest, const CRegion* pArea, uint64 uiMyMovementFlags, height_t uiMyHeight, CServerMapBlockingState* blockingState, bool fPathfinding) const;
CRegion * CanMoveWalkTo( CPointMap & pt, bool fCheckChars = true, bool fCheckOnly = false, DIR_TYPE dir = DIR_QTY, bool fPathFinding = false );
void CheckRevealOnMove();
TRIGRET_TYPE CheckLocation(bool fCanCheckRecursively, bool fStanding);
TRIGRET_TYPE CheckLocationEffects(bool fStanding);

public:
// Client Player specific stuff. -------------------------
Expand Down
Loading

0 comments on commit 1defff8

Please sign in to comment.