From 3c411dd174c9910f8da7bc0deead41418d90e425 Mon Sep 17 00:00:00 2001 From: janwas Date: Sat, 12 Jul 2008 10:45:11 +0000 Subject: [PATCH] large batch of Dehydra static code analysis fixes (mostly passing arguments by const reference and checking LibError return codes) This was SVN commit r6214. --- source/graphics/ColladaManager.cpp | 8 +++-- source/graphics/MapReader.cpp | 4 +-- source/graphics/MapWriter.cpp | 6 ++-- source/graphics/Material.cpp | 20 +++++------ source/graphics/Material.h | 20 +++++------ source/graphics/MaterialManager.cpp | 4 +-- source/graphics/ObjectManager.cpp | 4 +-- source/graphics/Patch.cpp | 4 +-- source/graphics/Sprite.cpp | 2 +- source/graphics/TerrainProperties.cpp | 2 +- source/graphics/TerrainProperties.h | 2 +- source/graphics/TextureEntry.cpp | 5 +-- source/graphics/TextureManager.cpp | 13 +++---- source/graphics/TextureManager.h | 10 +++--- source/lib/file/file_system_util.cpp | 6 ++-- source/lib/file/file_system_util.h | 6 ++-- source/lib/file/vfs/vfs_tree.cpp | 2 +- source/lib/file/vfs/vfs_tree.h | 2 +- source/lib/frequency_filter.cpp | 2 +- source/lib/lib_errors.cpp | 2 +- source/lib/path_util.cpp | 10 +++--- source/lib/path_util.h | 3 +- source/lib/tests/test_path_util.h | 2 +- source/network/NetClient.cpp | 4 +-- source/network/NetServer.cpp | 6 ++-- source/network/NetSession.cpp | 14 ++++---- source/network/NetSession.h | 4 +-- source/ps/Loader.cpp | 35 ++++++------------- source/ps/Loader.h | 8 ++--- source/ps/LoaderThunks.h | 4 +-- source/ps/XML/XMLWriter.h | 2 +- source/renderer/TerrainRenderer.cpp | 8 ++--- source/simulation/Entity.cpp | 4 +-- source/simulation/Entity.h | 4 +-- source/simulation/EventHandlers.cpp | 4 +-- source/simulation/EventHandlers.h | 4 +-- source/simulation/Simulation.cpp | 6 ++-- source/simulation/TriggerManager.h | 2 +- source/sound/JSI_Sound.cpp | 22 ++++++------ .../tools/atlas/GameInterface/ActorViewer.cpp | 4 +-- .../GameInterface/Handlers/MapHandlers.cpp | 4 +-- 41 files changed, 134 insertions(+), 144 deletions(-) diff --git a/source/graphics/ColladaManager.cpp b/source/graphics/ColladaManager.cpp index 7b6fcc658f..491982d3b1 100644 --- a/source/graphics/ColladaManager.cpp +++ b/source/graphics/ColladaManager.cpp @@ -125,7 +125,10 @@ public: // we deliberately pass invalid XML data) because the VFS caching // logic warns when asked to load such. if(writeBuffer.Size()) - g_VFS->CreateFile(pmdFilename, writeBuffer.Data(), writeBuffer.Size()); + { + LibError ret = g_VFS->CreateFile(pmdFilename, writeBuffer.Data(), writeBuffer.Size()); + debug_assert(ret == INFO::OK); + } return true; } @@ -215,7 +218,8 @@ VfsPath CColladaManager::GetLoadableFilename(const CStr& sourceName, FileType ty // realDaePath is "mods/whatever/art/meshes/whatever.dae" Path realDaePath; - g_VFS->GetRealPath(dae, realDaePath); + LibError ret = g_VFS->GetRealPath(dae, realDaePath); + debug_assert(ret == INFO::OK); // cachedPmdVfsPath is "cache/mods/whatever/art/meshes/whatever_{hash}.pmd" VfsPath cachedPmdVfsPath = VfsPath("cache/") / realDaePath.string(); diff --git a/source/graphics/MapReader.cpp b/source/graphics/MapReader.cpp index cdf2dd0724..2250d0d5bc 100644 --- a/source/graphics/MapReader.cpp +++ b/source/graphics/MapReader.cpp @@ -170,8 +170,8 @@ int CMapReader::UnpackTerrain() } // unpack tile data [3ms] - size_t tilesPerSide = m_MapSize*PATCH_SIZE; - m_Tiles.resize(SQR(tilesPerSide)); + ssize_t tilesPerSide = m_MapSize*PATCH_SIZE; + m_Tiles.resize(size_t(SQR(tilesPerSide))); unpacker.UnpackRaw(&m_Tiles[0], sizeof(STileDesc)*m_Tiles.size()); // reset generator state. diff --git a/source/graphics/MapWriter.cpp b/source/graphics/MapWriter.cpp index aea6e2008c..ea5c84845b 100644 --- a/source/graphics/MapWriter.cpp +++ b/source/graphics/MapWriter.cpp @@ -87,8 +87,8 @@ void CMapWriter::EnumTerrainTextures(CTerrain *pTerrain, ssize_t mapsize=pTerrain->GetPatchesPerSide(); for (ssize_t j=0;jGetPatch(i,j)->m_MiniPatches[m][k]; u16 index=u16(GetHandleIndex(mp.Tex1,handles)); if (index==0xFFFF) { @@ -516,7 +516,7 @@ void CMapWriter::RewriteAllMaps(CTerrain* pTerrain, CUnitManager* pUnitMan, CLightEnv* pLightEnv, CCamera* pCamera, CCinemaManager* pCinema) { VfsPaths pathnames; - fs_GetPathnames(g_VFS, "maps/scenarios", "*.pmp", pathnames); + (void)fs_GetPathnames(g_VFS, "maps/scenarios", "*.pmp", pathnames); for (size_t i = 0; i < pathnames.size(); i++) { const char* pathname = pathnames[i].string().c_str(); diff --git a/source/graphics/Material.cpp b/source/graphics/Material.cpp index 43f9ff923d..1bd6929c2f 100644 --- a/source/graphics/Material.cpp +++ b/source/graphics/Material.cpp @@ -17,7 +17,7 @@ static SMaterialColor IdentityEmissive(0.0f, 0.0f, 0.0f, 1.0f); static SMaterialColor BrokenColor(0.3f, 0.3f, 0.3f, 1.0f); -bool SMaterialColor::operator ==(const SMaterialColor color) +bool SMaterialColor::operator==(const SMaterialColor& color) { return ( r == color.r && @@ -40,7 +40,7 @@ CMaterial::CMaterial() ComputeHash(); } -CMaterial::CMaterial(const CMaterial &material) +CMaterial::CMaterial(const CMaterial& material) { (*this) = material; } @@ -49,7 +49,7 @@ CMaterial::~CMaterial() { } -void CMaterial::operator =(const CMaterial &material) +void CMaterial::operator=(const CMaterial& material) { m_Diffuse = material.m_Diffuse; m_Ambient = material.m_Ambient; @@ -63,7 +63,7 @@ void CMaterial::operator =(const CMaterial &material) ComputeHash(); } -bool CMaterial::operator ==(const CMaterial &material) +bool CMaterial::operator==(const CMaterial& material) { return( m_Texture == m_Texture && @@ -141,13 +141,13 @@ void CMaterial::SetPlayerColor(size_t id) m_PlayerID = id; } -void CMaterial::SetPlayerColor(CColor &colour) +void CMaterial::SetPlayerColor(CColor& colour) { m_TextureColor = SMaterialColor(colour.r, colour.g, colour.b, colour.a); } -void CMaterial::SetTexture(const CStr& texture) +void CMaterial::SetTexture(const CStr& texture) { m_Texture = texture; ComputeHash(); @@ -165,25 +165,25 @@ void CMaterial::SetFragmentProgram(const CStr& prog) ComputeHash(); } -void CMaterial::SetDiffuse(const SMaterialColor &color) +void CMaterial::SetDiffuse(const SMaterialColor& color) { m_Diffuse = color; ComputeHash(); } -void CMaterial::SetAmbient(const SMaterialColor &color) +void CMaterial::SetAmbient(const SMaterialColor& color) { m_Ambient = color; ComputeHash(); } -void CMaterial::SetSpecular(const SMaterialColor &color) +void CMaterial::SetSpecular(const SMaterialColor& color) { m_Specular = color; ComputeHash(); } -void CMaterial::SetEmissive(const SMaterialColor &color) +void CMaterial::SetEmissive(const SMaterialColor& color) { m_Emissive = color; ComputeHash(); diff --git a/source/graphics/Material.h b/source/graphics/Material.h index 5badc30534..41cdab3a9f 100644 --- a/source/graphics/Material.h +++ b/source/graphics/Material.h @@ -21,7 +21,7 @@ public: b = _b; a = _a; } - SMaterialColor(const SMaterialColor &color) + SMaterialColor(const SMaterialColor& color) { r = color.r; g = color.g; @@ -29,14 +29,14 @@ public: a = color.a; } - void operator =(const SMaterialColor color) + void operator=(const SMaterialColor& color) { r = color.r; g = color.g; b = color.b; a = color.a; } - bool operator ==(const SMaterialColor color); + bool operator==(const SMaterialColor& color); float Sum() { @@ -48,7 +48,7 @@ class CMaterial { public: CMaterial(); - CMaterial(const CMaterial &material); + CMaterial(const CMaterial& material); virtual ~CMaterial(); void Bind(); @@ -81,15 +81,15 @@ public: void SetTexture(const CStr& texture); void SetVertexProgram(const CStr& prog); void SetFragmentProgram(const CStr& prog); - void SetDiffuse(const SMaterialColor &color); - void SetAmbient(const SMaterialColor &color); - void SetSpecular(const SMaterialColor &color); - void SetEmissive(const SMaterialColor &color); + void SetDiffuse(const SMaterialColor& color); + void SetAmbient(const SMaterialColor& color); + void SetSpecular(const SMaterialColor& color); + void SetEmissive(const SMaterialColor& color); void SetSpecularPower(float power); void SetUsesAlpha(bool flag); - void operator =(const CMaterial &material); - bool operator ==(const CMaterial &material); + void operator=(const CMaterial& material); + bool operator==(const CMaterial& material); protected: void ComputeHash(); diff --git a/source/graphics/MaterialManager.cpp b/source/graphics/MaterialManager.cpp index b7b1b13051..ae5346a237 100644 --- a/source/graphics/MaterialManager.cpp +++ b/source/graphics/MaterialManager.cpp @@ -13,11 +13,11 @@ static float ClampFloat(float value, float min, float max) return value; } -static SMaterialColor ParseColor(CStr colorStr) +static SMaterialColor ParseColor(const CStr& colorStr_) { SMaterialColor color; - colorStr = colorStr.Trim(PS_TRIM_BOTH); + CStr colorStr(colorStr_.Trim(PS_TRIM_BOTH)); CStr tmp; int idx = 0; long pos = colorStr.Find(' '); diff --git a/source/graphics/ObjectManager.cpp b/source/graphics/ObjectManager.cpp index 7d51493079..dbeecb95d1 100644 --- a/source/graphics/ObjectManager.cpp +++ b/source/graphics/ObjectManager.cpp @@ -160,10 +160,10 @@ static LibError GetObjectName_ThunkCb(const VfsPath& pathname, const FileInfo& U void CObjectManager::GetAllObjectNames(std::vector& names) { - fs_ForEachFile(g_VFS, "art/actors/", GetObjectName_ThunkCb, (uintptr_t)&names, "*.xml", DIR_RECURSIVE); + (void)fs_ForEachFile(g_VFS, "art/actors/", GetObjectName_ThunkCb, (uintptr_t)&names, "*.xml", DIR_RECURSIVE); } void CObjectManager::GetPropObjectNames(std::vector& names) { - fs_ForEachFile(g_VFS, "art/actors/props/", GetObjectName_ThunkCb, (uintptr_t)&names, "*.xml", DIR_RECURSIVE); + (void)fs_ForEachFile(g_VFS, "art/actors/props/", GetObjectName_ThunkCb, (uintptr_t)&names, "*.xml", DIR_RECURSIVE); } diff --git a/source/graphics/Patch.cpp b/source/graphics/Patch.cpp index 1f2bf92e61..f6c1cbd156 100644 --- a/source/graphics/Patch.cpp +++ b/source/graphics/Patch.cpp @@ -38,9 +38,9 @@ void CPatch::Initialize(CTerrain* parent,ssize_t x,ssize_t z) m_Z=z; // set parent of each patch - for (size_t j=0;jGetHandle() != 0 ) - ogl_tex_bind(m_texture->GetHandle()); + (void)ogl_tex_bind(m_texture->GetHandle()); glColor4fv(m_colour); diff --git a/source/graphics/TerrainProperties.cpp b/source/graphics/TerrainProperties.cpp index 04cf3e82db..2d5a743e99 100644 --- a/source/graphics/TerrainProperties.cpp +++ b/source/graphics/TerrainProperties.cpp @@ -27,7 +27,7 @@ CTerrainProperties::CTerrainProperties(CTerrainPropertiesPtr parent): m_Groups = m_pParent->m_Groups; } -CTerrainPropertiesPtr CTerrainProperties::FromXML(CTerrainPropertiesPtr parent, const char* path) +CTerrainPropertiesPtr CTerrainProperties::FromXML(const CTerrainPropertiesPtr& parent, const char* path) { CXeromyces XeroFile; if (XeroFile.Load(path) != PSRETURN_OK) diff --git a/source/graphics/TerrainProperties.h b/source/graphics/TerrainProperties.h index ab62f7d05f..d6ad7c8b63 100644 --- a/source/graphics/TerrainProperties.h +++ b/source/graphics/TerrainProperties.h @@ -66,7 +66,7 @@ public: // Create a new object and load the XML file specified. Returns NULL upon // failure // The parent pointer may be NULL, for the "root" terrainproperties object. - static CTerrainPropertiesPtr FromXML(CTerrainPropertiesPtr parent, const char* path); + static CTerrainPropertiesPtr FromXML(const CTerrainPropertiesPtr& parent, const char* path); // Save the object to an XML file. Implement when needed! ;-) // bool WriteXML(const CStr& path); diff --git a/source/graphics/TextureEntry.cpp b/source/graphics/TextureEntry.cpp index 2f7d2fdb85..0d98f00307 100644 --- a/source/graphics/TextureEntry.cpp +++ b/source/graphics/TextureEntry.cpp @@ -54,7 +54,7 @@ CTextureEntry::~CTextureEntry() m_LoadedTextures.erase(it); if (m_Handle > 0) - ogl_tex_free(m_Handle); + (void)ogl_tex_free(m_Handle); for (GroupVector::iterator it=m_Groups.begin();it!=m_Groups.end();++it) (*it)->RemoveTerrain(this); @@ -87,7 +87,8 @@ void CTextureEntry::BuildBaseColor() return; } - ogl_tex_bind(GetHandle()); + LibError ret = ogl_tex_bind(GetHandle()); + debug_assert(ret == INFO::OK); // get root colour for coloring minimap by querying root level of the texture // (this should decompress any compressed textures for us), diff --git a/source/graphics/TextureManager.cpp b/source/graphics/TextureManager.cpp index fbd98ad22c..90b83d792e 100644 --- a/source/graphics/TextureManager.cpp +++ b/source/graphics/TextureManager.cpp @@ -42,8 +42,9 @@ void CTextureManager::UnloadTerrainTextures() m_LastGroupIndex = 0; } -CTextureEntry* CTextureManager::FindTexture(CStr tag) +CTextureEntry* CTextureManager::FindTexture(const CStr& tag_) { + CStr tag(tag_); // Strip extension off of tag long pos=tag.ReverseFind("."); if (pos != -1) @@ -65,12 +66,12 @@ CTextureEntry* CTextureManager::FindTexture(Handle handle) return CTextureEntry::GetByHandle(handle); } -CTerrainPropertiesPtr CTextureManager::GetPropertiesFromFile(CTerrainPropertiesPtr props, const char* path) +CTerrainPropertiesPtr CTextureManager::GetPropertiesFromFile(const CTerrainPropertiesPtr& props, const char* path) { return CTerrainProperties::FromXML(props, path); } -CTextureEntry *CTextureManager::AddTexture(CTerrainPropertiesPtr props, const CStr& path) +CTextureEntry *CTextureManager::AddTexture(const CTerrainPropertiesPtr& props, const CStr& path) { CTextureEntry *entry = new CTextureEntry(props, path); m_TextureEntries.push_back(entry); @@ -93,7 +94,7 @@ void CTextureManager::DeleteTexture(CTextureEntry* entry) // jw: indeed this is inefficient and RecurseDirectory should be implemented // via VFSUtil::EnumFiles, but it works fine and "only" takes 25ms for // typical maps. therefore, we'll leave it for now. -void CTextureManager::LoadTextures(CTerrainPropertiesPtr props, const char* dir) +void CTextureManager::LoadTextures(const CTerrainPropertiesPtr& props, const char* dir) { VfsPaths pathnames; if(fs_GetPathnames(g_VFS, dir, 0, pathnames) < 0) @@ -134,7 +135,7 @@ void CTextureManager::LoadTextures(CTerrainPropertiesPtr props, const char* dir) } } -void CTextureManager::RecurseDirectory(CTerrainPropertiesPtr parentProps, const char* cur_dir_path) +void CTextureManager::RecurseDirectory(const CTerrainPropertiesPtr& parentProps, const char* cur_dir_path) { //LOG(CLogger::Normal, LOG_CATEGORY, "CTextureManager::RecurseDirectory(%s)", path.c_str()); @@ -157,7 +158,7 @@ void CTextureManager::RecurseDirectory(CTerrainPropertiesPtr parentProps, const // Recurse once for each subdirectory DirectoryNames subdirectoryNames; - g_VFS->GetDirectoryEntries(cur_dir_path, 0, &subdirectoryNames); + (void)g_VFS->GetDirectoryEntries(cur_dir_path, 0, &subdirectoryNames); for (size_t i=0;i files; RETURN_ERR(fs->GetDirectoryEntries(path, &files, 0)); @@ -63,7 +63,7 @@ void fs_SortDirectories(DirectoryNames& directories) } -LibError fs_ForEachFile(PIVFS fs, const VfsPath& path, FileCallback cb, uintptr_t cbData, const char* pattern, int flags) +LibError fs_ForEachFile(const PIVFS& fs, const VfsPath& path, FileCallback cb, uintptr_t cbData, const char* pattern, int flags) { debug_assert(vfs_path_IsDirectory(path)); @@ -102,7 +102,7 @@ LibError fs_ForEachFile(PIVFS fs, const VfsPath& path, FileCallback cb, uintptr_ } -void fs_NextNumberedFilename(PIVFS fs, const VfsPath& pathnameFormat, size_t& nextNumber, VfsPath& nextPathname) +void fs_NextNumberedFilename(const PIVFS& fs, const VfsPath& pathnameFormat, size_t& nextNumber, VfsPath& nextPathname) { // (first call only:) scan directory and set nextNumber according to // highest matching filename found. this avoids filling "holes" in diff --git a/source/lib/file/file_system_util.h b/source/lib/file/file_system_util.h index 98426381a4..622ab14207 100644 --- a/source/lib/file/file_system_util.h +++ b/source/lib/file/file_system_util.h @@ -16,7 +16,7 @@ extern void fs_SortFiles(FileInfos& files); extern void fs_SortDirectories(DirectoryNames& directories); -extern LibError fs_GetPathnames(PIVFS fs, const VfsPath& path, const char* filter, VfsPaths& pathnames); +extern LibError fs_GetPathnames(const PIVFS& fs, const VfsPath& path, const char* filter, VfsPaths& pathnames); /** @@ -47,7 +47,7 @@ enum DirFlags * @param flags see DirFlags * @param LibError **/ -extern LibError fs_ForEachFile(PIVFS fs, const VfsPath& path, FileCallback cb, uintptr_t cbData, const char* pattern = 0, int flags = 0); +extern LibError fs_ForEachFile(const PIVFS& fs, const VfsPath& path, FileCallback cb, uintptr_t cbData, const char* pattern = 0, int flags = 0); /** @@ -62,6 +62,6 @@ extern LibError fs_ForEachFile(PIVFS fs, const VfsPath& path, FileCallback cb, u * if 0, numbers corresponding to existing files are skipped. * @param nextPathname receives the output. **/ -extern void fs_NextNumberedFilename(PIVFS fs, const VfsPath& pathnameFormat, size_t& nextNumber, VfsPath& nextPathname); +extern void fs_NextNumberedFilename(const PIVFS& fs, const VfsPath& pathnameFormat, size_t& nextNumber, VfsPath& nextPathname); #endif // #ifndef INCLUDED_FILE_SYSTEM_UTIL diff --git a/source/lib/file/vfs/vfs_tree.cpp b/source/lib/file/vfs/vfs_tree.cpp index 4e5ef81f7e..31643bd779 100644 --- a/source/lib/file/vfs/vfs_tree.cpp +++ b/source/lib/file/vfs/vfs_tree.cpp @@ -189,7 +189,7 @@ void VfsDirectory::ClearR() } -void VfsDirectory::Attach(PRealDirectory realDirectory) +void VfsDirectory::Attach(const PRealDirectory& realDirectory) { if(!cpu_CAS(&m_shouldPopulate, 0, 1)) { diff --git a/source/lib/file/vfs/vfs_tree.h b/source/lib/file/vfs/vfs_tree.h index bd15578af1..0ad1993be0 100644 --- a/source/lib/file/vfs/vfs_tree.h +++ b/source/lib/file/vfs/vfs_tree.h @@ -78,7 +78,7 @@ public: void ClearR(); - void Attach(PRealDirectory realDirectory); + void Attach(const PRealDirectory& realDirectory); PRealDirectory AssociatedDirectory() const { diff --git a/source/lib/frequency_filter.cpp b/source/lib/frequency_filter.cpp index 3dd8c483ad..115c77382c 100644 --- a/source/lib/frequency_filter.cpp +++ b/source/lib/frequency_filter.cpp @@ -132,7 +132,7 @@ private: const int vote = (value >= m_history[i])? 1 : -1; sum += vote; } - return abs(sum) == m_historySize; + return abs(sum) == (int)m_historySize; } static double Change(double from, double to) diff --git a/source/lib/lib_errors.cpp b/source/lib/lib_errors.cpp index 06670a0830..1a3c5c27fc 100644 --- a/source/lib/lib_errors.cpp +++ b/source/lib/lib_errors.cpp @@ -76,7 +76,7 @@ char* error_description_r(LibError err, char* buf, size_t max_chars) } // unknown - snprintf(buf, max_chars, "Unknown error (%d, 0x%X)", err, err); + snprintf(buf, max_chars, "Unknown error (%d, 0x%X)", (int)err, (unsigned int)err); return buf; } diff --git a/source/lib/path_util.cpp b/source/lib/path_util.cpp index 4da93361c9..c90cdecc08 100644 --- a/source/lib/path_util.cpp +++ b/source/lib/path_util.cpp @@ -160,7 +160,7 @@ void path_copy(char* dst, const char* src) // if necessary, a directory separator is added between the paths. // each may be empty, filenames, or full paths. // total path length (including '\0') must not exceed PATH_MAX. -LibError path_append(char* dst, const char* path1, const char* path2, int flags) +void path_append(char* dst, const char* path1, const char* path2, int flags) { const size_t len1 = strlen(path1); const size_t len2 = strlen(path2); @@ -189,7 +189,11 @@ LibError path_append(char* dst, const char* path1, const char* path2, int flags) } if(total_len > PATH_MAX) - WARN_RETURN(ERR::PATH_LENGTH); + { + DEBUG_WARN_ERR(ERR::PATH_LENGTH); + *dst = 0; + return; + } SAFE_STRCPY(dst, path1); dst += len1; @@ -198,8 +202,6 @@ LibError path_append(char* dst, const char* path1, const char* path2, int flags) SAFE_STRCPY(dst, path2); if(need_terminator) SAFE_STRCPY(dst+len2, "/"); - - return INFO::OK; } diff --git a/source/lib/path_util.h b/source/lib/path_util.h index 4070d99aa3..571bba3019 100644 --- a/source/lib/path_util.h +++ b/source/lib/path_util.h @@ -104,9 +104,8 @@ enum PathAppendFlags * @param path1, path2 strings: empty, filenames, or full paths. * total resulting string must not exceed PATH_MAX chars. * @param flags see PathAppendFlags. - * @return LibError **/ -extern LibError path_append(char* dst, const char* path1, const char* path2, int flags = 0); +extern void path_append(char* dst, const char* path1, const char* path2, int flags = 0); /** * get the name component of a path. diff --git a/source/lib/tests/test_path_util.h b/source/lib/tests/test_path_util.h index 90d3dd0b5c..c8cf95b9e7 100644 --- a/source/lib/tests/test_path_util.h +++ b/source/lib/tests/test_path_util.h @@ -7,7 +7,7 @@ #define TEST_APPEND(path1, path2, flags, correct_result) \ { \ char dst[PATH_MAX] = {0}; \ - TS_ASSERT_OK(path_append(dst, path1, path2, flags)); \ + path_append(dst, path1, path2, flags); \ TS_ASSERT_STR_EQUALS(dst, correct_result); \ } diff --git a/source/network/NetClient.cpp b/source/network/NetClient.cpp index 1c6bb3e951..b6ed3e1a58 100644 --- a/source/network/NetClient.cpp +++ b/source/network/NetClient.cpp @@ -24,7 +24,6 @@ #include "simulation/Simulation.h" // DECLARATIONS -#pragma warning( disable : 4100 ) #define LOG_CAT_NET "net" @@ -130,7 +129,7 @@ void CNetClient::ScriptingInit() // Name: Run() // Desc: Connect to server and start main loop //----------------------------------------------------------------------------- -bool CNetClient::SetupConnection( JSContext* pContext, uintN argc, jsval* argv ) +bool CNetClient::SetupConnection( JSContext* UNUSED(pContext), uintN argc, jsval* argv ) { uint port = DEFAULT_HOST_PORT; @@ -340,6 +339,7 @@ bool CNetClient::OnAuthenticate( void* pContext, CFsmEvent* pEvent ) if ( !pEvent || !pContext ) return false; CNetClient* pClient = ( CNetClient* )( ( FsmActionCtx* )pContext )->pHost; + UNUSED2(pClient); CNetSession* pSession = ( ( FsmActionCtx* )pContext )->pSession; assert( pClient ); diff --git a/source/network/NetServer.cpp b/source/network/NetServer.cpp index 6371ef12ac..bfc61dc9c6 100644 --- a/source/network/NetServer.cpp +++ b/source/network/NetServer.cpp @@ -17,8 +17,6 @@ // DECLARATIONS -#pragma warning( disable : 4100 ) - CNetServer* g_NetServer = NULL; //----------------------------------------------------------------------------- @@ -97,7 +95,7 @@ void CNetServer::ScriptingInit( void ) // Name: Start() // Desc: Initialize the server //----------------------------------------------------------------------------- -bool CNetServer::Start( JSContext* pContext, uintN argc, jsval* argv ) +bool CNetServer::Start( JSContext* UNUSED(pContext), uintN UNUSED(argc), jsval* UNUSED(argv) ) { // Setup initial state m_State = SERVER_STATE_PREGAME; @@ -378,7 +376,9 @@ bool CNetServer::OnError( void* pContext, CFsmEvent* pEvent ) if ( pEvent->GetType() != NMT_ERROR ) return true; CNetServer* pServer = ( CNetServer* )( ( FsmActionCtx* )pContext )->pHost; + UNUSED2(pServer); CNetSession* pSession = ( ( FsmActionCtx* )pContext )->pSession; + UNUSED2(pSession); CErrorMessage* pMessage = ( CErrorMessage* )pEvent->GetParamRef(); if ( pMessage ) diff --git a/source/network/NetSession.cpp b/source/network/NetSession.cpp index c83557d69b..d395f1c7c9 100644 --- a/source/network/NetSession.cpp +++ b/source/network/NetSession.cpp @@ -13,8 +13,6 @@ //#include "NetServer.h" #include "NetLog.h" -#pragma warning( disable : 4100 ) - // DECLARATIONS //----------------------------------------------------------------------------- @@ -447,7 +445,7 @@ void CNetHost::Broadcast( const CNetMessage* pMessage ) // Name: ResizeBuffer() // Desc: Resizes the internal buffer //----------------------------------------------------------------------------- -void CNetHost::ResizeBuffer( uint size ) +void CNetHost::ResizeBuffer( size_t size ) { // Already enough space? if ( size <= m_BufferSize ) return; @@ -486,7 +484,7 @@ bool CNetHost::SendMessage( assert( pSession->m_Peer ); assert( m_Host ); - uint size = pMessage->GetSerializedLength(); + size_t size = pMessage->GetSerializedLength(); // Adjust buffer for message ResizeBuffer( size ); @@ -546,7 +544,7 @@ CNetMessage* CNetHost::ReceiveMessage( const CNetSession* pSession ) // Name: SetupSession() // Desc: Setup new session upon creation //----------------------------------------------------------------------------- -bool CNetHost::SetupSession( CNetSession* pSession ) +bool CNetHost::SetupSession( CNetSession* UNUSED(pSession) ) { return true; } @@ -555,7 +553,7 @@ bool CNetHost::SetupSession( CNetSession* pSession ) // Name: HandleConnect() // Desc: Allow application to handle client connect //----------------------------------------------------------------------------- -bool CNetHost::HandleConnect( CNetSession* pSession ) +bool CNetHost::HandleConnect( CNetSession* UNUSED(pSession) ) { return true; } @@ -564,7 +562,7 @@ bool CNetHost::HandleConnect( CNetSession* pSession ) // Name: HandleDisconnect() // Desc: Allow application to handle client disconnect //----------------------------------------------------------------------------- -bool CNetHost::HandleDisconnect( CNetSession* pSession ) +bool CNetHost::HandleDisconnect( CNetSession* UNUSED(pSession) ) { return true; } @@ -726,7 +724,7 @@ void CNetSession::ScriptingInit( void ) // Name: JSI_Close() // Desc: //----------------------------------------------------------------------------- -bool CNetSession::JSI_Close( JSContext* cx, uintN argc, jsval* argv ) +bool CNetSession::JSI_Close( JSContext* UNUSED(cx), uintN UNUSED(argc), jsval* UNUSED(argv) ) { return false; } diff --git a/source/network/NetSession.h b/source/network/NetSession.h index 209af5ce89..8d0a8063bf 100644 --- a/source/network/NetSession.h +++ b/source/network/NetSession.h @@ -143,7 +143,7 @@ protected: * * @param size The new size for the buffer */ - void ResizeBuffer( uint size ); + void ResizeBuffer( size_t size ); // Allow application to handle new client connect virtual bool SetupSession ( CNetSession* pSession ); @@ -168,7 +168,7 @@ private: CNetHost& operator=( const CNetHost& ); u8* m_Buffer; // Serialize out messages buffer - uint m_BufferSize; // Output buffer size + size_t m_BufferSize; // Output buffer size ENetHost* m_Host; // Represents this host PeerSessionList m_PeerSessions; // Session list of connected peers //pthread_t m_WorkerID; // Worker thread diff --git a/source/ps/Loader.cpp b/source/ps/Loader.cpp index 23306b2444..9c9e26204b 100644 --- a/source/ps/Loader.cpp +++ b/source/ps/Loader.cpp @@ -81,14 +81,12 @@ struct DurationAdder: public std::binary_function: used to calculate progress, and when checking // whether there is enough of the time budget left to process this task // (reduces timeslice overruns, making the main loop more responsive). -LibError LDR_Register(LoadFunc func, void* param, const wchar_t* description, +void LDR_Register(LoadFunc func, void* param, const wchar_t* description, int estimated_duration_ms) { - if(state != REGISTERING) - { - debug_warn("not called between LDR_(Begin|End)Register - why?!"); - // warn here instead of relying on the caller to CHECK_ERR because - // there will be lots of call sites spread around. - return ERR::LOGIC; - } + debug_assert(state == REGISTERING); // must be called between LDR_(Begin|End)Register const LoadRequest lr(func, param, description, estimated_duration_ms); load_requests.push_back(lr); - return INFO::OK; } // call when finished registering tasks; subsequent calls to // LDR_ProgressiveLoad will then work off the queued entries. -LibError LDR_EndRegistering() +void LDR_EndRegistering() { - if(state != REGISTERING) - return ERR::LOGIC; - - if(load_requests.empty()) - debug_warn("no LoadRequests queued"); + debug_assert(state == REGISTERING); + debug_assert(!load_requests.empty()); state = FIRST_LOAD; estimated_duration_tally = 0.0; task_elapsed_time = 0.0; total_estimated_duration = std::accumulate(load_requests.begin(), load_requests.end(), 0.0, DurationAdder()); - return INFO::OK; } // immediately cancel this load; no further tasks will be processed. // used to abort loading upon user request or failure. // note: no special notification will be returned by LDR_ProgressiveLoad. -LibError LDR_Cancel() +void LDR_Cancel() { // note: calling during registering doesn't make sense - that // should be an atomic sequence of begin, register [..], end. - if(state != LOADING) - return ERR::LOGIC; + debug_assert(state == LOADING); - state = IDLE; // the queue doesn't need to be emptied now; that'll happen during the // next LDR_StartRegistering. for now, it is sufficient to set the // state, so that LDR_ProgressiveLoad is a no-op. - return INFO::OK; + state = IDLE; } diff --git a/source/ps/Loader.h b/source/ps/Loader.h index 06898569c8..e3aea9f939 100644 --- a/source/ps/Loader.h +++ b/source/ps/Loader.h @@ -84,7 +84,7 @@ registering member functions, which would otherwise be messy. // this routine is provided so we can prevent 2 simultaneous load operations, // which is bogus. that can happen by clicking the load button quickly, // or issuing via console while already loading. -extern LibError LDR_BeginRegistering(); +extern void LDR_BeginRegistering(); // callback function of a task; performs the actual work. @@ -109,19 +109,19 @@ typedef int (*LoadFunc)(void* param, double time_left); // : used to calculate progress, and when checking // whether there is enough of the time budget left to process this task // (reduces timeslice overruns, making the main loop more responsive). -extern LibError LDR_Register(LoadFunc func, void* param, const wchar_t* description, +extern void LDR_Register(LoadFunc func, void* param, const wchar_t* description, int estimated_duration_ms); // call when finished registering tasks; subsequent calls to // LDR_ProgressiveLoad will then work off the queued entries. -extern LibError LDR_EndRegistering(); +extern void LDR_EndRegistering(); // immediately cancel this load; no further tasks will be processed. // used to abort loading upon user request or failure. // note: no special notification will be returned by LDR_ProgressiveLoad. -extern LibError LDR_Cancel(); +extern void LDR_Cancel(); // process as many of the queued tasks as possible within [s]. diff --git a/source/ps/LoaderThunks.h b/source/ps/LoaderThunks.h index 5c88413651..a247aae06d 100644 --- a/source/ps/LoaderThunks.h +++ b/source/ps/LoaderThunks.h @@ -46,7 +46,7 @@ template void RegMemFun(T* this_, int(T::*func)(void), const wchar_t* description, int estimated_duration_ms) { void* param = new MemFun_t(this_, func); - THROW_ERR(LDR_Register(MemFunThunk, param, description, estimated_duration_ms)); + LDR_Register(MemFunThunk, param, description, estimated_duration_ms); } @@ -75,5 +75,5 @@ template void RegMemFun1(T* this_, int(T::*func)(Arg), Arg a const wchar_t* description, int estimated_duration_ms) { void* param = new MemFun1_t(this_, func, arg); - THROW_ERR(LDR_Register(MemFun1Thunk, param, description, estimated_duration_ms)); + LDR_Register(MemFun1Thunk, param, description, estimated_duration_ms); } diff --git a/source/ps/XML/XMLWriter.h b/source/ps/XML/XMLWriter.h index 127b2e3dfb..13daa8ff62 100644 --- a/source/ps/XML/XMLWriter.h +++ b/source/ps/XML/XMLWriter.h @@ -121,7 +121,7 @@ public: XMLWriter_Element(XMLWriter_File& file, const char* name); ~XMLWriter_Element(); - template void Text(T text); + template void Text(constCharPtr text); template void Attribute(const char* name, T value) { m_File->ElementAttribute(name, value, false); } template void Setting(const char* name, T value) { m_File->ElementAttribute(name, value, true); } void Close(int type); diff --git a/source/renderer/TerrainRenderer.cpp b/source/renderer/TerrainRenderer.cpp index 051a37f343..404bfc9439 100644 --- a/source/renderer/TerrainRenderer.cpp +++ b/source/renderer/TerrainRenderer.cpp @@ -533,12 +533,12 @@ void TerrainRenderer::RenderWater() { CPatch* patch = m->visiblePatches[i]; - for(int dx=0; dxm_X*PATCH_SIZE + dx); - int z = (patch->m_Z*PATCH_SIZE + dz); + ssize_t x = (patch->m_X*PATCH_SIZE + dx); + ssize_t z = (patch->m_Z*PATCH_SIZE + dz); // is any corner of the tile below the water height? if not, no point rendering it bool shouldRender = false; diff --git a/source/simulation/Entity.cpp b/source/simulation/Entity.cpp index 556ee042da..d6f4c05251 100644 --- a/source/simulation/Entity.cpp +++ b/source/simulation/Entity.cpp @@ -814,7 +814,7 @@ void CEntity::PopOrder() m_orderQueue.pop_front(); } -void CEntity::PushOrder( CEntityOrder& order ) +void CEntity::PushOrder( const CEntityOrder& order ) { CEventPrepareOrder evt( order.m_target_entity, order.m_type, order.m_action, order.m_produce_name ); if( DispatchEvent(&evt) ) @@ -827,7 +827,7 @@ void CEntity::PushOrder( CEntityOrder& order ) } } -void CEntity::DispatchNotification( CEntityOrder order, int type ) +void CEntity::DispatchNotification( const CEntityOrder& order, int type ) { CEventNotification evt( order, type ); DispatchEvent( &evt ); diff --git a/source/simulation/Entity.h b/source/simulation/Entity.h index b5c5284b25..98b3589edf 100644 --- a/source/simulation/Entity.h +++ b/source/simulation/Entity.h @@ -374,9 +374,9 @@ public: void ClearOrders(); void PopOrder(); //Use this if an order has finished instead of m_orderQueue.pop_front() - void PushOrder( CEntityOrder& order ); + void PushOrder( const CEntityOrder& order ); - void DispatchNotification( CEntityOrder order, int type ); + void DispatchNotification( const CEntityOrder& order, int type ); int DestroyNotifier( CEntity* target ); //Stop notifier from sending to us void DestroyAllNotifiers(); diff --git a/source/simulation/EventHandlers.cpp b/source/simulation/EventHandlers.cpp index d4ed532cf8..3cccb6a1d3 100644 --- a/source/simulation/EventHandlers.cpp +++ b/source/simulation/EventHandlers.cpp @@ -108,7 +108,7 @@ CEventOrderTransition::CEventOrderTransition( int orderPrevious, int orderCurren AddLocalProperty( L"target", &m_target ); AddLocalProperty( L"position", &m_worldPosition ); } -CEventNotification::CEventNotification( CEntityOrder order, int notifyType ) : CScriptEvent( L"notification", EVENT_NOTIFICATION, true ) +CEventNotification::CEventNotification( const CEntityOrder& order, int notifyType ) : CScriptEvent( L"notification", EVENT_NOTIFICATION, true ) { m_notifyType = notifyType; m_target = order.m_target_entity; @@ -124,7 +124,7 @@ CFormationEvent::CFormationEvent( int type ) : CScriptEvent( L"formationEvent", (int&) m_formationEvent = type; AddLocalProperty( L"formationEvent", &m_formationEvent ); } -CIdleEvent::CIdleEvent( CEntityOrder order, int notifyType ) : CScriptEvent( L"idleEvent", EVENT_IDLE, false ) +CIdleEvent::CIdleEvent( const CEntityOrder& order, int notifyType ) : CScriptEvent( L"idleEvent", EVENT_IDLE, false ) { m_notifyType = notifyType; m_orderType = order.m_type; diff --git a/source/simulation/EventHandlers.h b/source/simulation/EventHandlers.h index 38d0bc3833..8b9bed2772 100644 --- a/source/simulation/EventHandlers.h +++ b/source/simulation/EventHandlers.h @@ -120,7 +120,7 @@ class CEventNotification : public CScriptEvent int m_notifyType; CVector3D m_location; //No real use for y, but CVector2D unsupported public: - CEventNotification( CEntityOrder order, int notifyType ); + CEventNotification( const CEntityOrder& order, int notifyType ); }; class CFormationEvent : public CScriptEvent { @@ -147,6 +147,6 @@ class CIdleEvent : public CScriptEvent CVector3D m_location; CEntity* m_target; public: - CIdleEvent( CEntityOrder order, int notifyType ); + CIdleEvent( const CEntityOrder& order, int notifyType ); }; #endif diff --git a/source/simulation/Simulation.cpp b/source/simulation/Simulation.cpp index 2284cd2882..8e7f890811 100644 --- a/source/simulation/Simulation.cpp +++ b/source/simulation/Simulation.cpp @@ -193,7 +193,7 @@ void CSimulation::Simulate() // Task them all to a point within a radius of the target, radius depends upon // the number of units in the group. -void RandomizeLocations(CEntityOrder order, const std::vector &entities, bool isQueued) +void RandomizeLocations(const CEntityOrder& order, const std::vector &entities, bool isQueued) { std::vector::const_iterator it; float radius = 2.0f * sqrt( (float)entities.size() - 1 ); @@ -226,7 +226,7 @@ void RandomizeLocations(CEntityOrder order, const std::vector &entities } } -void FormationLocations(CEntityOrder order, const std::vector &entities, bool isQueued) +void FormationLocations(const CEntityOrder& order, const std::vector &entities, bool isQueued) { CVector2D upvec(0.0f, 1.0f); std::vector::const_iterator it = entities.begin(); @@ -261,7 +261,7 @@ void FormationLocations(CEntityOrder order, const std::vector &entities } } -void QueueOrder(CEntityOrder order, const std::vector &entities, bool isQueued) +void QueueOrder(const CEntityOrder& order, const std::vector &entities, bool isQueued) { std::vector::const_iterator it; diff --git a/source/simulation/TriggerManager.h b/source/simulation/TriggerManager.h index cd5e689b49..bbc7fedc06 100644 --- a/source/simulation/TriggerManager.h +++ b/source/simulation/TriggerManager.h @@ -62,7 +62,7 @@ struct MapTrigger struct MapTriggerGroup { MapTriggerGroup() { } - MapTriggerGroup(CStrW _name, CStrW _parentName) : name(_name), parentName(_parentName) {} + MapTriggerGroup(const CStrW& _name, const CStrW& _parentName) : name(_name), parentName(_parentName) {} std::list triggers; std::list childGroups; //Indices of children diff --git a/source/sound/JSI_Sound.cpp b/source/sound/JSI_Sound.cpp index 4b236cb6f8..9c2a26cafd 100644 --- a/source/sound/JSI_Sound.cpp +++ b/source/sound/JSI_Sound.cpp @@ -26,12 +26,12 @@ JSI_Sound::JSI_Sound(const CStr& Filename) if (m_Handle < 0) throw std::exception(); // caught by JSI_Sound::Construct. - snd_set_pos(m_Handle, 0,0,0, true); + (void)snd_set_pos(m_Handle, 0,0,0, true); } JSI_Sound::~JSI_Sound() { - this->Free(0, 0, 0); + (void)this->Free(0, 0, 0); } @@ -45,7 +45,7 @@ bool JSI_Sound::SetGain(JSContext* cx, uintN argc, jsval* argv) if (! ToPrimitive(cx, argv[0], gain)) return false; - snd_set_gain(m_Handle, gain); + (void)snd_set_gain(m_Handle, gain); return true; } @@ -59,7 +59,7 @@ bool JSI_Sound::SetPitch(JSContext* cx, uintN argc, jsval* argv) if (! ToPrimitive(cx, argv[0], pitch)) return false; - snd_set_pitch(m_Handle, pitch); + (void)snd_set_pitch(m_Handle, pitch); return true; } @@ -73,11 +73,11 @@ bool JSI_Sound::SetPosition(JSContext* cx, uintN argc, jsval* argv) CVector3D pos; // absolute world coords if (ToPrimitive(cx, argv[0], pos)) - snd_set_pos(m_Handle, pos[0], pos[1], pos[2]); + (void)snd_set_pos(m_Handle, pos[0], pos[1], pos[2]); // relative, 0 offset - right on top of the listener // (we don't need displacement from the listener, e.g. always behind) else - snd_set_pos(m_Handle, 0,0,0, true); + (void)snd_set_pos(m_Handle, 0,0,0, true); return true; } @@ -96,7 +96,7 @@ bool JSI_Sound::Fade(JSContext* cx, uintN argc, jsval* argv) && ToPrimitive(cx, argv[2], length))) return false; - snd_fade(m_Handle, initial_gain, final_gain, length, FT_S_CURVE); + (void)snd_fade(m_Handle, initial_gain, final_gain, length, FT_S_CURVE); // HACK: snd_fade causes to be automatically freed when a // fade to 0 has completed. however, we're still holding on to a @@ -116,7 +116,7 @@ bool JSI_Sound::Play(JSContext* UNUSED(cx), uintN UNUSED(argc), jsval* UNUSED(ar if (! m_Handle) return false; - snd_play(m_Handle); + (void)snd_play(m_Handle); // We can't do anything else with this sound now, since it's impossible to // know whether or not it's still valid (since it might have finished playing // already). So set it to 0, so we don't try doing anything (like freeing it) @@ -131,8 +131,8 @@ bool JSI_Sound::Loop(JSContext* UNUSED(cx), uintN UNUSED(argc), jsval* UNUSED(ar if (! m_Handle) return false; - snd_set_loop(m_Handle, true); - snd_play(m_Handle); + (void)snd_set_loop(m_Handle, true); + (void)snd_play(m_Handle); return true; } @@ -144,7 +144,7 @@ bool JSI_Sound::Free(JSContext* UNUSED(cx), uintN UNUSED(argc), jsval* UNUSED(ar if (! m_Handle) return false; - snd_free(m_Handle); // resets it to 0 + (void)snd_free(m_Handle); // resets it to 0 return true; } diff --git a/source/tools/atlas/GameInterface/ActorViewer.cpp b/source/tools/atlas/GameInterface/ActorViewer.cpp index d57f2565b4..54d02c132e 100644 --- a/source/tools/atlas/GameInterface/ActorViewer.cpp +++ b/source/tools/atlas/GameInterface/ActorViewer.cpp @@ -82,9 +82,9 @@ ActorViewer::ActorViewer() if (tex) { CPatch* patch = m.Terrain.GetPatch(0, 0); - for (int i = 0; i < PATCH_SIZE; ++i) + for (ssize_t i = 0; i < PATCH_SIZE; ++i) { - for (int j = 0; j < PATCH_SIZE; ++j) + for (ssize_t j = 0; j < PATCH_SIZE; ++j) { CMiniPatch& mp = patch->m_MiniPatches[i][j]; mp.Tex1 = tex->GetHandle(); diff --git a/source/tools/atlas/GameInterface/Handlers/MapHandlers.cpp b/source/tools/atlas/GameInterface/Handlers/MapHandlers.cpp index 7fad274c04..ab90b42d24 100644 --- a/source/tools/atlas/GameInterface/Handlers/MapHandlers.cpp +++ b/source/tools/atlas/GameInterface/Handlers/MapHandlers.cpp @@ -98,9 +98,9 @@ MESSAGEHANDLER(GenerateMap) { CPatch* patch = terrain->GetPatch(px, pz); - for (int z = 0; z < PATCH_SIZE; ++z) + for (ssize_t z = 0; z < PATCH_SIZE; ++z) { - for (int x = 0; x < PATCH_SIZE; ++x) + for (ssize_t x = 0; x < PATCH_SIZE; ++x) { patch->m_MiniPatches[z][x].Tex1 = tex; patch->m_MiniPatches[z][x].Tex1Priority = 0;