diff options
author | Max Horn | 2010-10-30 21:27:42 +0000 |
---|---|---|
committer | Max Horn | 2010-10-30 21:27:42 +0000 |
commit | 44393b2dc8ba78342dcbb7df39eca2e9e1f6e429 (patch) | |
tree | b5b2d7013d64ca317072453a7fbbc391174e2851 | |
parent | ff34a778318355ffba2ee5700524fccba9fe5cf3 (diff) | |
download | scummvm-rg350-44393b2dc8ba78342dcbb7df39eca2e9e1f6e429.tar.gz scummvm-rg350-44393b2dc8ba78342dcbb7df39eca2e9e1f6e429.tar.bz2 scummvm-rg350-44393b2dc8ba78342dcbb7df39eca2e9e1f6e429.zip |
ALL: Add code to help stop people from accidentally using "bad" APIs
A new header file common/forbidden.h is included by scummsys.h and it
re-#defines numerous symbols like fopen(), fread(), system(), etc. with
garbage, in order to provoke compile errors in any code using them.
If a .cpp file really *must* use any of these (e.g. because it is a
backend file), then these redefinitions can be disabled by #defining
FORBIDDEN_SYMBOL_ALLOW_ALL as the first thing in the .cpp file. Whenever
this is done, an explanatory comment should be added.
Note that this system cannot catch all "bad" usages (notably the Lua
code in the sword25 engine), as it can only work if scummsys.h is
included.
svn-id: r53961
-rw-r--r-- | backends/fs/stdiostream.cpp | 3 | ||||
-rw-r--r-- | backends/midi/alsa.cpp | 3 | ||||
-rw-r--r-- | backends/midi/camd.cpp | 3 | ||||
-rw-r--r-- | backends/midi/coreaudio.cpp | 3 | ||||
-rw-r--r-- | backends/midi/coremidi.cpp | 3 | ||||
-rw-r--r-- | backends/midi/dmedia.cpp | 3 | ||||
-rw-r--r-- | backends/midi/seq.cpp | 3 | ||||
-rw-r--r-- | backends/midi/stmidi.cpp | 3 | ||||
-rw-r--r-- | backends/midi/timidity.cpp | 3 | ||||
-rw-r--r-- | backends/midi/windows.cpp | 3 | ||||
-rw-r--r-- | backends/platform/sdl/main.cpp | 2 | ||||
-rw-r--r-- | backends/platform/sdl/sdl.cpp | 5 | ||||
-rw-r--r-- | common/forbidden.h | 147 | ||||
-rw-r--r-- | common/scummsys.h | 1 | ||||
-rw-r--r-- | engines/sword25/gfx/image/pngloader.cpp | 3 | ||||
-rw-r--r-- | engines/sword25/gfx/screenshot.cpp | 3 | ||||
-rw-r--r-- | gui/browser_osx.mm | 3 | ||||
-rw-r--r-- | sound/decoders/flac.cpp | 3 | ||||
-rw-r--r-- | sound/decoders/vorbis.cpp | 5 | ||||
-rw-r--r-- | sound/softsynth/mt32/mt32_file.cpp | 18 | ||||
-rw-r--r-- | sound/softsynth/mt32/mt32_file.h | 2 |
21 files changed, 214 insertions, 8 deletions
diff --git a/backends/fs/stdiostream.cpp b/backends/fs/stdiostream.cpp index 8845d796c6..d0600f41a6 100644 --- a/backends/fs/stdiostream.cpp +++ b/backends/fs/stdiostream.cpp @@ -23,6 +23,9 @@ * */ +// Disable symbol overrides so that we can use FILE, fopen etc. +#define FORBIDDEN_SYMBOL_ALLOW_ALL + #include "backends/fs/stdiostream.h" StdioStream::StdioStream(void *handle) : _handle(handle) { diff --git a/backends/midi/alsa.cpp b/backends/midi/alsa.cpp index 4f73d7384b..fd32777a1b 100644 --- a/backends/midi/alsa.cpp +++ b/backends/midi/alsa.cpp @@ -22,6 +22,9 @@ * $Id$ */ +// Disable symbol overrides so that we can use system headers. +#define FORBIDDEN_SYMBOL_ALLOW_ALL + #include "common/scummsys.h" #if defined(USE_ALSA) diff --git a/backends/midi/camd.cpp b/backends/midi/camd.cpp index 3486532549..7bf702de58 100644 --- a/backends/midi/camd.cpp +++ b/backends/midi/camd.cpp @@ -22,6 +22,9 @@ * $Id$ */ +// Disable symbol overrides so that we can use system headers. +#define FORBIDDEN_SYMBOL_ALLOW_ALL + #include "common/scummsys.h" #if defined(__amigaos4__) diff --git a/backends/midi/coreaudio.cpp b/backends/midi/coreaudio.cpp index aa0ad75f0a..97db5cb292 100644 --- a/backends/midi/coreaudio.cpp +++ b/backends/midi/coreaudio.cpp @@ -24,6 +24,9 @@ #ifdef MACOSX +// Disable symbol overrides so that we can use system headers. +#define FORBIDDEN_SYMBOL_ALLOW_ALL + // HACK to disable deprecated warnings under Mac OS X 10.5. // Apple depracted the AUGraphNewNode & AUGraphGetNodeInfo APIs // in favor of the new AUGraphAddNode & AUGraphNodeInfo APIs. diff --git a/backends/midi/coremidi.cpp b/backends/midi/coremidi.cpp index 08f36a8b0f..bca16df61a 100644 --- a/backends/midi/coremidi.cpp +++ b/backends/midi/coremidi.cpp @@ -24,6 +24,9 @@ #ifdef MACOSX +// Disable symbol overrides so that we can use system headers. +#define FORBIDDEN_SYMBOL_ALLOW_ALL + #include "common/config-manager.h" #include "common/util.h" #include "sound/musicplugin.h" diff --git a/backends/midi/dmedia.cpp b/backends/midi/dmedia.cpp index 8c006b2cd9..5e4088fa17 100644 --- a/backends/midi/dmedia.cpp +++ b/backends/midi/dmedia.cpp @@ -29,6 +29,9 @@ #if defined(IRIX) +// Disable symbol overrides so that we can use system headers. +#define FORBIDDEN_SYMBOL_ALLOW_ALL + #include "common/scummsys.h" #include "common/util.h" #include "common/config-manager.h" diff --git a/backends/midi/seq.cpp b/backends/midi/seq.cpp index e3d2c35b39..c0098742d0 100644 --- a/backends/midi/seq.cpp +++ b/backends/midi/seq.cpp @@ -28,6 +28,9 @@ * both the QuickTime support and (vkeybd http://www.alsa-project.org/~iwai/alsa.html) */ +// Disable symbol overrides so that we can use system headers. +#define FORBIDDEN_SYMBOL_ALLOW_ALL + #include "common/scummsys.h" #if defined(USE_SEQ_MIDI) diff --git a/backends/midi/stmidi.cpp b/backends/midi/stmidi.cpp index b00188dfea..01e28aa5ca 100644 --- a/backends/midi/stmidi.cpp +++ b/backends/midi/stmidi.cpp @@ -36,6 +36,9 @@ #if defined __MINT__ +// Disable symbol overrides so that we can use system headers. +#define FORBIDDEN_SYMBOL_ALLOW_ALL + #include <osbind.h> #include "sound/mpu401.h" #include "common/util.h" diff --git a/backends/midi/timidity.cpp b/backends/midi/timidity.cpp index 16c1cc43be..d79a83809f 100644 --- a/backends/midi/timidity.cpp +++ b/backends/midi/timidity.cpp @@ -34,6 +34,9 @@ * */ +// Disable symbol overrides so that we can use system headers. +#define FORBIDDEN_SYMBOL_ALLOW_ALL + #include "common/scummsys.h" #if defined(USE_TIMIDITY) diff --git a/backends/midi/windows.cpp b/backends/midi/windows.cpp index 31f057df18..81b29219b4 100644 --- a/backends/midi/windows.cpp +++ b/backends/midi/windows.cpp @@ -24,6 +24,9 @@ #if defined(WIN32) && !defined(_WIN32_WCE) +// Disable symbol overrides so that we can use system headers. +#define FORBIDDEN_SYMBOL_ALLOW_ALL + #define WIN32_LEAN_AND_MEAN #include <windows.h> // winnt.h defines ARRAYSIZE, but we want our own one... diff --git a/backends/platform/sdl/main.cpp b/backends/platform/sdl/main.cpp index 60bf59689c..a9e1f5cf4b 100644 --- a/backends/platform/sdl/main.cpp +++ b/backends/platform/sdl/main.cpp @@ -23,6 +23,8 @@ * */ +#define FORBIDDEN_SYMBOL_ALLOW_ALL + // Fix for bug #2895217 "MSVC compilation broken with r47595": // We need to keep this on top of the "common/scummsys.h" include, // otherwise we will get errors about the windows headers redefining diff --git a/backends/platform/sdl/sdl.cpp b/backends/platform/sdl/sdl.cpp index 83393c225a..8725a7df8a 100644 --- a/backends/platform/sdl/sdl.cpp +++ b/backends/platform/sdl/sdl.cpp @@ -23,6 +23,9 @@ * */ +// Disable symbol overrides so that we can use system headers. +#define FORBIDDEN_SYMBOL_ALLOW_ALL + #if defined(WIN32) #define WIN32_LEAN_AND_MEAN #include <windows.h> @@ -79,7 +82,7 @@ #endif #if defined(MACOSX) || defined(IPHONE) -#include "CoreFoundation/CoreFoundation.h" +#include <CoreFoundation/CoreFoundation.h> #endif diff --git a/common/forbidden.h b/common/forbidden.h new file mode 100644 index 0000000000..cc71c36711 --- /dev/null +++ b/common/forbidden.h @@ -0,0 +1,147 @@ +/* ScummVM - Graphic Adventure Engine + * + * ScummVM is the legal property of its developers, whose names + * are too numerous to list here. Please refer to the COPYRIGHT + * file distributed with this source distribution. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * $URL$ + * $Id$ + * + */ + +#ifndef COMMON_FORBIDDEN_H +#define COMMON_FORBIDDEN_H + + +// +// Backend files may #define FORBIDDEN_SYMBOL_ALLOW_ALL if they +// have to access functions like fopen, fread etc. +// Regular code, esp. code in engines/, should never do that. +// + +#ifndef FORBIDDEN_SYMBOL_ALLOW_ALL + +#define FORBIDDEN_SYMBOL_REPLACEMENT FORBIDDEN SYMBOL! + + +/* +#ifndef FORBIDDEN_SYMBOL_EXCEPTION_printf +#undef printf +#define printf FORBIDDEN_SYMBOL_REPLACEMENT +#endif + +#ifndef FORBIDDEN_SYMBOL_EXCEPTION_fprintf +#undef fprintf +#define fprintf FORBIDDEN_SYMBOL_REPLACEMENT +#endif +*/ + +#ifndef FORBIDDEN_SYMBOL_EXCEPTION_FILE +#undef FILE +#define FILE FORBIDDEN_SYMBOL_REPLACEMENT +#endif + +#ifndef FORBIDDEN_SYMBOL_EXCEPTION_fopen +#undef fopen +#define fopen(a,b) FORBIDDEN_SYMBOL_REPLACEMENT +#endif + +#ifndef FORBIDDEN_SYMBOL_EXCEPTION_fclose +#undef fclose +#define fclose(a) FORBIDDEN_SYMBOL_REPLACEMENT +#endif + +#ifndef FORBIDDEN_SYMBOL_EXCEPTION_fread +#undef fread +#define fread(a,b,c,d) FORBIDDEN_SYMBOL_REPLACEMENT +#endif + +#ifndef FORBIDDEN_SYMBOL_EXCEPTION_fwrite +#undef fwrite +#define fwrite(a,b,c,d) FORBIDDEN_SYMBOL_REPLACEMENT +#endif + +#ifndef FORBIDDEN_SYMBOL_EXCEPTION_fseek +#undef fseek +#define fseek(a,b,c) FORBIDDEN_SYMBOL_REPLACEMENT +#endif + +#ifndef FORBIDDEN_SYMBOL_EXCEPTION_ftell +#undef ftell +#define ftell(a) FORBIDDEN_SYMBOL_REPLACEMENT +#endif + +#ifndef FORBIDDEN_SYMBOL_EXCEPTION_feof +#undef feof +#define feof(a) FORBIDDEN_SYMBOL_REPLACEMENT +#endif + +#ifndef FORBIDDEN_SYMBOL_EXCEPTION_fgetc +#undef fgetc +#define fgetc(a) FORBIDDEN_SYMBOL_REPLACEMENT +#endif + +#ifndef FORBIDDEN_SYMBOL_EXCEPTION_fputc +#undef fputc +#define fputc(a,b) FORBIDDEN_SYMBOL_REPLACEMENT +#endif + + +#ifndef FORBIDDEN_SYMBOL_EXCEPTION_setjmp +#undef setjmp +#define setjmp(a) FORBIDDEN_SYMBOL_REPLACEMENT +#endif + +#ifndef FORBIDDEN_SYMBOL_EXCEPTION_longjmp +#undef longjmp +#define longjmp(a,b) FORBIDDEN_SYMBOL_REPLACEMENT +#endif + +#ifndef FORBIDDEN_SYMBOL_EXCEPTION_system +#undef system +#define system(a) FORBIDDEN_SYMBOL_REPLACEMENT +#endif + + +/* +time_t + +time + +difftime + +mktime + +localtime + +clock + +gmtime + +system + +remove + +setlocale + +setvbuf +*/ + +#endif + + +#endif diff --git a/common/scummsys.h b/common/scummsys.h index 3acf3b4b3b..d168544b18 100644 --- a/common/scummsys.h +++ b/common/scummsys.h @@ -437,5 +437,6 @@ typedef uint16 OverlayColor; #endif +#include <common/forbidden.h> #endif diff --git a/engines/sword25/gfx/image/pngloader.cpp b/engines/sword25/gfx/image/pngloader.cpp index efe5817305..1b72595a8f 100644 --- a/engines/sword25/gfx/image/pngloader.cpp +++ b/engines/sword25/gfx/image/pngloader.cpp @@ -32,6 +32,9 @@ * */ +// Disable symbol overrides so that we can use png.h +#define FORBIDDEN_SYMBOL_ALLOW_ALL + #include "sword25/gfx/image/image.h" #include "sword25/gfx/image/pngloader.h" #include <png.h> diff --git a/engines/sword25/gfx/screenshot.cpp b/engines/sword25/gfx/screenshot.cpp index 74174cbcd9..88417b72c5 100644 --- a/engines/sword25/gfx/screenshot.cpp +++ b/engines/sword25/gfx/screenshot.cpp @@ -32,6 +32,9 @@ * */ +// Disable symbol overrides so that we can use png.h +#define FORBIDDEN_SYMBOL_ALLOW_ALL + #define BS_LOG_PREFIX "SCREENSHOT" #include "common/system.h" diff --git a/gui/browser_osx.mm b/gui/browser_osx.mm index a3a09b8ed2..ea77e16c04 100644 --- a/gui/browser_osx.mm +++ b/gui/browser_osx.mm @@ -22,6 +22,9 @@ * $Id$ */ +// Disable symbol overrides so that we can use system headers +#define FORBIDDEN_SYMBOL_ALLOW_ALL + #include "gui/browser.h" #include "gui/GuiManager.h" #include "gui/ListWidget.h" diff --git a/sound/decoders/flac.cpp b/sound/decoders/flac.cpp index d01e0d0a79..65f3306106 100644 --- a/sound/decoders/flac.cpp +++ b/sound/decoders/flac.cpp @@ -23,6 +23,9 @@ * */ +// Disable symbol overrides for FILE as that is used in FLAC headers +#define FORBIDDEN_SYMBOL_EXCEPTION_FILE + #include "sound/decoders/flac.h" #ifdef USE_FLAC diff --git a/sound/decoders/vorbis.cpp b/sound/decoders/vorbis.cpp index 7673c53010..ee31bbc38d 100644 --- a/sound/decoders/vorbis.cpp +++ b/sound/decoders/vorbis.cpp @@ -23,6 +23,11 @@ * */ +// Disable symbol overrides for FILE and fseek as those are used in the +// Vorbis headers. +#define FORBIDDEN_SYMBOL_EXCEPTION_FILE +#define FORBIDDEN_SYMBOL_EXCEPTION_fseek + #include "sound/decoders/vorbis.h" #ifdef USE_VORBIS diff --git a/sound/softsynth/mt32/mt32_file.cpp b/sound/softsynth/mt32/mt32_file.cpp index f4eba73d33..ce5c2874c4 100644 --- a/sound/softsynth/mt32/mt32_file.cpp +++ b/sound/softsynth/mt32/mt32_file.cpp @@ -19,6 +19,12 @@ * IN THE SOFTWARE. */ + +// FIXME: Disable symbol overrides so that we can use system headers. +// But we *really* should get rid of this usage of FILE, fopen etc. +#define FORBIDDEN_SYMBOL_ALLOW_ALL + + #include <stdio.h> #include "mt32emu.h" @@ -37,15 +43,15 @@ namespace MT32Emu { } void ANSIFile::close() { - fclose(fp); + fclose((FILE *)fp); } size_t ANSIFile::read(void *in, size_t size) { - return fread(in, 1, size, fp); + return fread(in, 1, size, (FILE *)fp); } bool ANSIFile::readBit8u(Bit8u *in) { - int c = fgetc(fp); + int c = fgetc((FILE *)fp); if (c == EOF) return false; *in = (Bit8u)c; @@ -69,11 +75,11 @@ namespace MT32Emu { } size_t ANSIFile::write(const void *out, size_t size) { - return fwrite(out, 1, size, fp); + return fwrite(out, 1, size, (FILE *)fp); } bool ANSIFile::writeBit8u(Bit8u out) { - return fputc(out, fp) != EOF; + return fputc(out, (FILE *)fp) != EOF; } bool File::writeBit16u(Bit16u out) { @@ -103,6 +109,6 @@ namespace MT32Emu { } bool ANSIFile::isEOF() { - return feof(fp) != 0; + return feof((FILE *)fp) != 0; } } diff --git a/sound/softsynth/mt32/mt32_file.h b/sound/softsynth/mt32/mt32_file.h index 27c8ccbe46..b311ad9626 100644 --- a/sound/softsynth/mt32/mt32_file.h +++ b/sound/softsynth/mt32/mt32_file.h @@ -49,7 +49,7 @@ public: class ANSIFile: public File { private: - FILE *fp; + void *fp; public: bool open(const char *filename, OpenMode mode); void close(); |