From 2ea40a23a31f3e9fda2133dbfbadc5946e03f0cb Mon Sep 17 00:00:00 2001 From: Ykkrosh Date: Sat, 2 Jul 2005 21:42:55 +0000 Subject: [PATCH] VS2005 compatibility fixes and warning adjustments: Updated DLLs. Added DirectX headers/libraries, since they're not in the platform SDK. Fixed invalid STL iterator usage. Disabled STL in stack trace, since it breaks. Added comments for some reported warnings. Corrected some apparent off-by-one errors. Defined strlen_s to strnlen. Probably broke pre-beta2 versions of VC2005. This was SVN commit r2454. --- build/premake/premake.lua | 78 ++++++++++++++++------------ source/graphics/MapReader.cpp | 9 ++-- source/graphics/ObjectEntry.cpp | 2 +- source/graphics/ObjectEntry.h | 2 +- source/graphics/ObjectManager.cpp | 4 +- source/graphics/ObjectManager.h | 4 +- source/gui/CList.cpp | 2 +- source/lib/debug_stl.cpp | 7 +++ source/lib/precompiled.h | 3 ++ source/lib/res/snd.cpp | 2 +- source/lib/res/vfs_tree.cpp | 4 +- source/lib/string_s.h | 7 ++- source/lib/sysdep/win/wdbg.cpp | 2 +- source/lib/sysdep/win/wdbg_sym.cpp | 2 +- source/lib/sysdep/win/win_internal.h | 7 ++- source/lib/sysdep/win/wposix.cpp | 4 +- source/lib/sysdep/win/wposix.h | 4 +- source/lib/sysdep/win/wsdl.cpp | 2 +- source/ps/CLogger.cpp | 6 +-- source/ps/Interact.cpp | 6 +++ source/ps/Xeromyces.cpp | 7 ++- source/renderer/ModelRData.cpp | 4 +- source/scripting/ScriptableComplex.h | 2 +- source/simulation/EntityManager.cpp | 6 ++- 24 files changed, 112 insertions(+), 64 deletions(-) diff --git a/build/premake/premake.lua b/build/premake/premake.lua index 82f76c3bb9..7a99786543 100755 --- a/build/premake/premake.lua +++ b/build/premake/premake.lua @@ -1,5 +1,8 @@ dofile("../functions.lua") +atlas = 0 -- temporarily disabled, until the whole of Atlas + -- can be integrated into this build process + -- Set up the Project project.name = "pyrogenesis" project.bindir = "../../../binaries/system" @@ -17,6 +20,7 @@ function setuppackage (projectname) exename = "sced" objdirprefix = "obj/ScEd_" package.build = 0 -- Don't build Sced by default + atlas = 0 -- Don't build Atlas into ScEd else package.name = "pyrogenesis" exename = "ps" @@ -26,7 +30,7 @@ function setuppackage (projectname) -- Windowed executable on windows, "exe" on all other platforms package.kind = "winexe" package.language = "c++" - + -- Package target for debug and release build -- On Windows, ".exe" is added on the end, on unices the name is used directly package.config["Debug"].target = exename.."_dbg" @@ -37,13 +41,13 @@ function setuppackage (projectname) package.config["Release"].objdir = objdirprefix.."Release" package.config["Testing"].objdir = objdirprefix.."Testing" - + sourceroot = "../../../source/" librariesroot = "../../../libraries/" - + source_dirs = {} - + tconcat(source_dirs, { "ps", "ps/scripting", @@ -64,12 +68,17 @@ function setuppackage (projectname) "renderer" }) - + if (projectname ~= "sced") then tconcat(source_dirs, { "gui", "gui/scripting" }) end + if (atlas == 1) then tconcat(source_dirs, { + "tools/atlas/GameInterface", + "tools/atlas/GameInterface/Handlers" + }) end + tconcat(source_dirs, { "terrain", @@ -81,17 +90,17 @@ function setuppackage (projectname) "tests" }) - + if (projectname == "sced") then tconcat(source_dirs, { "tools/sced", "tools/sced/ui" }) end package.files = sourcesfromdirs(sourceroot, source_dirs) - + tinsert(package.files, sourceroot.."main.cpp") - + include_dirs = { "ps", "simulation", @@ -102,19 +111,19 @@ function setuppackage (projectname) "terrain", "" } - + if (projectname == "sced") then tinsert(include_dirs, "tools/sced") end - + package.includepaths = {} - + foreach(include_dirs, function (i,v) tinsert(package.includepaths, sourceroot .. v) end) - + package.libpaths = {} - + if (OS == "windows") then package.buildflags = { "no-rtti" } else @@ -128,11 +137,11 @@ function setuppackage (projectname) package.config["Testing"].buildflags = { "with-symbols", "no-runtime-checks", "no-edit-and-continue" } package.config["Testing"].defines = { "TESTING" } - + package.config["Release"].buildflags = { "with-symbols", "no-runtime-checks", "no-edit-and-continue", "optimize" } package.config["Release"].defines = { "NDEBUG" } - - + + if (projectname == "sced") then tinsert(package.defines, "SCED") tinsert(package.defines, "_AFXDLL") @@ -142,10 +151,14 @@ function setuppackage (projectname) tinsert(package.defines, "USE_WINMAIN") tinsert(package.defines, "NO_MAIN_REDIRECT") end - + + if (atlas == 1) then + tinsert(package.defines, "ATLAS") + end + -- Platform Specifics if (OS == "windows") then - + -- Directories under 'libraries', each containing 'lib' and 'include': external_libraries = { "misc", @@ -157,28 +170,29 @@ function setuppackage (projectname) "vorbis", "boost", "libjpg", - "dbghelp" + "dbghelp", + "directx" } - + -- Add '//lib' and '/include' to the includepaths and libpaths foreach(external_libraries, function (i,v) tinsert(package.includepaths, librariesroot..v.."/include") tinsert(package.libpaths, librariesroot..v.."/lib") end) - + -- Libraries package.links = { "opengl32" } tinsert(package.files, sourcesfromdirs(sourceroot, {"lib/sysdep/win"})) tinsert(package.files, {sourceroot.."lib/sysdep/win/error_dialog.rc"}) - + if (projectname == "sced") then tinsert(package.files, {sourceroot.."tools/sced/ui/ScEd.rc"}) end - + if (projectname ~= "sced") then tinsert(package.files, {sourceroot.."lib/sysdep/win/icon.rc"}) end - + package.linkoptions = { "/ENTRY:entry", "/DELAYLOAD:opengl32.dll", "/DELAYLOAD:oleaut32.dll", @@ -194,7 +208,7 @@ function setuppackage (projectname) "/DELAYLOAD:dbghelp.dll", "/DELAY:UNLOAD" -- allow manual unload of delay-loaded DLLs } - + package.config["Debug"].linkoptions = { "/DELAYLOAD:js32d.dll", "/DELAYLOAD:zlib1d.dll", @@ -202,10 +216,10 @@ function setuppackage (projectname) "/DELAYLOAD:jpeg-6bd.dll", "/DELAYLOAD:vorbisfile_d.dll", } - + -- 'Testing' uses 'Debug' DLL's package.config["Testing"].linkoptions = package.config["Debug"].linkoptions - + package.config["Release"].linkoptions = { "/DELAYLOAD:js32.dll", "/DELAYLOAD:zlib1.dll", @@ -216,14 +230,14 @@ function setuppackage (projectname) -- required to use WinMain() on Windows, otherwise will default to main() tinsert(package.buildflags, { "no-main" }) - + package.pchHeader = "precompiled.h" package.pchSource = "precompiled.cpp" - + else -- Non-Windows, = Unix - + tinsert(package.files, sourcesfromdirs(sourceroot, {"lib/sysdep/unix"})) - + -- Libraries package.links = { -- OpenGL and X-Windows @@ -231,7 +245,7 @@ function setuppackage (projectname) "SDL", "png", "jpeg", "fam", -- Audio - "openal", "vorbisfile", + "openal", "vorbisfile", -- Utilities "xerces-c", "z", "pthread", "rt", "js" } diff --git a/source/graphics/MapReader.cpp b/source/graphics/MapReader.cpp index eba78b1725..221e370a2c 100755 --- a/source/graphics/MapReader.cpp +++ b/source/graphics/MapReader.cpp @@ -109,7 +109,8 @@ void CMapReader::UnpackObjects() u32 numObjects; unpacker.UnpackRaw(&numObjects, sizeof(numObjects)); m_Objects.resize(numObjects); - unpacker.UnpackRaw(&m_Objects[0], sizeof(SObjectDesc)*numObjects); + if (numObjects) + unpacker.UnpackRaw(&m_Objects[0], sizeof(SObjectDesc)*numObjects); } // UnpackTerrain: unpack the terrain from the end of the input data stream @@ -382,9 +383,9 @@ int CXMLReader::ReadEntities(XMBElement parent, double end_time) debug_assert(entity.getNodeName() == el_entity); CStrW TemplateName; - int PlayerID; + int PlayerID = 0; CVector3D Position; - float Orientation; + float Orientation = 0.f; XERO_ITER_EL(entity, setting) { @@ -447,7 +448,7 @@ int CXMLReader::ReadNonEntities(XMBElement parent, double end_time) CStr ActorName; CVector3D Position; - float Orientation; + float Orientation = 0.f; XERO_ITER_EL(nonentity, setting) { diff --git a/source/graphics/ObjectEntry.cpp b/source/graphics/ObjectEntry.cpp index f3bff45203..b22cb14324 100755 --- a/source/graphics/ObjectEntry.cpp +++ b/source/graphics/ObjectEntry.cpp @@ -36,7 +36,7 @@ CObjectEntry::~CObjectEntry() delete m_Model; } -bool CObjectEntry::BuildRandomVariant(CObjectBase::variation_key& vars, CObjectBase::variation_key::iterator& vars_it) +bool CObjectEntry::BuildRandomVariant(const CObjectBase::variation_key& vars, CObjectBase::variation_key::const_iterator vars_it) { CStr chosenTexture; CStr chosenModel; diff --git a/source/graphics/ObjectEntry.h b/source/graphics/ObjectEntry.h index a183f8b709..8d030e79f7 100755 --- a/source/graphics/ObjectEntry.h +++ b/source/graphics/ObjectEntry.h @@ -18,7 +18,7 @@ public: CObjectEntry(int type, CObjectBase* base); ~CObjectEntry(); - bool BuildRandomVariant(CObjectBase::variation_key& vars, CObjectBase::variation_key::iterator& vars_it); + bool BuildRandomVariant(const CObjectBase::variation_key& vars, CObjectBase::variation_key::const_iterator vars_it); // Base actor. Contains all the things that don't change between // different variations of the actor. diff --git a/source/graphics/ObjectManager.cpp b/source/graphics/ObjectManager.cpp index c1bcbf05f1..cad0841e91 100755 --- a/source/graphics/ObjectManager.cpp +++ b/source/graphics/ObjectManager.cpp @@ -105,7 +105,7 @@ CObjectEntry* CObjectManager::FindObject(const char* objname) return FindObjectVariation(base, var, vars_it); } -CObjectEntry* CObjectManager::FindObjectVariation(const char* objname, CObjectBase::variation_key vars, CObjectBase::variation_key::iterator& vars_it) +CObjectEntry* CObjectManager::FindObjectVariation(const char* objname, const CObjectBase::variation_key& vars, CObjectBase::variation_key::const_iterator vars_it) { CObjectBase* base = FindObjectBase(objname); @@ -115,7 +115,7 @@ CObjectEntry* CObjectManager::FindObjectVariation(const char* objname, CObjectBa return FindObjectVariation(base, vars, vars_it); } -CObjectEntry* CObjectManager::FindObjectVariation(CObjectBase* base, CObjectBase::variation_key vars, CObjectBase::variation_key::iterator& vars_it) +CObjectEntry* CObjectManager::FindObjectVariation(CObjectBase* base, const CObjectBase::variation_key& vars, CObjectBase::variation_key::const_iterator vars_it) { // Look to see whether this particular variation has already been loaded diff --git a/source/graphics/ObjectManager.h b/source/graphics/ObjectManager.h index e7efc5ddc5..0720910c60 100755 --- a/source/graphics/ObjectManager.h +++ b/source/graphics/ObjectManager.h @@ -67,8 +67,8 @@ public: CObjectBase* FindObjectBase(const char* objname); - CObjectEntry* FindObjectVariation(const char* objname, CObjectBase::variation_key vars, CObjectBase::variation_key::iterator& vars_it); - CObjectEntry* FindObjectVariation(CObjectBase* base, CObjectBase::variation_key vars, CObjectBase::variation_key::iterator& vars_it); + CObjectEntry* FindObjectVariation(const char* objname, const CObjectBase::variation_key& vars, CObjectBase::variation_key::const_iterator vars_it); + CObjectEntry* FindObjectVariation(CObjectBase* base, const CObjectBase::variation_key& vars, CObjectBase::variation_key::const_iterator vars_it); // Get all names, quite slowly. (Intended only for ScEd.) void GetAllObjectNames(std::vector& names); diff --git a/source/gui/CList.cpp b/source/gui/CList.cpp index 03a1be9b48..6dcde49b9f 100644 --- a/source/gui/CList.cpp +++ b/source/gui/CList.cpp @@ -334,7 +334,7 @@ void CList::DrawList(const int &selected, rect.right, rect.top + m_ItemsYPositions[selected+1] - scroll); if (rect.top <= rect.bottom && - rect.bottom >= rect.top) + rect.bottom >= rect.top) // TODO: "warning C6287: redundant code: the left and right sub-expressions are identical" { if (rect.bottom > rect.bottom) rect.bottom = rect.bottom; diff --git a/source/lib/debug_stl.cpp b/source/lib/debug_stl.cpp index 4c1dbdd683..bd5b469647 100644 --- a/source/lib/debug_stl.cpp +++ b/source/lib/debug_stl.cpp @@ -374,6 +374,13 @@ template bool get_container_info(T* t, size_t size, size_t el_size, int stl_get_container_info(const wchar_t* type_name, const u8* p, size_t size, size_t el_size, size_t* el_count, DebugIterator* el_iterator, void* it_mem) { + // HACK: The debug_stl code breaks VS2005's STL badly, causing crashes in + // later pieces of code that try to manipulate the STL containers. Presumably + // it needs to be altered/rewritten to work happily with the new STL debug iterators. +#if defined(_MSC_VER) && _MSC_VER >= 1400 + return -1; +#endif + bool valid; #define CONTAINER(name)\ diff --git a/source/lib/precompiled.h b/source/lib/precompiled.h index e22e6c990b..1ad826cb15 100755 --- a/source/lib/precompiled.h +++ b/source/lib/precompiled.h @@ -11,6 +11,9 @@ #ifdef _MSC_VER #pragma warning(disable:4996) // function is deprecated #pragma warning(disable:4786) // identifier truncated to 255 chars +// VS2005 code analysis warnings - disable the very frequent ones: +#pragma warning(disable:6011) // dereferencing NULL pointer +#pragma warning(disable:6246) // local declaration hides declaration of the same name in outer scope #endif // make these available everywhere for convenience: diff --git a/source/lib/res/snd.cpp b/source/lib/res/snd.cpp index a50e80a4b7..514f34aae4 100755 --- a/source/lib/res/snd.cpp +++ b/source/lib/res/snd.cpp @@ -1009,7 +1009,7 @@ if(file_type == FT_OGG) size_t bytes_read; do { - const size_t bufsize = 32*KiB; + const size_t bufsize = 32*KiB; // TODO (or not to do, if it's not a problem worth caring about): "warning C6262: Function uses '32840' bytes of stack: exceeds /analysis:stacksize'16384'. Consider moving some data to heap" char buf[bufsize]; bytes_read = ogg_read(sd->o, buf, bufsize); data.insert(data.end(), &buf[0], &buf[bytes_read]); diff --git a/source/lib/res/vfs_tree.cpp b/source/lib/res/vfs_tree.cpp index d7c031a1da..46a5258ee4 100644 --- a/source/lib/res/vfs_tree.cpp +++ b/source/lib/res/vfs_tree.cpp @@ -480,7 +480,9 @@ int TDir::lookup(const char* path, uint flags, TNode** pnode, char* exact_path) char* slash = (char*)strchr(cur_component, '/'); if(!slash) { - // string ended in slash => return the current dir node + // string ended in slash => return the current dir node. + // TODO: is it at all possible that this will happen on the + // first iteration, when 'node' is still undefined? if(*cur_component == '\0') break; // it's a filename diff --git a/source/lib/string_s.h b/source/lib/string_s.h index 3ae79dc563..bf60bd48b1 100644 --- a/source/lib/string_s.h +++ b/source/lib/string_s.h @@ -4,8 +4,13 @@ #include "posix_types.h" // size_t // these are already shipped with VC2005 -#if _MSC_VER < 1400 +#if _MSC_VER >= 1400 +// ...except VC2005 Beta 2 uses strnlen instead of strlen_s +// (see http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1059.htm) +#define strlen_s(str, max) strnlen(str, max) + +#else // return length [in characters] of a string, not including the trailing // null character. to protect against access violations, only the diff --git a/source/lib/sysdep/win/wdbg.cpp b/source/lib/sysdep/win/wdbg.cpp index ed781f591b..57df9d3ef3 100755 --- a/source/lib/sysdep/win/wdbg.cpp +++ b/source/lib/sysdep/win/wdbg.cpp @@ -910,7 +910,7 @@ static const wchar_t* get_exception_locus(const EXCEPTION_POINTERS* ep) // points to kernel32!RaiseException. we use debug_dump_stack to determine the // real location. - wchar_t buf[32000]; + wchar_t buf[32000]; // Maybe TODO: "warning C6262: Function uses '64016' bytes of stack: exceeds /analysis:stacksize'16384'. Consider moving some data to heap" const wchar_t* stack_trace = debug_dump_stack(buf, ARRAY_SIZE(buf), 1, ep->ContextRecord); const size_t MAX_LOCUS_CHARS = 256; diff --git a/source/lib/sysdep/win/wdbg_sym.cpp b/source/lib/sysdep/win/wdbg_sym.cpp index 417e3e320a..c90db1724c 100755 --- a/source/lib/sysdep/win/wdbg_sym.cpp +++ b/source/lib/sysdep/win/wdbg_sym.cpp @@ -924,7 +924,7 @@ static int dump_sym_base_type(DWORD type_id, const u8* p, DumpState state) // single out() call. note: we pass a single u64 for all sizes, // which will only work on little-endian systems. - const wchar_t* fmt; + const wchar_t* fmt = L""; switch(base_type) { diff --git a/source/lib/sysdep/win/win_internal.h b/source/lib/sysdep/win/win_internal.h index 202ceb8310..2e258188f7 100755 --- a/source/lib/sysdep/win/win_internal.h +++ b/source/lib/sysdep/win/win_internal.h @@ -284,11 +284,14 @@ typedef struct _PROCESSOR_POWER_INFORMATION # define __deref_opt_out # define __deref_out +#endif + +// (VC2005 defines __specstrings, but doesn't define (or use) __out_xcount, +// so this is not inside the above #ifndef section) +// // missing from dbghelp's list # define __out_xcount(s) -#endif - // // not defined by dbghelp; these values are taken from DIA cvconst.h diff --git a/source/lib/sysdep/win/wposix.cpp b/source/lib/sysdep/win/wposix.cpp index 7c24ceb014..5d7ad637cf 100755 --- a/source/lib/sysdep/win/wposix.cpp +++ b/source/lib/sysdep/win/wposix.cpp @@ -465,7 +465,7 @@ void _hide_console() int tcgetattr(int fd, struct termios* termios_p) { - if(fd > 2) + if(fd >= 2) return -1; HANDLE h = std_h[fd]; @@ -479,7 +479,7 @@ int tcgetattr(int fd, struct termios* termios_p) int tcsetattr(int fd, int /* optional_actions */, const struct termios* termios_p) { - if(fd > 2) + if(fd >= 2) return -1; HANDLE h = std_h[fd]; SetConsoleMode(h, (DWORD)termios_p->c_lflag); diff --git a/source/lib/sysdep/win/wposix.h b/source/lib/sysdep/win/wposix.h index b8a6c71d3f..fd2c268a8b 100755 --- a/source/lib/sysdep/win/wposix.h +++ b/source/lib/sysdep/win/wposix.h @@ -59,7 +59,9 @@ extern "C" { // Win32 MAX_PATH is 260 #ifdef _WIN32 -# define SIZE_MAX 0xffffffff +# ifndef SIZE_MAX // VC2005 already defines this in limits.h +# define SIZE_MAX 0xffffffff +# endif #else # define SIZE_MAX 0xffffffffffffffff #endif diff --git a/source/lib/sysdep/win/wsdl.cpp b/source/lib/sysdep/win/wsdl.cpp index f9f8da7bff..f5b44f959d 100755 --- a/source/lib/sysdep/win/wsdl.cpp +++ b/source/lib/sysdep/win/wsdl.cpp @@ -1024,7 +1024,7 @@ SDL_Thread* SDL_CreateThread(int(*func)(void*), void* param) pthread_sdl u; if(pthread_create(&u.p, 0, (void*(*)(void*))func, param) < 0) return 0; - return u.s; + return u.s; // TODO: uninitialised value? } int SDL_KillThread(SDL_Thread* thread) diff --git a/source/ps/CLogger.cpp b/source/ps/CLogger.cpp index 1866499a9b..74f2ef8fe2 100755 --- a/source/ps/CLogger.cpp +++ b/source/ps/CLogger.cpp @@ -215,13 +215,11 @@ void CLogger::QuickLog(const char *fmt, ...) while(buffer[count] != '\0') { - *m_CurrentPosition = buffer[count]; - *m_CurrentPosition++; + *m_CurrentPosition++ = buffer[count]; count++; } - *m_CurrentPosition = '\n'; - *m_CurrentPosition++; + *m_CurrentPosition++ = '\n'; free(buffer); } diff --git a/source/ps/Interact.cpp b/source/ps/Interact.cpp index b37adbda50..f4cb62d011 100755 --- a/source/ps/Interact.cpp +++ b/source/ps/Interact.cpp @@ -269,6 +269,12 @@ void CSelectedEntities::loadGroup( i8 groupid ) if( m_group == groupid ) return; + if( groupid >= MAX_GROUPS ) + { + debug_warn( "Invalid group id" ); + return; + } + clearSelection(); m_selected = m_groups[groupid]; diff --git a/source/ps/Xeromyces.cpp b/source/ps/Xeromyces.cpp index 31191f8e93..4445d9992b 100755 --- a/source/ps/Xeromyces.cpp +++ b/source/ps/Xeromyces.cpp @@ -90,8 +90,11 @@ private: void grow() { allocated += bufferinc; - buffer = (char*)realloc(buffer, allocated); - debug_assert(buffer); + char* newbuffer = (char*)realloc(buffer, allocated); + if (newbuffer) + buffer = newbuffer; + else + debug_warn("Xeromyces: realloc failed"); } }; diff --git a/source/renderer/ModelRData.cpp b/source/renderer/ModelRData.cpp index 3cf7fe4fff..2b833a1083 100755 --- a/source/renderer/ModelRData.cpp +++ b/source/renderer/ModelRData.cpp @@ -110,7 +110,7 @@ static void SkinPoint(const SModelVertex& vertex,const CMatrix3D* matrices,CVect m.Transform(vertex.m_Coords,result); result*=blend.m_Weight[0]; - for (u32 i=1;blend.m_Bone[i]!=0xff && im_Owner; IJSComplexProperty* Property; - JSString* str; + JSString* str = NULL; while( Target ) { diff --git a/source/simulation/EntityManager.cpp b/source/simulation/EntityManager.cpp index 6d22b9f279..0415623478 100755 --- a/source/simulation/EntityManager.cpp +++ b/source/simulation/EntityManager.cpp @@ -59,7 +59,11 @@ HEntity CEntityManager::create( CBaseEntity* base, CVector3D position, float ori while( m_entities[m_nextalloc].m_refcount ) { m_nextalloc++; - debug_assert(m_nextalloc < MAX_HANDLES); + if( m_nextalloc >= MAX_HANDLES ) + { + debug_warn("Ran out of entity handles!"); + return HEntity(); + } } m_entities[m_nextalloc].m_entity = new CEntity( base, position, orientation ); m_entities[m_nextalloc].m_entity->me = HEntity( m_nextalloc );