From ce0cc0ee857740cb0bd1ebd3b4bfa6eefc31aee6 Mon Sep 17 00:00:00 2001 From: Eugene Sandulenko Date: Sun, 17 Apr 2011 14:48:27 +0300 Subject: COMMON: Partial fix for #3087922: COMMON/BASE/BACKENDS: Code analysis warnings --- backends/platform/sdl/sdl.cpp | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) (limited to 'backends/platform/sdl') diff --git a/backends/platform/sdl/sdl.cpp b/backends/platform/sdl/sdl.cpp index d6e79248f9..2c0c45907f 100644 --- a/backends/platform/sdl/sdl.cpp +++ b/backends/platform/sdl/sdl.cpp @@ -378,7 +378,11 @@ void OSystem_SDL::setupIcon() { unsigned int rgba[256]; unsigned int *icon; - sscanf(scummvm_icon[0], "%d %d %d %d", &w, &h, &ncols, &nbytes); + if (sscanf(scummvm_icon[0], "%d %d %d %d", &w, &h, &ncols, &nbytes) != 4) { + warning("Wrong format of scummvm_icon[0] (%s)", scummvm_icon[0]); + + return; + } if ((w > 512) || (h > 512) || (ncols > 255) || (nbytes > 1)) { warning("Could not load the built-in icon (%d %d %d %d)", w, h, ncols, nbytes); return; @@ -393,13 +397,17 @@ void OSystem_SDL::setupIcon() { unsigned char code; char color[32]; unsigned int col; - sscanf(scummvm_icon[1 + i], "%c c %s", &code, color); + if (sscanf(scummvm_icon[1 + i], "%c c %s", &code, color) != 2) { + warning("Wrong format of scummvm_icon[%d] (%s)", 1 + i, scummvm_icon[1 + i]); + } if (!strcmp(color, "None")) col = 0x00000000; else if (!strcmp(color, "black")) col = 0xFF000000; else if (color[0] == '#') { - sscanf(color + 1, "%06x", &col); + if (sscanf(color + 1, "%06x", &col) != 1) { + warning("Wrong format of color (%s)", color + 1); + } col |= 0xFF000000; } else { warning("Could not load the built-in icon (%d %s - %s) ", code, color, scummvm_icon[1 + i]); -- cgit v1.2.3 From 9414d7a6e287ff8abfb5746b564e92c8f0e6de58 Mon Sep 17 00:00:00 2001 From: Ori Avtalion Date: Sun, 24 Apr 2011 11:34:27 +0300 Subject: JANITORIAL: Reduce header dependencies in shared code Some backends may break as I only compiled SDL --- backends/platform/sdl/sdl.cpp | 1 + 1 file changed, 1 insertion(+) (limited to 'backends/platform/sdl') diff --git a/backends/platform/sdl/sdl.cpp b/backends/platform/sdl/sdl.cpp index 2c0c45907f..4694a061a3 100644 --- a/backends/platform/sdl/sdl.cpp +++ b/backends/platform/sdl/sdl.cpp @@ -32,6 +32,7 @@ #include "backends/platform/sdl/sdl.h" #include "common/config-manager.h" #include "common/EventRecorder.h" +#include "common/textconsole.h" #include "backends/saves/default/default-saves.h" #include "backends/audiocd/sdl/sdl-audiocd.h" -- cgit v1.2.3 From c6fa23a3d1af0256b43503439abe5c0083c03cfd Mon Sep 17 00:00:00 2001 From: Paul Gilbert Date: Thu, 28 Apr 2011 22:32:12 +1000 Subject: JANITORIAL: Add in necessary include files to fix compilation in MSVC --- backends/platform/sdl/win32/win32.cpp | 2 ++ 1 file changed, 2 insertions(+) (limited to 'backends/platform/sdl') diff --git a/backends/platform/sdl/win32/win32.cpp b/backends/platform/sdl/win32/win32.cpp index 9459263ae2..fffc3a2a75 100644 --- a/backends/platform/sdl/win32/win32.cpp +++ b/backends/platform/sdl/win32/win32.cpp @@ -27,6 +27,8 @@ #define FORBIDDEN_SYMBOL_ALLOW_ALL #include "common/scummsys.h" +#include "common/error.h" +#include "common/textconsole.h" #ifdef WIN32 -- cgit v1.2.3 From 59e77ed66779d33a14a5f4d2a5885a70b793f36f Mon Sep 17 00:00:00 2001 From: Max Horn Date: Mon, 2 May 2011 14:42:08 +0200 Subject: ALL: Mark printf and various other symbols as forbidden Right now, a few places in the frontend code still use printf and consorts. We mark the affected files with a FIXME for now, and add a dedicated exception for each. To be fixed! Also tweak FORBIDDEN_SYMBOL_REPLACEMENT to hopefully really always enforce a compiler error --- backends/platform/sdl/posix/posix.cpp | 3 +++ backends/platform/sdl/sdl.cpp | 3 +++ 2 files changed, 6 insertions(+) (limited to 'backends/platform/sdl') diff --git a/backends/platform/sdl/posix/posix.cpp b/backends/platform/sdl/posix/posix.cpp index 71a88265a0..889bc5cd5e 100644 --- a/backends/platform/sdl/posix/posix.cpp +++ b/backends/platform/sdl/posix/posix.cpp @@ -23,6 +23,8 @@ * */ +#define FORBIDDEN_SYMBOL_EXCEPTION_mkdir + #include "common/scummsys.h" #ifdef UNIX @@ -34,6 +36,7 @@ #include #include + OSystem_POSIX::OSystem_POSIX(Common::String baseConfigName) : _baseConfigName(baseConfigName) { diff --git a/backends/platform/sdl/sdl.cpp b/backends/platform/sdl/sdl.cpp index 4694a061a3..bc27f8e954 100644 --- a/backends/platform/sdl/sdl.cpp +++ b/backends/platform/sdl/sdl.cpp @@ -23,6 +23,9 @@ * */ +#define FORBIDDEN_SYMBOL_EXCEPTION_time_h + + #ifdef WIN32 #define WIN32_LEAN_AND_MEAN #include -- cgit v1.2.3 From 3d4e9fe674d2daf59ff4b481fc2f89f77b390a4f Mon Sep 17 00:00:00 2001 From: Max Horn Date: Tue, 3 May 2011 11:27:44 +0200 Subject: BACKENDS: Allow various files to use stuff from time.h --- backends/platform/sdl/sdl.cpp | 1 - 1 file changed, 1 deletion(-) (limited to 'backends/platform/sdl') diff --git a/backends/platform/sdl/sdl.cpp b/backends/platform/sdl/sdl.cpp index bc27f8e954..e6ca423f61 100644 --- a/backends/platform/sdl/sdl.cpp +++ b/backends/platform/sdl/sdl.cpp @@ -25,7 +25,6 @@ #define FORBIDDEN_SYMBOL_EXCEPTION_time_h - #ifdef WIN32 #define WIN32_LEAN_AND_MEAN #include -- cgit v1.2.3 From 297834017a56140d1a33a4ce642bc9f39f54cf28 Mon Sep 17 00:00:00 2001 From: Johannes Schickel Date: Fri, 22 Apr 2011 00:29:18 +0200 Subject: WIN32: Embed engine data files and theme files into executable. This embeds all the engine data files from dists/engine-data into the executable in case the engines using them are included statically. Furthermore it includes the theme dist files in the executable. --- backends/platform/sdl/win32/win32.cpp | 86 +++++++++++++++++++++++++++++++++++ backends/platform/sdl/win32/win32.h | 1 + 2 files changed, 87 insertions(+) (limited to 'backends/platform/sdl') diff --git a/backends/platform/sdl/win32/win32.cpp b/backends/platform/sdl/win32/win32.cpp index fffc3a2a75..d6a39ff48f 100644 --- a/backends/platform/sdl/win32/win32.cpp +++ b/backends/platform/sdl/win32/win32.cpp @@ -39,6 +39,8 @@ #include "backends/platform/sdl/win32/win32.h" #include "backends/fs/windows/windows-fs-factory.h" +#include "common/memstream.h" + #define DEFAULT_CONFIG_FILE "scummvm.ini" //#define HIDE_CONSOLE @@ -170,4 +172,88 @@ Common::WriteStream *OSystem_Win32::createLogFile() { } } +namespace { + +class Win32ResourceArchive : public Common::Archive { + friend BOOL CALLBACK EnumResNameProc(HMODULE hModule, LPCTSTR lpszType, LPTSTR lpszName, LONG_PTR lParam); +public: + Win32ResourceArchive(); + + virtual bool hasFile(const Common::String &name); + virtual int listMembers(Common::ArchiveMemberList &list); + virtual Common::ArchiveMemberPtr getMember(const Common::String &name); + virtual Common::SeekableReadStream *createReadStreamForMember(const Common::String &name) const; +private: + typedef Common::List FilenameList; + + FilenameList _files; +}; + +BOOL CALLBACK EnumResNameProc(HMODULE hModule, LPCTSTR lpszType, LPTSTR lpszName, LONG_PTR lParam) { + if (IS_INTRESOURCE(lpszName)) + return TRUE; + + Win32ResourceArchive *arch = (Win32ResourceArchive *)lParam; + arch->_files.push_back(lpszName); + return TRUE; +} + +Win32ResourceArchive::Win32ResourceArchive() { + EnumResourceNames(NULL, MAKEINTRESOURCE(256), &EnumResNameProc, (LONG_PTR)this); +} + +bool Win32ResourceArchive::hasFile(const Common::String &name) { + for (FilenameList::const_iterator i = _files.begin(); i != _files.end(); ++i) { + if (i->equalsIgnoreCase(name)) + return true; + } + + return false; +} + +int Win32ResourceArchive::listMembers(Common::ArchiveMemberList &list) { + int count = 0; + + for (FilenameList::const_iterator i = _files.begin(); i != _files.end(); ++i, ++count) + list.push_back(Common::ArchiveMemberPtr(new Common::GenericArchiveMember(*i, this))); + + return count; +} + +Common::ArchiveMemberPtr Win32ResourceArchive::getMember(const Common::String &name) { + return Common::ArchiveMemberPtr(new Common::GenericArchiveMember(name, this)); +} + +Common::SeekableReadStream *Win32ResourceArchive::createReadStreamForMember(const Common::String &name) const { + HRSRC resource = FindResource(NULL, name.c_str(), MAKEINTRESOURCE(256)); + + if (resource == NULL) + return 0; + + HGLOBAL handle = LoadResource(NULL, resource); + + if (handle == NULL) + return 0; + + const byte *data = (const byte *)LockResource(handle); + + if (data == NULL) + return 0; + + uint32 size = SizeofResource(NULL, resource); + + if (size == 0) + return 0; + + return new Common::MemoryReadStream(data, size); +} + +} // End of anonymous namespace + +void OSystem_Win32::addSysArchivesToSearchSet(Common::SearchSet &s, int priority) { + s.add("Win32Res", new Win32ResourceArchive()); + + OSystem_SDL::addSysArchivesToSearchSet(s, priority); +} + #endif diff --git a/backends/platform/sdl/win32/win32.h b/backends/platform/sdl/win32/win32.h index 8379c49437..25cb6bfbba 100644 --- a/backends/platform/sdl/win32/win32.h +++ b/backends/platform/sdl/win32/win32.h @@ -32,6 +32,7 @@ class OSystem_Win32 : public OSystem_SDL { public: virtual void init(); + virtual void addSysArchivesToSearchSet(Common::SearchSet &s, int priority = 0); protected: virtual Common::String getDefaultConfigFileName(); virtual Common::WriteStream *createLogFile(); -- cgit v1.2.3 From e28b402295b92e080274a8b39869dd5f63c195f1 Mon Sep 17 00:00:00 2001 From: Joost Peters Date: Sun, 8 May 2011 01:25:09 +0200 Subject: IRIX: Fix compilation --- backends/platform/sdl/posix/posix.cpp | 1 + 1 file changed, 1 insertion(+) (limited to 'backends/platform/sdl') diff --git a/backends/platform/sdl/posix/posix.cpp b/backends/platform/sdl/posix/posix.cpp index 889bc5cd5e..2208f7c351 100644 --- a/backends/platform/sdl/posix/posix.cpp +++ b/backends/platform/sdl/posix/posix.cpp @@ -24,6 +24,7 @@ */ #define FORBIDDEN_SYMBOL_EXCEPTION_mkdir +#define FORBIDDEN_SYMBOL_EXCEPTION_time_h //On IRIX, sys/stat.h includes sys/time.h #include "common/scummsys.h" -- cgit v1.2.3