From 700d3780bbab87c74a884beb82aaa4052de2a12c Mon Sep 17 00:00:00 2001 From: Magnus Auvinen Date: Thu, 16 Aug 2012 20:33:07 +0200 Subject: [PATCH 1/4] added missing flush to SendStartIfno --- src/game/client/gameclient.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/game/client/gameclient.cpp b/src/game/client/gameclient.cpp index 1e7dd55c4..de0c59bd9 100644 --- a/src/game/client/gameclient.cpp +++ b/src/game/client/gameclient.cpp @@ -1287,7 +1287,7 @@ void CGameClient::SendStartInfo() Msg.m_aUseCustomColors[p] = *gs_apUCCVariables[p]; Msg.m_aSkinPartColors[p] = *gs_apColorVariables[p]; } - Client()->SendPackMsg(&Msg, MSGFLAG_VITAL); + Client()->SendPackMsg(&Msg, MSGFLAG_VITAL|MSGFLAG_FLUSH); } void CGameClient::SendKill() From 4e20a9e6c0d2658d53562fc30027b60b009d3edb Mon Sep 17 00:00:00 2001 From: Magnus Auvinen Date: Fri, 17 Aug 2012 00:03:53 +0200 Subject: [PATCH 2/4] cleaned up warnings that clang spits out. some bugs found with it. --- src/base/tl/range.h | 2 +- src/engine/client/graphics_threaded.h | 2 ++ src/engine/server/server.cpp | 4 ++-- src/engine/server/server.h | 6 +++--- src/engine/shared/console.cpp | 6 +++--- src/engine/shared/mapchecker.cpp | 1 + src/engine/shared/netban.h | 2 +- src/game/server/gamemodes/ctf.cpp | 2 +- src/game/server/gamemodes/ctf.h | 2 +- src/versionsrv/mapversions.h | 22 ++++++++++++++++++++++ src/versionsrv/versionsrv.h | 17 ----------------- 11 files changed, 37 insertions(+), 29 deletions(-) create mode 100644 src/versionsrv/mapversions.h diff --git a/src/base/tl/range.h b/src/base/tl/range.h index f1fc070b2..1d225f491 100644 --- a/src/base/tl/range.h +++ b/src/base/tl/range.h @@ -154,7 +154,7 @@ public: void pop_back() { tl_assert(!empty()); end--; } T& front() { tl_assert(!empty()); return *begin; } T& back() { tl_assert(!empty()); return *(end-1); } - T& index(unsigned i) { tl_assert(i >= 0 && i < (unsigned)(end-begin)); return begin[i]; } + T& index(unsigned i) { tl_assert(i < (unsigned)(end-begin)); return begin[i]; } unsigned size() const { return (unsigned)(end-begin); } plain_range slice(unsigned startindex, unsigned endindex) { diff --git a/src/engine/client/graphics_threaded.h b/src/engine/client/graphics_threaded.h index 8627c2f32..3c7cd5ca4 100644 --- a/src/engine/client/graphics_threaded.h +++ b/src/engine/client/graphics_threaded.h @@ -296,6 +296,8 @@ public: INITFLAG_BORDERLESS = 8, }; + virtual ~IGraphicsBackend() {} + virtual int Init(const char *pName, int *Width, int *Height, int FsaaSamples, int Flags) = 0; virtual int Shutdown() = 0; diff --git a/src/engine/server/server.cpp b/src/engine/server/server.cpp index 0e791f15d..5cacb95af 100644 --- a/src/engine/server/server.cpp +++ b/src/engine/server/server.cpp @@ -145,7 +145,7 @@ void CSnapIDPool::FreeID(int ID) } -void CServerBan::Init(IConsole *pConsole, IStorage *pStorage, CServer* pServer) +void CServerBan::InitServerBan(IConsole *pConsole, IStorage *pStorage, CServer* pServer) { CNetBan::Init(pConsole, pStorage); @@ -1609,7 +1609,7 @@ void CServer::RegisterCommands() Console()->Chain("console_output_level", ConchainConsoleOutputLevelUpdate, this); // register console commands in sub parts - m_ServerBan.Init(Console(), Storage(), this); + m_ServerBan.InitServerBan(Console(), Storage(), this); m_pGameServer->OnConsoleInit(); } diff --git a/src/engine/server/server.h b/src/engine/server/server.h index d386646f7..f7f5eb344 100644 --- a/src/engine/server/server.h +++ b/src/engine/server/server.h @@ -50,10 +50,10 @@ class CServerBan : public CNetBan public: class CServer *Server() const { return m_pServer; } - void Init(class IConsole *pConsole, class IStorage *pStorage, class CServer* pServer); + void InitServerBan(class IConsole *pConsole, class IStorage *pStorage, class CServer* pServer); - int BanAddr(const NETADDR *pAddr, int Seconds, const char *pReason); - int BanRange(const CNetRange *pRange, int Seconds, const char *pReason); + virtual int BanAddr(const NETADDR *pAddr, int Seconds, const char *pReason); + virtual int BanRange(const CNetRange *pRange, int Seconds, const char *pReason); static void ConBanExt(class IConsole::IResult *pResult, void *pUser); }; diff --git a/src/engine/shared/console.cpp b/src/engine/shared/console.cpp index 443c59047..3ff3c5b3c 100644 --- a/src/engine/shared/console.cpp +++ b/src/engine/shared/console.cpp @@ -16,21 +16,21 @@ const char *CConsole::CResult::GetString(unsigned Index) { - if (Index < 0 || Index >= m_NumArgs) + if (Index >= m_NumArgs) return ""; return m_apArgs[Index]; } int CConsole::CResult::GetInteger(unsigned Index) { - if (Index < 0 || Index >= m_NumArgs) + if (Index >= m_NumArgs) return 0; return str_toint(m_apArgs[Index]); } float CConsole::CResult::GetFloat(unsigned Index) { - if (Index < 0 || Index >= m_NumArgs) + if (Index >= m_NumArgs) return 0.0f; return str_tofloat(m_apArgs[Index]); } diff --git a/src/engine/shared/mapchecker.cpp b/src/engine/shared/mapchecker.cpp index f8ba30ae5..5a7d062f1 100644 --- a/src/engine/shared/mapchecker.cpp +++ b/src/engine/shared/mapchecker.cpp @@ -6,6 +6,7 @@ #include #include +#include #include "datafile.h" #include "memheap.h" diff --git a/src/engine/shared/netban.h b/src/engine/shared/netban.h index 6d690164d..701648327 100644 --- a/src/engine/shared/netban.h +++ b/src/engine/shared/netban.h @@ -170,7 +170,7 @@ public: class IStorage *Storage() const { return m_pStorage; } virtual ~CNetBan() {} - virtual void Init(class IConsole *pConsole, class IStorage *pStorage); + void Init(class IConsole *pConsole, class IStorage *pStorage); void Update(); virtual int BanAddr(const NETADDR *pAddr, int Seconds, const char *pReason); diff --git a/src/game/server/gamemodes/ctf.cpp b/src/game/server/gamemodes/ctf.cpp index bde0e7281..cdb265407 100644 --- a/src/game/server/gamemodes/ctf.cpp +++ b/src/game/server/gamemodes/ctf.cpp @@ -21,7 +21,7 @@ CGameControllerCTF::CGameControllerCTF(CGameContext *pGameServer) } // balancing -bool CGameControllerCTF::CanBeMovedOnBalance(int ClientID) +bool CGameControllerCTF::CanBeMovedOnBalance(int ClientID) const { CCharacter* Character = GameServer()->m_apPlayers[ClientID]->GetCharacter(); if(Character) diff --git a/src/game/server/gamemodes/ctf.h b/src/game/server/gamemodes/ctf.h index 45ca184c6..7b095a7a5 100644 --- a/src/game/server/gamemodes/ctf.h +++ b/src/game/server/gamemodes/ctf.h @@ -8,7 +8,7 @@ class CGameControllerCTF : public IGameController { // balancing - virtual bool CanBeMovedOnBalance(int ClientID); + virtual bool CanBeMovedOnBalance(int ClientID) const; // game class CFlag *m_apFlags[2]; diff --git a/src/versionsrv/mapversions.h b/src/versionsrv/mapversions.h new file mode 100644 index 000000000..fe9e42295 --- /dev/null +++ b/src/versionsrv/mapversions.h @@ -0,0 +1,22 @@ +/* (c) Magnus Auvinen. See licence.txt in the root of the distribution for more information. */ +/* If you are missing that file, acquire a complete release at teeworlds.com. */ +#ifndef VERSIONSRV_MAPVERSIONS_H +#define VERSIONSRV_MAPVERSIONS_H + +static CMapVersion s_aMapVersionList[] = { + {"ctf1", {0x06, 0xb5, 0xf1, 0x17}, {0x00, 0x00, 0x12, 0x38}}, + {"ctf2", {0x27, 0xbc, 0x5e, 0xac}, {0x00, 0x00, 0x64, 0x1a}}, + {"ctf3", {0xa3, 0x73, 0x9d, 0x41}, {0x00, 0x00, 0x17, 0x0f}}, + {"ctf4", {0xbe, 0x7c, 0x4d, 0xb9}, {0x00, 0x00, 0x2e, 0xfe}}, + {"ctf5", {0xd9, 0x21, 0x29, 0xa0}, {0x00, 0x00, 0x2f, 0x4c}}, + {"ctf6", {0x28, 0xc8, 0x43, 0x51}, {0x00, 0x00, 0x69, 0x2f}}, + {"ctf7", {0x1d, 0x35, 0x98, 0x72}, {0x00, 0x00, 0x15, 0x87}}, + {"dm1", {0xf2, 0x15, 0x9e, 0x6e}, {0x00, 0x00, 0x16, 0xad}}, + {"dm2", {0x71, 0x83, 0x98, 0x78}, {0x00, 0x00, 0x21, 0xdf}}, + {"dm6", {0x47, 0x4d, 0xa2, 0x35}, {0x00, 0x00, 0x1e, 0x95}}, + {"dm7", {0x42, 0x6d, 0xa1, 0x67}, {0x00, 0x00, 0x27, 0x2a}}, + {"dm8", {0x85, 0xf1, 0x1e, 0xd6}, {0x00, 0x00, 0x9e, 0xbd}}, + {"dm9", {0x42, 0xd4, 0x77, 0x7e}, {0x00, 0x00, 0x20, 0x11}}, +}; +static const int s_NumMapVersionItems = sizeof(s_aMapVersionList)/sizeof(CMapVersion); +#endif diff --git a/src/versionsrv/versionsrv.h b/src/versionsrv/versionsrv.h index 383f1ac43..46f64251e 100644 --- a/src/versionsrv/versionsrv.h +++ b/src/versionsrv/versionsrv.h @@ -11,23 +11,6 @@ struct CMapVersion unsigned char m_aSize[4]; }; -static CMapVersion s_aMapVersionList[] = { - {"ctf1", {0x06, 0xb5, 0xf1, 0x17}, {0x00, 0x00, 0x12, 0x38}}, - {"ctf2", {0x27, 0xbc, 0x5e, 0xac}, {0x00, 0x00, 0x64, 0x1a}}, - {"ctf3", {0xa3, 0x73, 0x9d, 0x41}, {0x00, 0x00, 0x17, 0x0f}}, - {"ctf4", {0xbe, 0x7c, 0x4d, 0xb9}, {0x00, 0x00, 0x2e, 0xfe}}, - {"ctf5", {0xd9, 0x21, 0x29, 0xa0}, {0x00, 0x00, 0x2f, 0x4c}}, - {"ctf6", {0x28, 0xc8, 0x43, 0x51}, {0x00, 0x00, 0x69, 0x2f}}, - {"ctf7", {0x1d, 0x35, 0x98, 0x72}, {0x00, 0x00, 0x15, 0x87}}, - {"dm1", {0xf2, 0x15, 0x9e, 0x6e}, {0x00, 0x00, 0x16, 0xad}}, - {"dm2", {0x71, 0x83, 0x98, 0x78}, {0x00, 0x00, 0x21, 0xdf}}, - {"dm6", {0x47, 0x4d, 0xa2, 0x35}, {0x00, 0x00, 0x1e, 0x95}}, - {"dm7", {0x42, 0x6d, 0xa1, 0x67}, {0x00, 0x00, 0x27, 0x2a}}, - {"dm8", {0x85, 0xf1, 0x1e, 0xd6}, {0x00, 0x00, 0x9e, 0xbd}}, - {"dm9", {0x42, 0xd4, 0x77, 0x7e}, {0x00, 0x00, 0x20, 0x11}}, -}; -static const int s_NumMapVersionItems = sizeof(s_aMapVersionList)/sizeof(CMapVersion); - static const unsigned char VERSIONSRV_GETVERSION[] = {255, 255, 255, 255, 'v', 'e', 'r', 'g'}; static const unsigned char VERSIONSRV_VERSION[] = {255, 255, 255, 255, 'v', 'e', 'r', 's'}; From 678cc311df664158f223aa5d945b7ee8748a36f5 Mon Sep 17 00:00:00 2001 From: Magnus Auvinen Date: Fri, 17 Aug 2012 00:05:39 +0200 Subject: [PATCH 3/4] corrected gitignore so it isn't as recursive. git failed to recognize new files. --- .gitignore | 36 ++++++++++++++++++------------------ 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/.gitignore b/.gitignore index 97b56e1ca..229917c30 100644 --- a/.gitignore +++ b/.gitignore @@ -1,24 +1,24 @@ -bam -.bam -config.lua -objs +/bam +/.bam +/config.lua +/objs __pycache__/ *.pyc *.pyo scripts/work/ src/game/generated/ -SDL.dll -freetype.dll -autoexec.cfg +/SDL.dll +/freetype.dll +/autoexec.cfg -crapnet* -dilate* -fake_server* -map_resave* -map_version* -mastersrv* -packetgen* -teeworlds* -teeworlds_srv* -tileset_border* -versionsrv* +/crapnet* +/dilate* +/fake_server* +/map_resave* +/map_version* +/mastersrv* +/packetgen* +/teeworlds* +/teeworlds_srv* +/tileset_border* +/versionsrv* From 8ed246fa1c25049a11e7b0ef5690070863a6a659 Mon Sep 17 00:00:00 2001 From: Magnus Auvinen Date: Fri, 17 Aug 2012 18:32:56 +0200 Subject: [PATCH 4/4] fixed all the errors that the clang static analayzer found --- src/base/system.c | 4 +++- src/base/system.h | 7 +++++++ src/engine/client/client.cpp | 3 +-- src/engine/shared/console.cpp | 2 +- src/engine/shared/snapshot.cpp | 7 ++++--- src/game/editor/editor.cpp | 4 ---- src/game/editor/popups.cpp | 1 - src/game/server/gamecontext.cpp | 12 +++++++----- src/game/server/gamecontroller.cpp | 4 ++-- 9 files changed, 25 insertions(+), 19 deletions(-) diff --git a/src/base/system.c b/src/base/system.c index 2fe79a00b..ebae87d3d 100644 --- a/src/base/system.c +++ b/src/base/system.c @@ -80,7 +80,7 @@ void dbg_assert_imp(const char *filename, int line, int test, const char *msg) void dbg_break() { - *((unsigned*)0) = 0x0; + *((volatile unsigned*)0) = 0x0; } void dbg_msg(const char *sys, const char *fmt, ...) @@ -166,6 +166,8 @@ void *mem_alloc_debug(const char *filename, int line, unsigned size, unsigned al MEMTAIL *tail; MEMHEADER *header = (struct MEMHEADER *)malloc(size+sizeof(MEMHEADER)+sizeof(MEMTAIL)); dbg_assert(header != 0, "mem_alloc failure"); + if(!header) + return NULL; tail = (struct MEMTAIL *)(((char*)(header+1))+size); header->size = size; header->filename = filename; diff --git a/src/base/system.h b/src/base/system.h index 032cf7857..7ba0c0a09 100644 --- a/src/base/system.h +++ b/src/base/system.h @@ -33,6 +33,13 @@ void dbg_assert(int test, const char *msg); #define dbg_assert(test,msg) dbg_assert_imp(__FILE__, __LINE__, test, msg) void dbg_assert_imp(const char *filename, int line, int test, const char *msg); + +#ifdef __clang_analyzer__ +#include +#undef dbg_assert +#define dbg_assert(test,msg) assert(test) +#endif + /* Function: dbg_break Breaks into the debugger. diff --git a/src/engine/client/client.cpp b/src/engine/client/client.cpp index 7f881d4d4..4e6c3757a 100644 --- a/src/engine/client/client.cpp +++ b/src/engine/client/client.cpp @@ -1300,7 +1300,6 @@ void CClient::ProcessServerPacket(CNetChunk *pPacket) } // unpack delta - PurgeTick = DeltaTick; SnapSize = m_SnapshotDelta.UnpackDelta(pDeltaShot, pTmpBuffer3, pDeltaData, DeltaSize); if(SnapSize < 0) { @@ -1339,7 +1338,7 @@ void CClient::ProcessServerPacket(CNetChunk *pPacket) if(m_aSnapshots[SNAP_PREV] && m_aSnapshots[SNAP_PREV]->m_Tick < PurgeTick) PurgeTick = m_aSnapshots[SNAP_PREV]->m_Tick; if(m_aSnapshots[SNAP_CURRENT] && m_aSnapshots[SNAP_CURRENT]->m_Tick < PurgeTick) - PurgeTick = m_aSnapshots[SNAP_PREV]->m_Tick; + PurgeTick = m_aSnapshots[SNAP_CURRENT]->m_Tick; m_SnapshotStorage.PurgeUntil(PurgeTick); // add new diff --git a/src/engine/shared/console.cpp b/src/engine/shared/console.cpp index 3ff3c5b3c..399f53230 100644 --- a/src/engine/shared/console.cpp +++ b/src/engine/shared/console.cpp @@ -68,7 +68,7 @@ int CConsole::ParseStart(CResult *pResult, const char *pString, int Length) if(Length < Len) Len = Length; - str_copy(pResult->m_aStringStorage, pString, Length); + str_copy(pResult->m_aStringStorage, pString, Len); pStr = pResult->m_aStringStorage; // get command diff --git a/src/engine/shared/snapshot.cpp b/src/engine/shared/snapshot.cpp index 3b784ad1e..944858d20 100644 --- a/src/engine/shared/snapshot.cpp +++ b/src/engine/shared/snapshot.cpp @@ -195,13 +195,14 @@ int CSnapshotDelta::CreateDelta(CSnapshot *pFrom, CSnapshot *pTo, void *pDstData // fetch previous indices // we do this as a separate pass because it helps the cache - for(i = 0; i < pTo->NumItems(); i++) + const int NumItems = pTo->NumItems(); + for(i = 0; i < NumItems; i++) { pCurItem = pTo->GetItem(i); // O(1) .. O(n) aPastIndecies[i] = GetItemIndexHashed(pCurItem->Key(), Hashlist); // O(n) .. O(n^n) } - for(i = 0; i < pTo->NumItems(); i++) + for(i = 0; i < NumItems; i++) { // do delta ItemSize = pTo->GetItemSize(i); // O(1) .. O(n) @@ -474,7 +475,7 @@ int CSnapshotStorage::Get(int Tick, int64 *pTagtime, CSnapshot **ppData, CSnapsh if(ppData) *ppData = pHolder->m_pSnap; if(ppAltData) - *ppData = pHolder->m_pAltSnap; + *ppAltData = pHolder->m_pAltSnap; return pHolder->m_SnapSize; } diff --git a/src/game/editor/editor.cpp b/src/game/editor/editor.cpp index 7674bc85c..333e6eb85 100644 --- a/src/game/editor/editor.cpp +++ b/src/game/editor/editor.cpp @@ -2295,8 +2295,6 @@ void CEditor::RenderLayers(CUIRect ToolBox, CUIRect ToolBar, CUIRect View) if(Input()->KeyPresses(KEY_MOUSE_WHEEL_DOWN)) s_ScrollValue = clamp(s_ScrollValue + 1.0f/ScrollNum, 0.0f, 1.0f); } - else - ScrollNum = 0; } } @@ -2619,8 +2617,6 @@ void CEditor::RenderImages(CUIRect ToolBox, CUIRect ToolBar, CUIRect View) if(Input()->KeyPresses(KEY_MOUSE_WHEEL_DOWN)) s_ScrollValue = clamp(s_ScrollValue + 1.0f/ScrollNum, 0.0f, 1.0f); } - else - ScrollNum = 0; } } diff --git a/src/game/editor/popups.cpp b/src/game/editor/popups.cpp index 0e5385a62..48cba679f 100644 --- a/src/game/editor/popups.cpp +++ b/src/game/editor/popups.cpp @@ -578,7 +578,6 @@ int CEditor::PopupPoint(CEditor *pEditor, CUIRect View) { if(pEditor->m_SelectedPoints&(1<m_aColors[v].r = (NewVal>>24)&0xff; pQuad->m_aColors[v].g = (NewVal>>16)&0xff; pQuad->m_aColors[v].b = (NewVal>>8)&0xff; diff --git a/src/game/server/gamecontext.cpp b/src/game/server/gamecontext.cpp index c9c51e355..78e0b3224 100644 --- a/src/game/server/gamecontext.cpp +++ b/src/game/server/gamecontext.cpp @@ -680,11 +680,14 @@ void CGameContext::OnMessage(int MsgID, CUnpacker *pUnpacker, int ClientID) void *pRawMsg = m_NetObjHandler.SecureUnpackMsg(MsgID, pUnpacker); CPlayer *pPlayer = m_apPlayers[ClientID]; - if(!pRawMsg && g_Config.m_Debug) + if(!pRawMsg) { - char aBuf[256]; - str_format(aBuf, sizeof(aBuf), "dropped weird message '%s' (%d), failed on '%s'", m_NetObjHandler.GetMsgName(MsgID), MsgID, m_NetObjHandler.FailedMsgOn()); - Console()->Print(IConsole::OUTPUT_LEVEL_DEBUG, "server", aBuf); + if(g_Config.m_Debug) + { + char aBuf[256]; + str_format(aBuf, sizeof(aBuf), "dropped weird message '%s' (%d), failed on '%s'", m_NetObjHandler.GetMsgName(MsgID), MsgID, m_NetObjHandler.FailedMsgOn()); + Console()->Print(IConsole::OUTPUT_LEVEL_DEBUG, "server", aBuf); + } return; } @@ -1025,7 +1028,6 @@ void CGameContext::OnMessage(int MsgID, CUnpacker *pUnpacker, int ClientID) { OptionMsg.m_NumOptions = NumOptions; Server()->SendPackMsg(&OptionMsg, MSGFLAG_VITAL, ClientID); - NumOptions = 0; } // send tuning parameters to client diff --git a/src/game/server/gamecontroller.cpp b/src/game/server/gamecontroller.cpp index 3fe946845..11cb1adda 100644 --- a/src/game/server/gamecontroller.cpp +++ b/src/game/server/gamecontroller.cpp @@ -924,8 +924,8 @@ void IGameController::CycleMap() pNextMap = pMapRotation; // cut out the next map - char aBuf[512]; - for(int i = 0; i < 512; i++) + char aBuf[512] = {0}; + for(int i = 0; i < 511; i++) { aBuf[i] = pNextMap[i]; if(IsSeparator(pNextMap[i]) || pNextMap[i] == 0)