[Scummvm-cvs-logs] scummvm master -> e35b4f20c1041b13361aa2ebc4e758873bb1cee3

lordhoto lordhoto at gmail.com
Sun Aug 7 15:27:12 CEST 2011


This automated email contains information about 23 new commits which have been
pushed to the 'scummvm' repo located at https://github.com/scummvm/scummvm .

Summary:
17044f0784 COMMON: Simplify initialization of z_stream struct.
b3997f0562 COMMON: Use ScopedPtr<> to simplify resource management.
84220d2ca0 COMMON: Remove superfluous Common:: qualifiers.
79729d03e0 COMMON: Use correct format specifier.
c876e87efc COMMON: Correct error message.
97a6ee2e64 AUDIO: #define OV_EXCLUDE_STATIC_CALLBACKS to not get unnecessary static data, which causes warnings.
c6d5d74835 COMMON: Make constants actually const.
08ad90edf6 TSAGE: Reduce scope of variable.
715c07930d CRUISE: Replace casts and offset calculations for memory debugger by a simple struct.
0a458019b3 AGOS: Replace if-cascade by switch.
5f4d83c38d AGOS: Correct off-by-one error in range check for setting the debug level.
f3afb32ee6 SCI: Remove unnecessary cast.
0e6751372a SCI: Simplify allocation of ResourceManager.
a5675c3dbe TEENAGENT: Pass streams as references.
c21f87836e PSP: Pass the stream as reference to PngLoader.
2f23ff72c1 COMMON: Remove implicit conversion from ScopedPtr<T> to T*.
a5a8833c05 COMMON: Add DisposablePtr<T>, which replaces many repeated implementations of a dispose flag.
e3e0a317e7 AUDIO: Simplify complicated loop condition.
ab80b20a30 COMMON: Replace x + ARRAYSIZE(x) by the simpler ARRAYEND(x).
3ee307e6b3 KYRA: Simplify initializing a buffer with a string.
d1688d22d4 AUDIO: Simplify iterating backwards over an array.
b4b6ce0954 ALL: Use Graphics::skipThumbnail() where appropriate.
e35b4f20c1 GRAPHICS: Simplify the interface of Graphics::loadThumbnail().


Commit: 17044f0784724e0e6cf79dd947569e307dc70366
    https://github.com/scummvm/scummvm/commit/17044f0784724e0e6cf79dd947569e307dc70366
Author: Christoph Mallon (christoph.mallon at gmx.de)
Date: 2011-08-07T06:19:06-07:00

Commit Message:
COMMON: Simplify initialization of z_stream struct.

Changed paths:
    common/zlib.cpp



diff --git a/common/zlib.cpp b/common/zlib.cpp
index 71a25bd..2b37506 100644
--- a/common/zlib.cpp
+++ b/common/zlib.cpp
@@ -70,15 +70,9 @@ protected:
 
 public:
 
-	GZipReadStream(Common::SeekableReadStream *w) : _wrapped(w) {
+	GZipReadStream(Common::SeekableReadStream *w) : _wrapped(w), _stream() {
 		assert(w != 0);
 
-		_stream.zalloc = Z_NULL;
-		_stream.zfree = Z_NULL;
-		_stream.opaque = Z_NULL;
-		_stream.avail_in = 0;
-		_stream.next_in = Z_NULL;
-
 		// Verify file header is correct
 		w->seek(0, SEEK_SET);
 		uint16 header = w->readUint16BE();
@@ -230,11 +224,8 @@ protected:
 	}
 
 public:
-	GZipWriteStream(Common::WriteStream *w) : _wrapped(w) {
+	GZipWriteStream(Common::WriteStream *w) : _wrapped(w), _stream() {
 		assert(w != 0);
-		_stream.zalloc = Z_NULL;
-		_stream.zfree = Z_NULL;
-		_stream.opaque = Z_NULL;
 
 		// Adding 16 to windowBits indicates to zlib that it is supposed to
 		// write gzip headers. This feature was added in zlib 1.2.0.4,


Commit: b3997f0562e31f41716ecaff24cc3431925f0029
    https://github.com/scummvm/scummvm/commit/b3997f0562e31f41716ecaff24cc3431925f0029
Author: Christoph Mallon (christoph.mallon at gmx.de)
Date: 2011-08-07T06:19:07-07:00

Commit Message:
COMMON: Use ScopedPtr<> to simplify resource management.

Changed paths:
    common/zlib.cpp



diff --git a/common/zlib.cpp b/common/zlib.cpp
index 2b37506..1048430 100644
--- a/common/zlib.cpp
+++ b/common/zlib.cpp
@@ -24,6 +24,7 @@
 #define FORBIDDEN_SYMBOL_ALLOW_ALL
 
 #include "common/zlib.h"
+#include "common/ptr.h"
 #include "common/util.h"
 #include "common/stream.h"
 
@@ -61,7 +62,7 @@ protected:
 
 	byte	_buf[BUFSIZE];
 
-	Common::SeekableReadStream *_wrapped;
+	ScopedPtr<SeekableReadStream> _wrapped;
 	z_stream _stream;
 	int _zlibErr;
 	uint32 _pos;
@@ -107,7 +108,6 @@ public:
 
 	~GZipReadStream() {
 		inflateEnd(&_stream);
-		delete _wrapped;
 	}
 
 	bool err() const { return (_zlibErr != Z_OK) && (_zlibErr != Z_STREAM_END); }
@@ -204,7 +204,7 @@ protected:
 	};
 
 	byte	_buf[BUFSIZE];
-	Common::WriteStream *_wrapped;
+	ScopedPtr<WriteStream> _wrapped;
 	z_stream _stream;
 	int _zlibErr;
 
@@ -248,7 +248,6 @@ public:
 	~GZipWriteStream() {
 		finalize();
 		deflateEnd(&_stream);
-		delete _wrapped;
 	}
 
 	bool err() const {


Commit: 84220d2ca05707f22a0242b1745caf0b657237a3
    https://github.com/scummvm/scummvm/commit/84220d2ca05707f22a0242b1745caf0b657237a3
Author: Christoph Mallon (christoph.mallon at gmx.de)
Date: 2011-08-07T06:19:07-07:00

Commit Message:
COMMON: Remove superfluous Common:: qualifiers.

Changed paths:
    common/EventDispatcher.cpp
    common/algorithm.h
    common/archive.cpp
    common/archive.h
    common/array.h
    common/config-file.cpp
    common/config-file.h
    common/config-manager.cpp
    common/config-manager.h
    common/dcl.cpp
    common/events.h
    common/file.cpp
    common/file.h
    common/fs.cpp
    common/func.h
    common/huffman.h
    common/iff_container.cpp
    common/iff_container.h
    common/ptr.h
    common/quicktime.cpp
    common/quicktime.h
    common/rational.cpp
    common/serializer.h
    common/str.h
    common/unarj.cpp
    common/unzip.cpp
    common/util.cpp
    common/util.h
    common/winexe_pe.cpp
    common/xmlparser.cpp
    common/xmlparser.h
    common/zlib.cpp



diff --git a/common/EventDispatcher.cpp b/common/EventDispatcher.cpp
index d317718..ce1ef0c 100644
--- a/common/EventDispatcher.cpp
+++ b/common/EventDispatcher.cpp
@@ -28,12 +28,12 @@ EventDispatcher::EventDispatcher() : _mapper(0) {
 }
 
 EventDispatcher::~EventDispatcher() {
-	for (Common::List<SourceEntry>::iterator i = _sources.begin(); i != _sources.end(); ++i) {
+	for (List<SourceEntry>::iterator i = _sources.begin(); i != _sources.end(); ++i) {
 		if (i->autoFree)
 			delete i->source;
 	}
 
-	for (Common::List<ObserverEntry>::iterator i = _observers.begin(); i != _observers.end(); ++i) {
+	for (List<ObserverEntry>::iterator i = _observers.begin(); i != _observers.end(); ++i) {
 		if (i->autoFree)
 			delete i->observer;
 	}
@@ -43,9 +43,9 @@ EventDispatcher::~EventDispatcher() {
 }
 
 void EventDispatcher::dispatch() {
-	Common::Event event;
+	Event event;
 
-	for (Common::List<SourceEntry>::iterator i = _sources.begin(); i != _sources.end(); ++i) {
+	for (List<SourceEntry>::iterator i = _sources.begin(); i != _sources.end(); ++i) {
 		const bool allowMapping = i->source->allowMapping();
 
 		while (i->source->pollEvent(event)) {
@@ -83,7 +83,7 @@ void EventDispatcher::registerSource(EventSource *source, bool autoFree) {
 }
 
 void EventDispatcher::unregisterSource(EventSource *source) {
-	for (Common::List<SourceEntry>::iterator i = _sources.begin(); i != _sources.end(); ++i) {
+	for (List<SourceEntry>::iterator i = _sources.begin(); i != _sources.end(); ++i) {
 		if (i->source == source) {
 			if (i->autoFree)
 				delete source;
@@ -101,7 +101,7 @@ void EventDispatcher::registerObserver(EventObserver *obs, uint priority, bool a
 	newEntry.priority = priority;
 	newEntry.autoFree = autoFree;
 
-	for (Common::List<ObserverEntry>::iterator i = _observers.begin(); i != _observers.end(); ++i) {
+	for (List<ObserverEntry>::iterator i = _observers.begin(); i != _observers.end(); ++i) {
 		if (i->priority < priority) {
 			_observers.insert(i, newEntry);
 			return;
@@ -112,7 +112,7 @@ void EventDispatcher::registerObserver(EventObserver *obs, uint priority, bool a
 }
 
 void EventDispatcher::unregisterObserver(EventObserver *obs) {
-	for (Common::List<ObserverEntry>::iterator i = _observers.begin(); i != _observers.end(); ++i) {
+	for (List<ObserverEntry>::iterator i = _observers.begin(); i != _observers.end(); ++i) {
 		if (i->observer == obs) {
 			if (i->autoFree)
 				delete obs;
@@ -124,7 +124,7 @@ void EventDispatcher::unregisterObserver(EventObserver *obs) {
 }
 
 void EventDispatcher::dispatchEvent(const Event &event) {
-	for (Common::List<ObserverEntry>::iterator i = _observers.begin(); i != _observers.end(); ++i) {
+	for (List<ObserverEntry>::iterator i = _observers.begin(); i != _observers.end(); ++i) {
 		if (i->observer->notifyEvent(event))
 			break;
 	}
diff --git a/common/algorithm.h b/common/algorithm.h
index 40ba605..e7ccef4 100644
--- a/common/algorithm.h
+++ b/common/algorithm.h
@@ -226,12 +226,12 @@ void sort(T first, T last, StrictWeakOrdering comp) {
  */
 template<typename T>
 void sort(T *first, T *last) {
-	sort(first, last, Common::Less<T>());
+	sort(first, last, Less<T>());
 }
 
 template<class T>
 void sort(T first, T last) {
-	sort(first, last, Common::Less<typename T::ValueType>());
+	sort(first, last, Less<typename T::ValueType>());
 }
 
 // MSVC is complaining about the minus operator being applied to an unsigned type
diff --git a/common/archive.cpp b/common/archive.cpp
index ad5e1a8..954de8b 100644
--- a/common/archive.cpp
+++ b/common/archive.cpp
@@ -147,7 +147,7 @@ void SearchSet::addSubDirectoriesMatching(const FSNode &directory, String origPa
 	for (FSList::const_iterator i = subDirs.begin(); i != subDirs.end(); ++i) {
 		String name = i->getName();
 
-		if (Common::matchString(name.c_str(), pattern.c_str(), ignoreCase)) {
+		if (matchString(name.c_str(), pattern.c_str(), ignoreCase)) {
 			matchIter = multipleMatches.find(name);
 			if (matchIter == multipleMatches.end()) {
 				multipleMatches[name] = true;
diff --git a/common/archive.h b/common/archive.h
index 8400c56..c8e78f9 100644
--- a/common/archive.h
+++ b/common/archive.h
@@ -254,7 +254,7 @@ public:
 	virtual void clear();
 
 private:
-	friend class Common::Singleton<SingletonBaseType>;
+	friend class Singleton<SingletonBaseType>;
 	SearchManager();
 };
 
diff --git a/common/array.h b/common/array.h
index e543409..af1fe57 100644
--- a/common/array.h
+++ b/common/array.h
@@ -42,7 +42,7 @@ namespace Common {
  * management scheme. There, only elements that 'live' are actually constructed
  * (i.e., have their constructor called), and objects that are removed are
  * immediately destructed (have their destructor called).
- * With Common::Array, this is not the case; instead, it simply uses new[] and
+ * With Array, this is not the case; instead, it simply uses new[] and
  * delete[] to allocate whole blocks of objects, possibly more than are
  * currently 'alive'. This simplifies memory management, but may have
  * undesirable side effects when one wants to use an Array of complex
diff --git a/common/config-file.cpp b/common/config-file.cpp
index ea3feff..1ebd9b5 100644
--- a/common/config-file.cpp
+++ b/common/config-file.cpp
@@ -36,7 +36,7 @@ namespace Common {
  * underscores. In particular, white space and "#", "=", "[", "]"
  * are not valid!
  */
-bool ConfigFile::isValidName(const Common::String &name) {
+bool ConfigFile::isValidName(const String &name) {
 	const char *p = name.c_str();
 	while (*p && (isalnum(static_cast<unsigned char>(*p)) || *p == '-' || *p == '_' || *p == '.'))
 		p++;
diff --git a/common/config-file.h b/common/config-file.h
index d28ad34..7bc5604 100644
--- a/common/config-file.h
+++ b/common/config-file.h
@@ -93,7 +93,7 @@ public:
 	 * underscores. In particular, white space and "#", "=", "[", "]"
 	 * are not valid!
 	 */
-	static bool isValidName(const Common::String &name);
+	static bool isValidName(const String &name);
 
 	/** Reset everything stored in this config file. */
 	void	clear();
diff --git a/common/config-manager.cpp b/common/config-manager.cpp
index 1064ecf..874aee1 100644
--- a/common/config-manager.cpp
+++ b/common/config-manager.cpp
@@ -112,7 +112,7 @@ void ConfigManager::loadConfigFile(const String &filename) {
  * Add a ready-made domain based on its name and contents
  * The domain name should not already exist in the ConfigManager.
  **/
-void ConfigManager::addDomain(const Common::String &domainName, const ConfigManager::Domain &domain) {
+void ConfigManager::addDomain(const String &domainName, const ConfigManager::Domain &domain) {
 	if (domainName.empty())
 		return;
 	if (domainName == kApplicationDomain) {
@@ -492,7 +492,7 @@ int ConfigManager::getInt(const String &key, const String &domName) const {
 bool ConfigManager::getBool(const String &key, const String &domName) const {
 	String value(get(key, domName));
 	bool val;
-	if (Common::parseBool(value, val))
+	if (parseBool(value, val))
 		return val;
 
 	error("ConfigManager::getBool(%s,%s): '%s' is not a valid bool",
diff --git a/common/config-manager.h b/common/config-manager.h
index 78a62b9..e04041d 100644
--- a/common/config-manager.h
+++ b/common/config-manager.h
@@ -153,7 +153,7 @@ private:
 	ConfigManager();
 
 	void			loadFromStream(SeekableReadStream &stream);
-	void			addDomain(const Common::String &domainName, const Domain &domain);
+	void			addDomain(const String &domainName, const Domain &domain);
 	void			writeDomain(WriteStream &stream, const String &name, const Domain &domain);
 	void			renameDomain(const String &oldName, const String &newName, DomainMap &map);
 
diff --git a/common/dcl.cpp b/common/dcl.cpp
index b75f7f3..1879be9 100644
--- a/common/dcl.cpp
+++ b/common/dcl.cpp
@@ -30,7 +30,7 @@ namespace Common {
 
 class DecompressorDCL {
 public:
-	bool unpack(Common::ReadStream *src, byte *dest, uint32 nPacked, uint32 nUnpacked);
+	bool unpack(ReadStream *src, byte *dest, uint32 nPacked, uint32 nUnpacked);
 
 protected:
 	/**
@@ -41,7 +41,7 @@ protected:
 	 * @param nUnpacket	size of unpacked data
 	 * @return 0 on success, non-zero on error
 	 */
-	void init(Common::ReadStream *src, byte *dest, uint32 nPacked, uint32 nUnpacked);
+	void init(ReadStream *src, byte *dest, uint32 nPacked, uint32 nUnpacked);
 
 	/**
 	 * Get a number of bits from _src stream, starting with the least
@@ -73,12 +73,11 @@ protected:
 	uint32 _szUnpacked;	///< size of the decompressed data
 	uint32 _dwRead;		///< number of bytes read from _src
 	uint32 _dwWrote;	///< number of bytes written to _dest
-	Common::ReadStream *_src;
+	ReadStream *_src;
 	byte *_dest;
 };
 
-void DecompressorDCL::init(Common::ReadStream *src, byte *dest, uint32 nPacked,
-                        uint32 nUnpacked) {
+void DecompressorDCL::init(ReadStream *src, byte *dest, uint32 nPacked, uint32 nUnpacked) {
 	_src = src;
 	_dest = dest;
 	_szPacked = nPacked;
@@ -333,7 +332,7 @@ int DecompressorDCL::huffman_lookup(const int *tree) {
 #define DCL_BINARY_MODE 0
 #define DCL_ASCII_MODE 1
 
-bool DecompressorDCL::unpack(Common::ReadStream *src, byte *dest, uint32 nPacked, uint32 nUnpacked) {
+bool DecompressorDCL::unpack(ReadStream *src, byte *dest, uint32 nPacked, uint32 nUnpacked) {
 	init(src, dest, nPacked, nUnpacked);
 
 	int value;
diff --git a/common/events.h b/common/events.h
index 371080c..7df2731 100644
--- a/common/events.h
+++ b/common/events.h
@@ -97,7 +97,7 @@ struct Event {
 	 * Virtual screen coordinates means: the coordinate system of the
 	 * screen area as defined by the most recent call to initSize().
 	 */
-	Common::Point mouse;
+	Point mouse;
 
 	Event() : type(EVENT_INVALID), synthetic(false) {}
 };
@@ -139,13 +139,13 @@ public:
  */
 class ArtificialEventSource : public EventSource {
 protected:
-	Common::Queue<Common::Event> _artificialEventQueue;
+	Queue<Event> _artificialEventQueue;
 public:
-	void addEvent(const Common::Event &ev) {
+	void addEvent(const Event &ev) {
 		_artificialEventQueue.push(ev);
 	}
 
-	bool pollEvent(Common::Event &ev) {
+	bool pollEvent(Event &ev) {
 	if (!_artificialEventQueue.empty()) {
 			ev = _artificialEventQueue.pop();
 			return true;
@@ -275,14 +275,14 @@ private:
 		EventSource *source;
 	};
 
-	Common::List<SourceEntry> _sources;
+	List<SourceEntry> _sources;
 
 	struct ObserverEntry : public Entry {
 		uint priority;
 		EventObserver *observer;
 	};
 
-	Common::List<ObserverEntry> _observers;
+	List<ObserverEntry> _observers;
 
 	void dispatchEvent(const Event &event);
 };
@@ -315,15 +315,15 @@ public:
 	 * @param event	point to an Event struct, which will be filled with the event data.
 	 * @return true if an event was retrieved.
 	 */
-	virtual bool pollEvent(Common::Event &event) = 0;
+	virtual bool pollEvent(Event &event) = 0;
 
 	/**
 	 * Pushes a "fake" event into the event queue
 	 */
-	virtual void pushEvent(const Common::Event &event) = 0;
+	virtual void pushEvent(const Event &event) = 0;
 
 	/** Return the current mouse position */
-	virtual Common::Point getMousePos() const = 0;
+	virtual Point getMousePos() const = 0;
 
 	/**
 	 * Return a bitmask with the button states:
@@ -362,7 +362,7 @@ public:
 	// TODO: Consider removing OSystem::getScreenChangeID and
 	// replacing it by a generic getScreenChangeID method here
 #ifdef ENABLE_KEYMAPPER
-	virtual Common::Keymapper *getKeymapper() = 0;
+	virtual Keymapper *getKeymapper() = 0;
 #endif
 
 	enum {
diff --git a/common/file.cpp b/common/file.cpp
index 381bf12..12d73c9 100644
--- a/common/file.cpp
+++ b/common/file.cpp
@@ -72,7 +72,7 @@ bool File::open(const FSNode &node) {
 	return open(stream, node.getPath());
 }
 
-bool File::open(SeekableReadStream *stream, const Common::String &name) {
+bool File::open(SeekableReadStream *stream, const String &name) {
 	assert(!_handle);
 
 	if (stream) {
diff --git a/common/file.h b/common/file.h
index 86c67c0..b6319df 100644
--- a/common/file.h
+++ b/common/file.h
@@ -97,7 +97,7 @@ public:
 	 * @param	name		a string describing the 'file' corresponding to stream
 	 * @return	true if stream was non-zero, false otherwise
 	 */
-	virtual bool open(SeekableReadStream *stream, const Common::String &name);
+	virtual bool open(SeekableReadStream *stream, const String &name);
 
 	/**
 	 * Close the file, if open.
diff --git a/common/fs.cpp b/common/fs.cpp
index 3dc8c28..8aa1115 100644
--- a/common/fs.cpp
+++ b/common/fs.cpp
@@ -33,7 +33,7 @@ FSNode::FSNode(AbstractFSNode *realNode)
 	: _realNode(realNode) {
 }
 
-FSNode::FSNode(const Common::String &p) {
+FSNode::FSNode(const String &p) {
 	assert(g_system);
 	FilesystemFactory *factory = g_system->getFilesystemFactory();
 	AbstractFSNode *tmp = 0;
@@ -42,7 +42,7 @@ FSNode::FSNode(const Common::String &p) {
 		tmp = factory->makeCurrentDirectoryFileNode();
 	else
 		tmp = factory->makeFileNodePath(p);
-	_realNode = Common::SharedPtr<AbstractFSNode>(tmp);
+	_realNode = SharedPtr<AbstractFSNode>(tmp);
 }
 
 bool FSNode::operator<(const FSNode& node) const {
@@ -59,7 +59,7 @@ bool FSNode::exists() const {
 	return _realNode && _realNode->exists();
 }
 
-FSNode FSNode::getChild(const Common::String &n) const {
+FSNode FSNode::getChild(const String &n) const {
 	// If this node is invalid or not a directory, return an invalid node
 	if (_realNode == 0 || !_realNode->isDirectory())
 		return FSNode();
@@ -85,12 +85,12 @@ bool FSNode::getChildren(FSList &fslist, ListMode mode, bool hidden) const {
 	return true;
 }
 
-Common::String FSNode::getDisplayName() const {
+String FSNode::getDisplayName() const {
 	assert(_realNode);
 	return _realNode->getDisplayName();
 }
 
-Common::String FSNode::getName() const {
+String FSNode::getName() const {
 	assert(_realNode);
 	return _realNode->getName();
 }
@@ -107,7 +107,7 @@ FSNode FSNode::getParent() const {
 	}
 }
 
-Common::String FSNode::getPath() const {
+String FSNode::getPath() const {
 	assert(_realNode);
 	return _realNode->getPath();
 }
@@ -124,7 +124,7 @@ bool FSNode::isWritable() const {
 	return _realNode && _realNode->isWritable();
 }
 
-Common::SeekableReadStream *FSNode::createReadStream() const {
+SeekableReadStream *FSNode::createReadStream() const {
 	if (_realNode == 0)
 		return 0;
 
@@ -139,7 +139,7 @@ Common::SeekableReadStream *FSNode::createReadStream() const {
 	return _realNode->createReadStream();
 }
 
-Common::WriteStream *FSNode::createWriteStream() const {
+WriteStream *FSNode::createWriteStream() const {
 	if (_realNode == 0)
 		return 0;
 
diff --git a/common/func.h b/common/func.h
index 589f702..db57d73 100644
--- a/common/func.h
+++ b/common/func.h
@@ -424,7 +424,7 @@ private:
  * are interesting for that matter.
  */
 template<class Arg, class Res>
-struct Functor1 : public Common::UnaryFunction<Arg, Res> {
+struct Functor1 : public UnaryFunction<Arg, Res> {
 	virtual ~Functor1() {}
 
 	virtual bool isValid() const = 0;
@@ -460,7 +460,7 @@ private:
  * @see Functor1
  */
 template<class Arg1, class Arg2, class Res>
-struct Functor2 : public Common::BinaryFunction<Arg1, Arg2, Res> {
+struct Functor2 : public BinaryFunction<Arg1, Arg2, Res> {
 	virtual ~Functor2() {}
 
 	virtual bool isValid() const = 0;
diff --git a/common/huffman.h b/common/huffman.h
index 9a8b712..4175d0d 100644
--- a/common/huffman.h
+++ b/common/huffman.h
@@ -66,9 +66,9 @@ private:
 		Symbol(uint32 c, uint32 s);
 	};
 
-	typedef Common::List<Symbol> CodeList;
-	typedef Common::Array<CodeList> CodeLists;
-	typedef Common::Array<Symbol *> SymbolList;
+	typedef List<Symbol> CodeList;
+	typedef Array<CodeList> CodeLists;
+	typedef Array<Symbol*> SymbolList;
 
 	/** Lists of codes and their symbols, sorted by code length. */
 	CodeLists _codes;
diff --git a/common/iff_container.cpp b/common/iff_container.cpp
index 02b445a..7bcbf86 100644
--- a/common/iff_container.cpp
+++ b/common/iff_container.cpp
@@ -25,7 +25,7 @@
 
 namespace Common {
 
-IFFParser::IFFParser(Common::ReadStream *stream, bool disposeStream) : _stream(stream), _disposeStream(disposeStream) {
+IFFParser::IFFParser(ReadStream *stream, bool disposeStream) : _stream(stream), _disposeStream(disposeStream) {
 	setInputStream(stream);
 }
 
@@ -36,7 +36,7 @@ IFFParser::~IFFParser() {
 	_stream = 0;
 }
 
-void IFFParser::setInputStream(Common::ReadStream *stream) {
+void IFFParser::setInputStream(ReadStream *stream) {
 	assert(stream);
 	_formChunk.setInputStream(stream);
 	_chunk.setInputStream(stream);
@@ -63,7 +63,7 @@ void IFFParser::parse(IFFCallback &callback) {
 		_chunk.readHeader();
 
 		// invoke the callback
-		Common::SubReadStream stream(&_chunk, _chunk.size);
+		SubReadStream stream(&_chunk, _chunk.size);
 		IFFChunk chunk(_chunk.id, _chunk.size, &stream);
 		stop = callback(chunk);
 
diff --git a/common/iff_container.h b/common/iff_container.h
index 1b12ef7..104ecf0 100644
--- a/common/iff_container.h
+++ b/common/iff_container.h
@@ -146,11 +146,11 @@ page 376) */
  *  Client code must *not* deallocate _stream when done.
  */
 struct IFFChunk {
-	Common::IFF_ID			_type;
-	uint32					_size;
-	Common::ReadStream		*_stream;
+	IFF_ID      _type;
+	uint32      _size;
+	ReadStream *_stream;
 
-	IFFChunk(Common::IFF_ID type, uint32 size, Common::ReadStream *stream) : _type(type), _size(size), _stream(stream) {
+	IFFChunk(IFF_ID type, uint32 size, ReadStream *stream) : _type(type), _size(size), _stream(stream) {
 		assert(_stream);
 	}
 };
@@ -163,17 +163,17 @@ class IFFParser {
 	/**
 	 *  This private class implements IFF chunk navigation.
 	 */
-	class IFFChunkNav : public Common::ReadStream {
+	class IFFChunkNav : public ReadStream {
 	protected:
-		Common::ReadStream *_input;
+		ReadStream *_input;
 		uint32 _bytesRead;
 	public:
-		Common::IFF_ID id;
+		IFF_ID id;
 		uint32 size;
 
 		IFFChunkNav() : _input(0) {
 		}
-		void setInputStream(Common::ReadStream *input) {
+		void setInputStream(ReadStream *input) {
 			_input = input;
 			size = _bytesRead = 0;
 		}
@@ -199,7 +199,7 @@ class IFFParser {
 				readByte();
 			}
 		}
-		// Common::ReadStream implementation
+		// ReadStream implementation
 		bool eos() const { return _input->eos(); }
 		bool err() const { return _input->err(); }
 		void clearErr() { _input->clearErr(); }
@@ -215,21 +215,21 @@ protected:
 	IFFChunkNav _chunk; 	///< The current chunk.
 
 	uint32 _formSize;
-	Common::IFF_ID _formType;
+	IFF_ID _formType;
 
-	Common::ReadStream *_stream;
+	ReadStream *_stream;
 	bool _disposeStream;
 
-	void setInputStream(Common::ReadStream *stream);
+	void setInputStream(ReadStream *stream);
 
 public:
-	IFFParser(Common::ReadStream *stream, bool disposeStream = false);
+	IFFParser(ReadStream *stream, bool disposeStream = false);
 	~IFFParser();
 
 	/**
 	 * Callback type for the parser.
 	 */
-	typedef Common::Functor1< IFFChunk&, bool > IFFCallback;
+	typedef Functor1< IFFChunk&, bool > IFFCallback;
 
 	/**
 	 * Parse the IFF container, invoking the callback on each chunk encountered.
diff --git a/common/ptr.h b/common/ptr.h
index fc272d3..c97d7a4 100644
--- a/common/ptr.h
+++ b/common/ptr.h
@@ -185,12 +185,12 @@ public:
 	}
 
 	template<class T2>
-	bool operator==(const Common::SharedPtr<T2> &r) const {
+	bool operator==(const SharedPtr<T2> &r) const {
 		return _pointer == r.get();
 	}
 
 	template<class T2>
-	bool operator!=(const Common::SharedPtr<T2> &r) const {
+	bool operator!=(const SharedPtr<T2> &r) const {
 		return _pointer != r.get();
 	}
 
diff --git a/common/quicktime.cpp b/common/quicktime.cpp
index 1cae2f1..9ea8c22 100644
--- a/common/quicktime.cpp
+++ b/common/quicktime.cpp
@@ -48,7 +48,7 @@ QuickTimeParser::QuickTimeParser() {
 	_fd = 0;
 	_scaleFactorX = 1;
 	_scaleFactorY = 1;
-	_resFork = new Common::MacResManager();
+	_resFork = new MacResManager();
 	_disposeFileHandle = DisposeAfterUse::YES;
 
 	initParseTable();
@@ -59,7 +59,7 @@ QuickTimeParser::~QuickTimeParser() {
 	delete _resFork;
 }
 
-bool QuickTimeParser::parseFile(const Common::String &filename) {
+bool QuickTimeParser::parseFile(const String &filename) {
 	if (!_resFork->open(filename) || !_resFork->hasDataFork())
 		return false;
 
@@ -70,7 +70,7 @@ bool QuickTimeParser::parseFile(const Common::String &filename) {
 
 	if (_resFork->hasResFork()) {
 		// Search for a 'moov' resource
-		Common::MacResIDArray idArray = _resFork->getResIDArray(MKTAG('m', 'o', 'o', 'v'));
+		MacResIDArray idArray = _resFork->getResIDArray(MKTAG('m', 'o', 'o', 'v'));
 
 		if (!idArray.empty())
 			_fd = _resFork->getResource(MKTAG('m', 'o', 'o', 'v'), idArray[0]);
@@ -96,7 +96,7 @@ bool QuickTimeParser::parseFile(const Common::String &filename) {
 	return true;
 }
 
-bool QuickTimeParser::parseStream(Common::SeekableReadStream *stream, DisposeAfterUse::Flag disposeFileHandle) {
+bool QuickTimeParser::parseStream(SeekableReadStream *stream, DisposeAfterUse::Flag disposeFileHandle) {
 	_fd = stream;
 	_foundMOOV = false;
 	_disposeFileHandle = disposeFileHandle;
@@ -274,7 +274,7 @@ int QuickTimeParser::readCMOV(Atom atom) {
 
 	// Uncompress the data
 	unsigned long dstLen = uncompressedSize;
-	if (!Common::uncompress(uncompressedData, &dstLen, compressedData, compressedSize)) {
+	if (!uncompress(uncompressedData, &dstLen, compressedData, compressedSize)) {
 		warning ("Could not uncompress cmov chunk");
 		free(compressedData);
 		free(uncompressedData);
@@ -282,8 +282,8 @@ int QuickTimeParser::readCMOV(Atom atom) {
 	}
 
 	// Load data into a new MemoryReadStream and assign _fd to be that
-	Common::SeekableReadStream *oldStream = _fd;
-	_fd = new Common::MemoryReadStream(uncompressedData, uncompressedSize, DisposeAfterUse::YES);
+	SeekableReadStream *oldStream = _fd;
+	_fd = new MemoryReadStream(uncompressedData, uncompressedSize, DisposeAfterUse::YES);
 
 	// Read the contents of the uncompressed data
 	Atom a = { MKTAG('m', 'o', 'o', 'v'), 0, uncompressedSize };
@@ -333,8 +333,8 @@ int QuickTimeParser::readMVHD(Atom atom) {
 	uint32 yMod = _fd->readUint32BE();
 	_fd->skip(16);
 
-	_scaleFactorX = Common::Rational(0x10000, xMod);
-	_scaleFactorY = Common::Rational(0x10000, yMod);
+	_scaleFactorX = Rational(0x10000, xMod);
+	_scaleFactorY = Rational(0x10000, yMod);
 
 	_scaleFactorX.debugPrint(1, "readMVHD(): scaleFactorX =");
 	_scaleFactorY.debugPrint(1, "readMVHD(): scaleFactorY =");
@@ -403,8 +403,8 @@ int QuickTimeParser::readTKHD(Atom atom) {
 	uint32 yMod = _fd->readUint32BE();
 	_fd->skip(16);
 
-	track->scaleFactorX = Common::Rational(0x10000, xMod);
-	track->scaleFactorY = Common::Rational(0x10000, yMod);
+	track->scaleFactorX = Rational(0x10000, xMod);
+	track->scaleFactorY = Rational(0x10000, yMod);
 
 	track->scaleFactorX.debugPrint(1, "readTKHD(): scaleFactorX =");
 	track->scaleFactorY.debugPrint(1, "readTKHD(): scaleFactorY =");
@@ -431,7 +431,7 @@ int QuickTimeParser::readELST(Atom atom) {
 	for (uint32 i = 0; i < track->editCount; i++){
 		track->editList[i].trackDuration = _fd->readUint32BE();
 		track->editList[i].mediaTime = _fd->readSint32BE();
-		track->editList[i].mediaRate = Common::Rational(_fd->readUint32BE(), 0x10000);
+		track->editList[i].mediaRate = Rational(_fd->readUint32BE(), 0x10000);
 		debugN(3, "\tDuration = %d, Media Time = %d, ", track->editList[i].trackDuration, track->editList[i].mediaTime);
 		track->editList[i].mediaRate.debugPrint(3, "Media Rate =");
 	}
@@ -695,7 +695,7 @@ enum {
 	kMP4DecSpecificDescTag = 5
 };
 
-static int readMP4DescLength(Common::SeekableReadStream *stream) {
+static int readMP4DescLength(SeekableReadStream *stream) {
 	int length = 0;
 	int count = 4;
 
@@ -710,7 +710,7 @@ static int readMP4DescLength(Common::SeekableReadStream *stream) {
 	return length;
 }
 
-static void readMP4Desc(Common::SeekableReadStream *stream, byte &tag, int &length) {
+static void readMP4Desc(SeekableReadStream *stream, byte &tag, int &length) {
 	tag = stream->readByte();
 	length = readMP4DescLength(stream);
 }
diff --git a/common/quicktime.h b/common/quicktime.h
index 800726b..e4c821e 100644
--- a/common/quicktime.h
+++ b/common/quicktime.h
@@ -56,14 +56,14 @@ public:
 	 * Load a QuickTime file
 	 * @param filename	the filename to load
 	 */
-	bool parseFile(const Common::String &filename);
+	bool parseFile(const String &filename);
 
 	/**
 	 * Load a QuickTime file from a SeekableReadStream
 	 * @param stream	the stream to load
 	 * @param disposeFileHandle whether to delete the stream after use
 	 */
-	bool parseStream(Common::SeekableReadStream *stream, DisposeAfterUse::Flag disposeFileHandle = DisposeAfterUse::YES);
+	bool parseStream(SeekableReadStream *stream, DisposeAfterUse::Flag disposeFileHandle = DisposeAfterUse::YES);
 
 	/**
 	 * Close a QuickTime file
@@ -81,7 +81,7 @@ public:
 
 protected:
 	// This is the file handle from which data is read from. It can be the actual file handle or a decompressed stream.
-	Common::SeekableReadStream *_fd;
+	SeekableReadStream *_fd;
 
 	DisposeAfterUse::Flag _disposeFileHandle;
 
@@ -110,7 +110,7 @@ protected:
 	struct EditListEntry {
 		uint32 trackDuration;
 		int32 mediaTime;
-		Common::Rational mediaRate;
+		Rational mediaRate;
 	};
 
 	struct Track;
@@ -154,18 +154,18 @@ protected:
 		uint16 height;
 		CodecType codecType;
 
-		Common::Array<SampleDesc *> sampleDescs;
+		Array<SampleDesc*> sampleDescs;
 
 		uint32 editCount;
 		EditListEntry *editList;
 
-		Common::SeekableReadStream *extraData;
+		SeekableReadStream *extraData;
 
 		uint32 frameCount;
 		uint32 duration;
 		uint32 startTime;
-		Common::Rational scaleFactorX;
-		Common::Rational scaleFactorY;
+		Rational scaleFactorX;
+		Rational scaleFactorY;
 
 		byte objectTypeMP4;
 	};
@@ -176,11 +176,11 @@ protected:
 	bool _foundMOOV;
 	uint32 _timeScale;
 	uint32 _duration;
-	Common::Rational _scaleFactorX;
-	Common::Rational _scaleFactorY;
-	Common::Array<Track *> _tracks;
+	Rational _scaleFactorX;
+	Rational _scaleFactorY;
+	Array<Track*> _tracks;
 	uint32 _beginOffset;
-	Common::MacResManager *_resFork;
+	MacResManager *_resFork;
 
 	void initParseTable();
 	void init();
diff --git a/common/rational.cpp b/common/rational.cpp
index cb28786..f5495da 100644
--- a/common/rational.cpp
+++ b/common/rational.cpp
@@ -107,8 +107,8 @@ Rational &Rational::operator-=(const Rational &right) {
 Rational &Rational::operator*=(const Rational &right) {
 	// Cross-cancel to avoid unnecessary overflow;
 	// the result then is automatically normalized
-	const int gcd1 = Common::gcd(_num, right._denom);
-	const int gcd2 = Common::gcd(right._num, _denom);
+	const int gcd1 = gcd(_num, right._denom);
+	const int gcd2 = gcd(right._num, _denom);
 
 	_num   = (_num    / gcd1) * (right._num    / gcd2);
 	_denom = (_denom  / gcd2) * (right._denom  / gcd1);
diff --git a/common/serializer.h b/common/serializer.h
index b874624..5b08a9a 100644
--- a/common/serializer.h
+++ b/common/serializer.h
@@ -68,15 +68,15 @@ public:
 	static const Version kLastVersion = 0xFFFFFFFF;
 
 protected:
-	Common::SeekableReadStream *_loadStream;
-	Common::WriteStream *_saveStream;
+	SeekableReadStream *_loadStream;
+	WriteStream *_saveStream;
 
 	uint _bytesSynced;
 
 	Version _version;
 
 public:
-	Serializer(Common::SeekableReadStream *in, Common::WriteStream *out)
+	Serializer(SeekableReadStream *in, WriteStream *out)
 		: _loadStream(in), _saveStream(out), _bytesSynced(0), _version(0) {
 		assert(in || out);
 	}
@@ -214,7 +214,7 @@ public:
 	 * Sync a C-string, by treating it as a zero-terminated byte sequence.
 	 * @todo Replace this method with a special Syncer class for Common::String
 	 */
-	void syncString(Common::String &str, Version minVersion = 0, Version maxVersion = kLastVersion) {
+	void syncString(String &str, Version minVersion = 0, Version maxVersion = kLastVersion) {
 		if (_version < minVersion || _version > maxVersion)
 			return;	// Ignore anything which is not supposed to be present in this save game version
 
diff --git a/common/str.h b/common/str.h
index 8e07b62..5039130 100644
--- a/common/str.h
+++ b/common/str.h
@@ -219,14 +219,14 @@ public:
 	 * except that it stores the result in (variably sized) String
 	 * instead of a fixed size buffer.
 	 */
-	static Common::String format(const char *fmt, ...) GCC_PRINTF(1,2);
+	static String format(const char *fmt, ...) GCC_PRINTF(1,2);
 
 	/**
 	 * Print formatted data into a String object. Similar to vsprintf,
 	 * except that it stores the result in (variably sized) String
 	 * instead of a fixed size buffer.
 	 */
-	static Common::String vformat(const char *fmt, va_list args);
+	static String vformat(const char *fmt, va_list args);
 
 public:
 	typedef char *        iterator;
@@ -293,7 +293,7 @@ extern char *trim(char *t);
  * @param sep character used to separate path components
  * @return The last component of the path.
  */
-Common::String lastPathComponent(const Common::String &path, const char sep);
+String lastPathComponent(const String &path, const char sep);
 
 /**
  * Normalize a given path to a canonical form. In particular:
@@ -307,7 +307,7 @@ Common::String lastPathComponent(const Common::String &path, const char sep);
  * @param sep   the separator token (usually '/' on Unix-style systems, or '\\' on Windows based stuff)
  * @return      the normalized path
  */
-Common::String normalizePath(const Common::String &path, const char sep);
+String normalizePath(const String &path, const char sep);
 
 
 /**
diff --git a/common/unarj.cpp b/common/unarj.cpp
index f45ddda..cccc330 100644
--- a/common/unarj.cpp
+++ b/common/unarj.cpp
@@ -293,8 +293,8 @@ ArjHeader *readHeader(SeekableReadStream &stream) {
 		return NULL;
 	}
 
-	Common::strlcpy(header.filename, (const char *)&headData[header.firstHdrSize], ARJ_FILENAME_MAX);
-	Common::strlcpy(header.comment, (const char *)&headData[header.firstHdrSize + strlen(header.filename) + 1], ARJ_COMMENT_MAX);
+	strlcpy(header.filename, (const char *)&headData[header.firstHdrSize], ARJ_FILENAME_MAX);
+	strlcpy(header.comment, (const char *)&headData[header.firstHdrSize + strlen(header.filename) + 1], ARJ_COMMENT_MAX);
 
 	// Process extended headers, if any
 	uint16 extHeaderSize;
@@ -692,15 +692,15 @@ void ArjDecoder::decode_f(int32 origsize) {
 
 typedef HashMap<String, ArjHeader*, IgnoreCase_Hash, IgnoreCase_EqualTo> ArjHeadersMap;
 
-class ArjArchive : public Common::Archive {
+class ArjArchive : public Archive {
 	ArjHeadersMap _headers;
-	Common::String _arjFilename;
+	String _arjFilename;
 
 public:
 	ArjArchive(const String &name);
 	virtual ~ArjArchive();
 
-	// Common::Archive implementation
+	// Archive implementation
 	virtual bool hasFile(const String &name);
 	virtual int listMembers(ArchiveMemberList &list);
 	virtual ArchiveMemberPtr getMember(const String &name);
@@ -708,7 +708,7 @@ public:
 };
 
 ArjArchive::ArjArchive(const String &filename) : _arjFilename(filename) {
-	Common::File arjFile;
+	File arjFile;
 
 	if (!arjFile.open(_arjFilename)) {
 		warning("ArjArchive::ArjArchive(): Could not find the archive file");
@@ -775,7 +775,7 @@ SeekableReadStream *ArjArchive::createReadStreamForMember(const String &name) co
 
 	ArjHeader *hdr = _headers[name];
 
-	Common::File archiveFile;
+	File archiveFile;
 	archiveFile.open(_arjFilename);
 	archiveFile.seek(hdr->pos, SEEK_SET);
 
@@ -794,8 +794,8 @@ SeekableReadStream *ArjArchive::createReadStreamForMember(const String &name) co
 		// If reading from archiveFile directly is too slow to be usable,
 		// maybe the filesystem code should instead wrap its files
 		// in a BufferedReadStream.
-		decoder->_compressed = Common::wrapBufferedReadStream(&archiveFile, 4096, DisposeAfterUse::NO);
-		decoder->_outstream = new Common::MemoryWriteStream(uncompressedData, hdr->origSize);
+		decoder->_compressed = wrapBufferedReadStream(&archiveFile, 4096, DisposeAfterUse::NO);
+		decoder->_outstream = new MemoryWriteStream(uncompressedData, hdr->origSize);
 
 		if (hdr->method == 1 || hdr->method == 2 || hdr->method == 3)
 			decoder->decode(hdr->origSize);
@@ -805,7 +805,7 @@ SeekableReadStream *ArjArchive::createReadStreamForMember(const String &name) co
 		delete decoder;
 	}
 
-	return new Common::MemoryReadStream(uncompressedData, hdr->origSize, DisposeAfterUse::YES);
+	return new MemoryReadStream(uncompressedData, hdr->origSize, DisposeAfterUse::YES);
 }
 
 Archive *makeArjArchive(const String &name) {
diff --git a/common/unzip.cpp b/common/unzip.cpp
index 91f352f..8650c91 100644
--- a/common/unzip.cpp
+++ b/common/unzip.cpp
@@ -1458,11 +1458,11 @@ ZipArchive::~ZipArchive() {
 	unzClose(_zipFile);
 }
 
-bool ZipArchive::hasFile(const Common::String &name) {
+bool ZipArchive::hasFile(const String &name) {
 	return (unzLocateFile(_zipFile, name.c_str(), 2) == UNZ_OK);
 }
 
-int ZipArchive::listMembers(Common::ArchiveMemberList &list) {
+int ZipArchive::listMembers(ArchiveMemberList &list) {
 	int matches = 0;
 	int err = unzGoToFirstFile(_zipFile);
 
@@ -1488,7 +1488,7 @@ ArchiveMemberPtr ZipArchive::getMember(const String &name) {
 	return ArchiveMemberPtr(new GenericArchiveMember(name, this));
 }
 
-Common::SeekableReadStream *ZipArchive::createReadStreamForMember(const Common::String &name) const {
+SeekableReadStream *ZipArchive::createReadStreamForMember(const String &name) const {
 	if (unzLocateFile(_zipFile, name.c_str(), 2) != UNZ_OK)
 		return 0;
 
@@ -1512,7 +1512,7 @@ Common::SeekableReadStream *ZipArchive::createReadStreamForMember(const Common::
 		return 0;
 	}
 
-	return new Common::MemoryReadStream(buffer, fileInfo.uncompressed_size, DisposeAfterUse::YES);
+	return new MemoryReadStream(buffer, fileInfo.uncompressed_size, DisposeAfterUse::YES);
 
 	// FIXME: instead of reading all into a memory stream, we could
 	// instead create a new ZipStream class. But then we have to be
diff --git a/common/util.cpp b/common/util.cpp
index 32315bc..6bde6a6 100644
--- a/common/util.cpp
+++ b/common/util.cpp
@@ -82,7 +82,7 @@ void hexdump(const byte *data, int len, int bytesPerLine, int startOffset) {
 #pragma mark -
 
 
-bool parseBool(const Common::String &val, bool &valAsBool) {
+bool parseBool(const String &val, bool &valAsBool) {
 	if (val.equalsIgnoreCase("true") ||
 		val.equalsIgnoreCase("yes") ||
 		val.equals("1")) {
diff --git a/common/util.h b/common/util.h
index cd890c9..6e14188 100644
--- a/common/util.h
+++ b/common/util.h
@@ -96,7 +96,7 @@ extern void hexdump(const byte * data, int len, int bytesPerLine = 16, int start
  * @param[out] valAsBool	the parsing result
  * @return 	true if the string parsed correctly, false if an error occurred.
  */
-bool parseBool(const Common::String &val, bool &valAsBool);
+bool parseBool(const String &val, bool &valAsBool);
 
 /**
  * List of game language.
@@ -131,7 +131,7 @@ struct LanguageDescription {
 	const char *code;
 	//const char *unixLocale;
 	const char *description;
-	Common::Language id;
+	Language id;
 };
 
 extern const LanguageDescription g_languages[];
@@ -182,7 +182,7 @@ struct PlatformDescription {
 	const char *code2;
 	const char *abbrev;
 	const char *description;
-	Common::Platform id;
+	Platform id;
 };
 
 extern const PlatformDescription g_platforms[];
@@ -211,7 +211,7 @@ enum RenderMode {
 struct RenderModeDescription {
 	const char *code;
 	const char *description;
-	Common::RenderMode id;
+	RenderMode id;
 };
 
 extern const RenderModeDescription g_renderModes[];
diff --git a/common/winexe_pe.cpp b/common/winexe_pe.cpp
index e5f6a24..6c0f9c9 100644
--- a/common/winexe_pe.cpp
+++ b/common/winexe_pe.cpp
@@ -133,7 +133,7 @@ void PEResources::parseResourceLevel(Section &section, uint32 offset, int level)
 			_exe->seek(section.offset + (value & 0x7fffffff));
 
 			// Read in the name, truncating from unicode to ascii
-			Common::String name;
+			String name;
 			uint16 nameLength = _exe->readUint16LE();
 			while (nameLength--)
 				name += (char)(_exe->readUint16LE() & 0xff);
diff --git a/common/xmlparser.cpp b/common/xmlparser.cpp
index 6236199..f768e44 100644
--- a/common/xmlparser.cpp
+++ b/common/xmlparser.cpp
@@ -81,7 +81,7 @@ void XMLParser::close() {
 	_stream = 0;
 }
 
-bool XMLParser::parserError(const Common::String &errStr) {
+bool XMLParser::parserError(const String &errStr) {
 	_state = kParserError;
 
 	const int startPosition = _stream->pos();
diff --git a/common/xmlparser.h b/common/xmlparser.h
index d75dc0e..93433b7 100644
--- a/common/xmlparser.h
+++ b/common/xmlparser.h
@@ -275,7 +275,7 @@ protected:
 	 * Parser error always returns "false" so we can pass the return value
 	 * directly and break down the parsing.
 	 */
-	bool parserError(const Common::String &errStr);
+	bool parserError(const String &errStr);
 
 	/**
 	 * Skips spaces/whitelines etc.
diff --git a/common/zlib.cpp b/common/zlib.cpp
index 1048430..86c6188 100644
--- a/common/zlib.cpp
+++ b/common/zlib.cpp
@@ -54,7 +54,7 @@ bool uncompress(byte *dst, unsigned long *dstLen, const byte *src, unsigned long
  * other SeekableReadStream and will then provide on-the-fly decompression support.
  * Assumes the compressed data to be in gzip format.
  */
-class GZipReadStream : public Common::SeekableReadStream {
+class GZipReadStream : public SeekableReadStream {
 protected:
 	enum {
 		BUFSIZE = 16384		// 1 << MAX_WBITS
@@ -71,7 +71,7 @@ protected:
 
 public:
 
-	GZipReadStream(Common::SeekableReadStream *w) : _wrapped(w), _stream() {
+	GZipReadStream(SeekableReadStream *w) : _wrapped(w), _stream() {
 		assert(w != 0);
 
 		// Verify file header is correct
@@ -197,7 +197,7 @@ public:
  * other WriteStream and will then provide on-the-fly compression support.
  * The compressed data is written in the gzip format.
  */
-class GZipWriteStream : public Common::WriteStream {
+class GZipWriteStream : public WriteStream {
 protected:
 	enum {
 		BUFSIZE = 16384		// 1 << MAX_WBITS
@@ -224,7 +224,7 @@ protected:
 	}
 
 public:
-	GZipWriteStream(Common::WriteStream *w) : _wrapped(w), _stream() {
+	GZipWriteStream(WriteStream *w) : _wrapped(w), _stream() {
 		assert(w != 0);
 
 		// Adding 16 to windowBits indicates to zlib that it is supposed to
@@ -300,7 +300,7 @@ public:
 
 #endif	// USE_ZLIB
 
-Common::SeekableReadStream *wrapCompressedReadStream(Common::SeekableReadStream *toBeWrapped) {
+SeekableReadStream *wrapCompressedReadStream(SeekableReadStream *toBeWrapped) {
 #if defined(USE_ZLIB)
 	if (toBeWrapped) {
 		uint16 header = toBeWrapped->readUint16BE();
@@ -315,7 +315,7 @@ Common::SeekableReadStream *wrapCompressedReadStream(Common::SeekableReadStream
 	return toBeWrapped;
 }
 
-Common::WriteStream *wrapCompressedWriteStream(Common::WriteStream *toBeWrapped) {
+WriteStream *wrapCompressedWriteStream(WriteStream *toBeWrapped) {
 #if defined(USE_ZLIB)
 	if (toBeWrapped)
 		return new GZipWriteStream(toBeWrapped);


Commit: 79729d03e014962cd9bcef263145997eec63ec38
    https://github.com/scummvm/scummvm/commit/79729d03e014962cd9bcef263145997eec63ec38
Author: Christoph Mallon (christoph.mallon at gmx.de)
Date: 2011-08-07T06:19:07-07:00

Commit Message:
COMMON: Use correct format specifier.

Changed paths:
    common/array.h



diff --git a/common/array.h b/common/array.h
index af1fe57..bc378d5 100644
--- a/common/array.h
+++ b/common/array.h
@@ -274,7 +274,7 @@ protected:
 		if (capacity) {
 			_storage = new T[capacity];
 			if (!_storage)
-				::error("Common::Array: failure to allocate %d bytes", capacity);
+				::error("Common::Array: failure to allocate %u bytes", capacity);
 		} else {
 			_storage = 0;
 		}


Commit: c876e87efc574a646268bd57428cdcef87a517a8
    https://github.com/scummvm/scummvm/commit/c876e87efc574a646268bd57428cdcef87a517a8
Author: Christoph Mallon (christoph.mallon at gmx.de)
Date: 2011-08-07T06:19:07-07:00

Commit Message:
COMMON: Correct error message.

The message displays bytes, but capacity is the count of objects, so multiply by their size.

Changed paths:
    common/array.h



diff --git a/common/array.h b/common/array.h
index bc378d5..18cecfb 100644
--- a/common/array.h
+++ b/common/array.h
@@ -274,7 +274,7 @@ protected:
 		if (capacity) {
 			_storage = new T[capacity];
 			if (!_storage)
-				::error("Common::Array: failure to allocate %u bytes", capacity);
+				::error("Common::Array: failure to allocate %u bytes", capacity * (uint)sizeof(T));
 		} else {
 			_storage = 0;
 		}


Commit: 97a6ee2e64da515c7d009d059768b34508ada38c
    https://github.com/scummvm/scummvm/commit/97a6ee2e64da515c7d009d059768b34508ada38c
Author: Christoph Mallon (christoph.mallon at gmx.de)
Date: 2011-08-07T06:19:07-07:00

Commit Message:
AUDIO: #define OV_EXCLUDE_STATIC_CALLBACKS to not get unnecessary static data, which causes warnings.

Changed paths:
    audio/decoders/vorbis.cpp



diff --git a/audio/decoders/vorbis.cpp b/audio/decoders/vorbis.cpp
index 2724dd1..e10ec11 100644
--- a/audio/decoders/vorbis.cpp
+++ b/audio/decoders/vorbis.cpp
@@ -42,6 +42,7 @@
 #include <tremor/ivorbisfile.h>
 #endif
 #else
+#define OV_EXCLUDE_STATIC_CALLBACKS
 #include <vorbis/vorbisfile.h>
 #endif
 


Commit: c6d5d748353c848e134517214217912447d7a567
    https://github.com/scummvm/scummvm/commit/c6d5d748353c848e134517214217912447d7a567
Author: Christoph Mallon (christoph.mallon at gmx.de)
Date: 2011-08-07T06:19:07-07:00

Commit Message:
COMMON: Make constants actually const.

Changed paths:
    common/config-manager.cpp
    common/config-manager.h



diff --git a/common/config-manager.cpp b/common/config-manager.cpp
index 874aee1..c62dee8 100644
--- a/common/config-manager.cpp
+++ b/common/config-manager.cpp
@@ -38,11 +38,11 @@ namespace Common {
 
 DECLARE_SINGLETON(ConfigManager);
 
-const char *ConfigManager::kApplicationDomain = "scummvm";
-const char *ConfigManager::kTransientDomain = "__TRANSIENT";
+char const *const ConfigManager::kApplicationDomain = "scummvm";
+char const *const ConfigManager::kTransientDomain = "__TRANSIENT";
 
 #ifdef ENABLE_KEYMAPPER
-const char *ConfigManager::kKeymapperDomain = "keymapper";
+char const *const ConfigManager::kKeymapperDomain = "keymapper";
 #endif
 
 #pragma mark -
diff --git a/common/config-manager.h b/common/config-manager.h
index e04041d..02d4ec3 100644
--- a/common/config-manager.h
+++ b/common/config-manager.h
@@ -64,14 +64,14 @@ public:
 	typedef HashMap<String, Domain, IgnoreCase_Hash, IgnoreCase_EqualTo> DomainMap;
 
 	/** The name of the application domain (normally 'scummvm'). */
-	static const char *kApplicationDomain;
+	static char const *const kApplicationDomain;
 
 	/** The transient (pseudo) domain. */
-	static const char *kTransientDomain;
+	static char const *const kTransientDomain;
 
 #ifdef ENABLE_KEYMAPPER
 	/** The name of keymapper domain used to store the key maps */
-	static const char *kKeymapperDomain;
+	static char const *const kKeymapperDomain;
 #endif
 
 	void				loadDefaultConfigFile();


Commit: 08ad90edf633f17e3168353815704ca50cab5e9e
    https://github.com/scummvm/scummvm/commit/08ad90edf633f17e3168353815704ca50cab5e9e
Author: Christoph Mallon (christoph.mallon at gmx.de)
Date: 2011-08-07T06:19:07-07:00

Commit Message:
TSAGE: Reduce scope of variable.

Changed paths:
    engines/tsage/sound.cpp



diff --git a/engines/tsage/sound.cpp b/engines/tsage/sound.cpp
index dd6ec69..efffa70 100644
--- a/engines/tsage/sound.cpp
+++ b/engines/tsage/sound.cpp
@@ -2825,8 +2825,6 @@ int AdlibSoundDriver::readBuffer(int16 *buffer, const int numSamples) {
 
 /*--------------------------------------------------------------------------*/
 
-const byte soundBlaster_group_data[] = { 3, 1, 1, 0, 0xff };
-
 
 SoundBlasterDriver::SoundBlasterDriver(): SoundDriver() {
 	_minVersion = 0x102;
@@ -2836,7 +2834,8 @@ SoundBlasterDriver::SoundBlasterDriver(): SoundDriver() {
 	_groupData.groupMask = 1;
 	_groupData.v1 = 0x3E;
 	_groupData.v2 = 0;
-	_groupData.pData = &soundBlaster_group_data[0];
+	static byte const group_data[] = { 3, 1, 1, 0, 0xff };
+	_groupData.pData = group_data;
 
 	_mixer = _vm->_mixer;
 	_sampleRate = _mixer->getOutputRate();


Commit: 715c07930dfa721b106c6db54db779de1d021c6c
    https://github.com/scummvm/scummvm/commit/715c07930dfa721b106c6db54db779de1d021c6c
Author: Christoph Mallon (christoph.mallon at gmx.de)
Date: 2011-08-07T06:19:07-07:00

Commit Message:
CRUISE: Replace casts and offset calculations for memory debugger by a simple struct.

Changed paths:
    engines/cruise/cruise.h
    engines/cruise/cruise_main.cpp



diff --git a/engines/cruise/cruise.h b/engines/cruise/cruise.h
index 900f677..94f8759 100644
--- a/engines/cruise/cruise.h
+++ b/engines/cruise/cruise.h
@@ -108,7 +108,15 @@ public:
 
 	Common::RandomSource _rnd;
 
-	Common::List<byte *> _memList;
+	struct MemInfo {
+		int32  lineNum;
+		char   fname[64];
+		uint32 magic;
+
+		static uint32 const cookie = 0x41424344;
+	};
+
+	Common::List<MemInfo*> _memList;
 
 	typedef Common::List<Common::Rect> RectList;
 
diff --git a/engines/cruise/cruise_main.cpp b/engines/cruise/cruise_main.cpp
index 031c53b..ff46696 100644
--- a/engines/cruise/cruise_main.cpp
+++ b/engines/cruise/cruise_main.cpp
@@ -40,19 +40,21 @@ unsigned int timer = 0;
 
 gfxEntryStruct* linkedMsgList = NULL;
 
+typedef CruiseEngine::MemInfo MemInfo;
+
 void MemoryList() {
 	if (!_vm->_memList.empty()) {
 		debug("Current list of un-freed memory blocks:");
-		Common::List<byte *>::iterator i;
+		Common::List<MemInfo*>::iterator i;
 		for (i = _vm->_memList.begin(); i != _vm->_memList.end(); ++i) {
-			byte *v = *i;
-			debug("%s - %d", (const char *)(v - 68), *((int32 *)(v - 72)));
+			MemInfo const *const v = *i;
+			debug("%s - %d", v->fname, v->lineNum);
 		}
 	}
 }
 
 void *MemoryAlloc(uint32 size, bool clearFlag, int32 lineNum, const char *fname) {
-	byte *result;
+	void *result;
 
 	if (gDebugLevel > 0) {
 		// Find the point after the final slash
@@ -61,17 +63,17 @@ void *MemoryAlloc(uint32 size, bool clearFlag, int32 lineNum, const char *fname)
 			--fnameP;
 
 		// Create the new memory block and add it to the memory list
-		byte *v = (byte *)malloc(size + 64 + 8);
-		*((int32 *) v) = lineNum;
-		strncpy((char *)v + 4, fnameP, 63);
-		*((char *)v + 4 + 63) = '\0';
-		*((uint32 *) (v + 68)) = 0x41424344;
+		MemInfo *const v = (MemInfo *)malloc(sizeof(MemInfo) + size);
+		v->lineNum = lineNum;
+		strncpy(v->fname, fnameP, sizeof(v->fname));
+		v->fname[ARRAYSIZE(v->fname) - 1] = '\0';
+		v->magic = MemInfo::cookie;
 
 		// Add the block to the memory list
-		result = v + 64 + 8;
-		_vm->_memList.push_back(result);
+		_vm->_memList.push_back(v);
+		result = v + 1;
 	} else
-		result = (byte *)malloc(size);
+		result = malloc(size);
 
 	if (clearFlag)
 		memset(result, 0, size);
@@ -84,11 +86,11 @@ void MemoryFree(void *v) {
 		return;
 
 	if (gDebugLevel > 0) {
-		byte *p = (byte *)v;
-		assert(*((uint32 *) (p - 4)) == 0x41424344);
+		MemInfo *const p = (MemInfo *)v - 1;
+		assert(p->magic == MemInfo::cookie);
 
 		_vm->_memList.remove(p);
-		free(p - 8 - 64);
+		free(p);
 	} else
 		free(v);
 }


Commit: 0a458019b3589cff5426becdbbcc01db0ce9d223
    https://github.com/scummvm/scummvm/commit/0a458019b3589cff5426becdbbcc01db0ce9d223
Author: Christoph Mallon (christoph.mallon at gmx.de)
Date: 2011-08-07T06:19:07-07:00

Commit Message:
AGOS: Replace if-cascade by switch.

Changed paths:
    engines/agos/agos.cpp



diff --git a/engines/agos/agos.cpp b/engines/agos/agos.cpp
index 530803c..300cd28 100644
--- a/engines/agos/agos.cpp
+++ b/engines/agos/agos.cpp
@@ -642,14 +642,12 @@ Common::Error AGOSEngine::init() {
 
 	// TODO: Use special debug levels instead of the following hack.
 	_debugMode = (gDebugLevel >= 0);
-	if (gDebugLevel == 2)
-		_dumpOpcodes = true;
-	if (gDebugLevel == 3)
-		_dumpVgaOpcodes = true;
-	if (gDebugLevel == 4)
-		_dumpScripts = true;
-	if (gDebugLevel == 5)
-		_dumpVgaScripts = true;
+	switch (gDebugLevel) {
+	case 2: _dumpOpcodes    = true; break;
+	case 3: _dumpVgaOpcodes = true; break;
+	case 4: _dumpScripts    = true; break;
+	case 5: _dumpVgaScripts = true; break;
+	}
 
 	return Common::kNoError;
 }


Commit: 5f4d83c38da338ebebb50a5d978d4b81ed361808
    https://github.com/scummvm/scummvm/commit/5f4d83c38da338ebebb50a5d978d4b81ed361808
Author: Christoph Mallon (christoph.mallon at gmx.de)
Date: 2011-08-07T06:19:07-07:00

Commit Message:
AGOS: Correct off-by-one error in range check for setting the debug level.

Changed paths:
    engines/agos/debugger.cpp



diff --git a/engines/agos/debugger.cpp b/engines/agos/debugger.cpp
index b019c06..fc24c6d 100644
--- a/engines/agos/debugger.cpp
+++ b/engines/agos/debugger.cpp
@@ -57,7 +57,7 @@ bool Debugger::Cmd_DebugLevel(int argc, const char **argv) {
 			DebugPrintf("Debugging is currently set at level %d\n", gDebugLevel);
 	} else { // set level
 		gDebugLevel = atoi(argv[1]);
-		if (gDebugLevel >= 0 && gDebugLevel < 10) {
+		if (0 <= gDebugLevel && gDebugLevel < 11) {
 			_vm->_debugMode = true;
 			DebugPrintf("Debug level set to level %d\n", gDebugLevel);
 		} else if (gDebugLevel < 0) {


Commit: f3afb32ee6039f69f3b3616989cc26fd4a0dca95
    https://github.com/scummvm/scummvm/commit/f3afb32ee6039f69f3b3616989cc26fd4a0dca95
Author: Christoph Mallon (christoph.mallon at gmx.de)
Date: 2011-08-07T06:19:08-07:00

Commit Message:
SCI: Remove unnecessary cast.

Changed paths:
    engines/sci/detection.cpp



diff --git a/engines/sci/detection.cpp b/engines/sci/detection.cpp
index 2285e51..b04c1a6 100644
--- a/engines/sci/detection.cpp
+++ b/engines/sci/detection.cpp
@@ -588,7 +588,7 @@ const ADGameDescription *SciMetaEngine::fallbackDetect(const FileMap &allFiles,
 			s_fallbackDesc.extra = "CD";
 	}
 
-	return (const ADGameDescription *)&s_fallbackDesc;
+	return &s_fallbackDesc;
 }
 
 bool SciMetaEngine::createInstance(OSystem *syst, Engine **engine, const ADGameDescription *desc) const {


Commit: 0e6751372a80716cadddd926eeb6965ae6c00a44
    https://github.com/scummvm/scummvm/commit/0e6751372a80716cadddd926eeb6965ae6c00a44
Author: Christoph Mallon (christoph.mallon at gmx.de)
Date: 2011-08-07T06:19:08-07:00

Commit Message:
SCI: Simplify allocation of ResourceManager.

Changed paths:
    engines/sci/detection.cpp



diff --git a/engines/sci/detection.cpp b/engines/sci/detection.cpp
index b04c1a6..82f762e 100644
--- a/engines/sci/detection.cpp
+++ b/engines/sci/detection.cpp
@@ -285,7 +285,7 @@ static const OldNewIdTableEntry s_oldNewTable[] = {
  * @param[in] gameFlags     The game's flags, which are adjusted accordingly for demos
  * @return					The equivalent ScummVM game id
  */
-Common::String convertSierraGameId(Common::String sierraId, uint32 *gameFlags, ResourceManager *resMan) {
+Common::String convertSierraGameId(Common::String sierraId, uint32 *gameFlags, ResourceManager &resMan) {
 	// Convert the id to lower case, so that we match all upper/lower case variants.
 	sierraId.toLowercase();
 
@@ -301,7 +301,7 @@ Common::String convertSierraGameId(Common::String sierraId, uint32 *gameFlags, R
 	if (sierraId == "fp" || sierraId == "gk" || sierraId == "pq4")
 		demoThreshold = 150;
 
-	Common::ScopedPtr<Common::List<ResourceId> > resources(resMan->listResources(kResourceTypeScript, -1));
+	Common::ScopedPtr<Common::List<ResourceId> > resources(resMan.listResources(kResourceTypeScript, -1));
 	if (resources->size() < demoThreshold) {
 		*gameFlags |= ADGF_DEMO;
 
@@ -337,7 +337,7 @@ Common::String convertSierraGameId(Common::String sierraId, uint32 *gameFlags, R
 		// This could either be qfg1 VGA, qfg3 or qfg4 demo (all SCI1.1),
 		// or qfg4 full (SCI2)
 		// qfg1 VGA doesn't have view 1
-		if (!resMan->testResource(ResourceId(kResourceTypeView, 1)))
+		if (!resMan.testResource(ResourceId(kResourceTypeView, 1)))
 			return "qfg1vga";
 
 		// qfg4 full is SCI2
@@ -480,10 +480,9 @@ const ADGameDescription *SciMetaEngine::fallbackDetect(const FileMap &allFiles,
 		return 0;
 	}
 
-	Common::ScopedPtr<ResourceManager> resMan(new ResourceManager());
-	assert(resMan);
-	resMan->addAppropriateSources(fslist);
-	resMan->init(true);
+	ResourceManager resMan;
+	resMan.addAppropriateSources(fslist);
+	resMan.init(true);
 	// TODO: Add error handling.
 
 #ifndef ENABLE_SCI32
@@ -494,7 +493,7 @@ const ADGameDescription *SciMetaEngine::fallbackDetect(const FileMap &allFiles,
 	}
 #endif
 
-	ViewType gameViews = resMan->getViewType();
+	ViewType gameViews = resMan.getViewType();
 
 	// Have we identified the game views? If not, stop here
 	// Can't be SCI (or unsupported SCI views). Pinball Creep by sierra also uses resource.map/resource.000 files
@@ -508,7 +507,7 @@ const ADGameDescription *SciMetaEngine::fallbackDetect(const FileMap &allFiles,
 		s_fallbackDesc.platform = Common::kPlatformAmiga;
 
 	// Determine the game id
-	Common::String sierraGameId = resMan->findSierraGameId();
+	Common::String sierraGameId = resMan.findSierraGameId();
 
 	// If we don't have a game id, the game is not SCI
 	if (sierraGameId.empty()) {
@@ -530,7 +529,7 @@ const ADGameDescription *SciMetaEngine::fallbackDetect(const FileMap &allFiles,
 	// As far as we know, these games store the messages of each language in separate
 	// resources, and it's not possible to detect that easily
 	// Also look for "%J" which is used in japanese games
-	Resource *text = resMan->findResource(ResourceId(kResourceTypeText, 0), 0);
+	Resource *text = resMan.findResource(ResourceId(kResourceTypeText, 0), 0);
 	uint seeker = 0;
 	if (text) {
 		while (seeker < text->size) {


Commit: a5675c3dbe799acf6ced70ba9e83cdd88252bce9
    https://github.com/scummvm/scummvm/commit/a5675c3dbe799acf6ced70ba9e83cdd88252bce9
Author: Christoph Mallon (christoph.mallon at gmx.de)
Date: 2011-08-07T06:19:08-07:00

Commit Message:
TEENAGENT: Pass streams as references.

Changed paths:
    engines/teenagent/animation.cpp
    engines/teenagent/animation.h
    engines/teenagent/inventory.cpp
    engines/teenagent/scene.cpp
    engines/teenagent/surface.cpp
    engines/teenagent/surface.h
    engines/teenagent/surface_list.cpp
    engines/teenagent/surface_list.h
    engines/teenagent/teenagent.cpp



diff --git a/engines/teenagent/animation.cpp b/engines/teenagent/animation.cpp
index e945bda..56107b6 100644
--- a/engines/teenagent/animation.cpp
+++ b/engines/teenagent/animation.cpp
@@ -106,11 +106,11 @@ void Animation::free() {
 	index = 0;
 }
 
-void Animation::load(Common::SeekableReadStream *s, Type type) {
+void Animation::load(Common::SeekableReadStream &s, Type type) {
 	//fixme: do not reload the same animation each time
 	free();
 
-	if (s == NULL || s->size() <= 1) {
+	if (s.size() <= 1) {
 		debug(1, "empty animation");
 		return;
 	}
@@ -119,29 +119,29 @@ void Animation::load(Common::SeekableReadStream *s, Type type) {
 	int off = 0;
 	switch (type) {
 	case kTypeLan:
-		data_size = s->readUint16LE();
-		if (s->eos()) {
+		data_size = s.readUint16LE();
+		if (s.eos()) {
 			debug(1, "empty animation");
 			return;
 		}
 
 		data_size -= 2;
 		data = new byte[data_size];
-		data_size = s->read(data, data_size);
+		data_size = s.read(data, data_size);
 		/*		for (int i = 0; i < data_size; ++i) {
 					debug(0, "%02x ", data[i]);
 				}
 				debug(0, ", %u frames", data_size / 3);
 		*/
-		frames_count = s->readByte();
+		frames_count = s.readByte();
 		debug(1, "%u physical frames", frames_count);
 		if (frames_count == 0)
 			return;
 
 		frames = new Surface[frames_count];
 
-		s->skip(frames_count * 2 - 2); //sizes
-		/*pos = */s->readUint16LE();
+		s.skip(frames_count * 2 - 2); //sizes
+		/*pos = */s.readUint16LE();
 		//debug(0, "pos?: %04x", pos);
 
 		for (uint16 i = 0; i < frames_count; ++i) {
@@ -152,15 +152,15 @@ void Animation::load(Common::SeekableReadStream *s, Type type) {
 		break;
 
 	case kTypeInventory: {
-		data_size = 3 * s->readByte();
+		data_size = 3 * s.readByte();
 		data = new byte[data_size];
 
 		frames_count = 0;
 		for (byte i = 0; i < data_size / 3; ++i) {
 			int idx = i * 3;
 			/* byte unk = */
-			s->readByte();
-			data[idx] = s->readByte();
+			s.readByte();
+			data[idx] = s.readByte();
 			if (data[idx] == 0)
 				data[idx] = 1; //fixme: investigate
 			if (data[idx] > frames_count)
@@ -179,17 +179,17 @@ void Animation::load(Common::SeekableReadStream *s, Type type) {
 	break;
 
 	case kTypeVaria:
-		frames_count = s->readByte();
+		frames_count = s.readByte();
 		debug(1, "loading varia resource, %u physical frames", frames_count);
 		uint16 offset[255];
 		for (byte i = 0; i < frames_count; ++i) {
-			offset[i] = s->readUint16LE();
+			offset[i] = s.readUint16LE();
 			//debug(0, "%u: %04x", i, offset[i]);
 		}
 		frames = new Surface[frames_count];
 		for (uint16 i = 0; i < frames_count; ++i) {
 			//debug(0, "%04x", offset[i]);
-			s->seek(offset[i] + off);
+			s.seek(offset[i] + off);
 			frames[i].load(s, Surface::kTypeOns);
 		}
 
diff --git a/engines/teenagent/animation.h b/engines/teenagent/animation.h
index e98bb42..d9092d1 100644
--- a/engines/teenagent/animation.h
+++ b/engines/teenagent/animation.h
@@ -35,7 +35,7 @@ public:
 	enum Type {kTypeLan, kTypeVaria, kTypeInventory};
 
 	Animation();
-	void load(Common::SeekableReadStream *s, Type type = kTypeLan);
+	void load(Common::SeekableReadStream&, Type type = kTypeLan);
 	void free();
 
 	Surface *firstFrame();
diff --git a/engines/teenagent/inventory.cpp b/engines/teenagent/inventory.cpp
index 4951b2d..2b858bb 100644
--- a/engines/teenagent/inventory.cpp
+++ b/engines/teenagent/inventory.cpp
@@ -43,7 +43,7 @@ Inventory::Inventory(TeenAgentEngine *engine) {
 		if (!s)
 			error("no inventory background");
 		debug(0, "loading inventory background...");
-		_background.load(s, Surface::kTypeOns);
+		_background.load(*s, Surface::kTypeOns);
 	}
 
 	uint32 items_size = varia.getSize(4);
@@ -300,13 +300,13 @@ void Inventory::Item::load(Inventory *inventory, uint item_id) {
 		if (_animation.empty()) {
 			debug(0, "loading item %d from offset %x", obj->id, inventory->_offset[obj->id - 1]);
 			Common::MemoryReadStream s(inventory->_items + inventory->_offset[obj->id - 1], inventory->_offset[obj->id] - inventory->_offset[obj->id - 1]);
-			_animation.load(&s, Animation::kTypeInventory);
+			_animation.load(s, Animation::kTypeInventory);
 		}
 	} else {
 		if (_surface.empty()) {
 			debug(0, "loading item %d from offset %x", obj->id, inventory->_offset[obj->id - 1]);
 			Common::MemoryReadStream s(inventory->_items + inventory->_offset[obj->id - 1], inventory->_offset[obj->id] - inventory->_offset[obj->id - 1]);
-			_surface.load(&s, Surface::kTypeOns);
+			_surface.load(s, Surface::kTypeOns);
 		}
 	}
 }
diff --git a/engines/teenagent/scene.cpp b/engines/teenagent/scene.cpp
index 4be6c9c..39b77ea 100644
--- a/engines/teenagent/scene.cpp
+++ b/engines/teenagent/scene.cpp
@@ -57,7 +57,7 @@ Scene::Scene(TeenAgentEngine *engine, OSystem *system) : intro(false), _id(0), o
 	if (!s)
 		error("invalid resource data");
 
-	teenagent.load(s, Animation::kTypeVaria);
+	teenagent.load(*s, Animation::kTypeVaria);
 	if (teenagent.empty())
 		error("invalid mark animation");
 
@@ -65,7 +65,7 @@ Scene::Scene(TeenAgentEngine *engine, OSystem *system) : intro(false), _id(0), o
 	if (!s)
 		error("invalid resource data");
 
-	teenagent_idle.load(s, Animation::kTypeVaria);
+	teenagent_idle.load(*s, Animation::kTypeVaria);
 	if (teenagent_idle.empty())
 		error("invalid mark animation");
 
@@ -340,7 +340,7 @@ void Scene::loadOns() {
 		for (uint32 i = 0; i < ons_count; ++i) {
 			Common::ScopedPtr<Common::SeekableReadStream> s(res->ons.getStream(on_id[i]));
 			if (s) {
-				ons[i].load(s, Surface::kTypeOns);
+				ons[i].load(*s, Surface::kTypeOns);
 			}
 		}
 	}
@@ -363,7 +363,7 @@ void Scene::loadLans() {
 
 		Common::ScopedPtr<Common::SeekableReadStream> s(res->loadLan000(res_id));
 		if (s) {
-			animation[i].load(s, Animation::kTypeLan);
+			animation[i].load(*s, Animation::kTypeLan);
 			if (bxv != 0 && bxv != 0xff)
 				animation[i].id = bxv;
 		}
@@ -412,7 +412,7 @@ void Scene::init(int id, const Common::Point &pos) {
 				sub_hack = 2;
 		}
 	}
-	on.load(stream, SurfaceList::kTypeOn, sub_hack);
+	on.load(*stream, SurfaceList::kTypeOn, sub_hack);
 
 	loadOns();
 	loadLans();
@@ -434,7 +434,7 @@ void Scene::playAnimation(byte idx, uint id, bool loop, bool paused, bool ignore
 	if (!s)
 		error("playing animation %u failed", id);
 
-	custom_animation[idx].load(s);
+	custom_animation[idx].load(*s);
 	custom_animation[idx].loop = loop;
 	custom_animation[idx].paused = paused;
 	custom_animation[idx].ignore = ignore;
@@ -446,7 +446,7 @@ void Scene::playActorAnimation(uint id, bool loop, bool ignore) {
 	if (!s)
 		error("playing animation %u failed", id);
 
-	actor_animation.load(s);
+	actor_animation.load(*s);
 	actor_animation.loop = loop;
 	actor_animation.ignore = ignore;
 	actor_animation.id = id;
diff --git a/engines/teenagent/surface.cpp b/engines/teenagent/surface.cpp
index 2e23c7a..e8b5a8a 100644
--- a/engines/teenagent/surface.cpp
+++ b/engines/teenagent/surface.cpp
@@ -33,26 +33,26 @@ Surface::~Surface() {
 	free();
 }
 
-void Surface::load(Common::SeekableReadStream *stream, Type type) {
+void Surface::load(Common::SeekableReadStream &stream, Type type) {
 	//debug(0, "load()");
 	free();
 
 	x = y = 0;
 
-	uint16 w_ = stream->readUint16LE();
-	uint16 h_ = stream->readUint16LE();
+	uint16 w_ = stream.readUint16LE();
+	uint16 h_ = stream.readUint16LE();
 
 	if (type != kTypeLan) {
-		uint16 pos = stream->readUint16LE();
+		uint16 pos = stream.readUint16LE();
 		x = pos % 320;
 		y = pos / 320;
 	}
 
 	//debug(0, "declared info: %ux%u (%04xx%04x) -> %u,%u", w_, h_, w_, h_, x, y);
-	if (stream->eos() || w_ == 0)
+	if (stream.eos() || w_ == 0)
 		return;
 
-	if (w_ * h_ > stream->size()) {
+	if (w_ * h_ > stream.size()) {
 		debug(0, "invalid surface %ux%u -> %u,%u", w_, h_, x, y);
 		return;
 	}
@@ -60,7 +60,7 @@ void Surface::load(Common::SeekableReadStream *stream, Type type) {
 	//debug(0, "creating surface %ux%u -> %u,%u", w_, h_, x, y);
 	create(w_, h_, Graphics::PixelFormat::createFormatCLUT8());
 
-	stream->read(pixels, w_ * h_);
+	stream.read(pixels, w_ * h_);
 }
 
 Common::Rect Surface::render(Graphics::Surface *surface, int dx, int dy, bool mirror, Common::Rect src_rect, uint zoom) const {
diff --git a/engines/teenagent/surface.h b/engines/teenagent/surface.h
index 5f74176..64e45a7 100644
--- a/engines/teenagent/surface.h
+++ b/engines/teenagent/surface.h
@@ -40,7 +40,7 @@ public:
 
 	Surface();
 	~Surface();
-	void load(Common::SeekableReadStream *stream, Type type);
+	void load(Common::SeekableReadStream&, Type type);
 	Common::Rect render(Graphics::Surface *surface, int dx = 0, int dy = 0, bool mirror = false, Common::Rect src_rect = Common::Rect(), uint zoom = 256) const;
 
 	bool empty() const { return pixels == NULL; }
diff --git a/engines/teenagent/surface_list.cpp b/engines/teenagent/surface_list.cpp
index e98153a..7f7eb1d 100644
--- a/engines/teenagent/surface_list.cpp
+++ b/engines/teenagent/surface_list.cpp
@@ -31,11 +31,11 @@ SurfaceList::~SurfaceList() {
 	free();
 }
 
-void SurfaceList::load(Common::SeekableReadStream *stream, Type type, int sub_hack) {
+void SurfaceList::load(Common::SeekableReadStream &stream, Type type, int sub_hack) {
 	free();
 
-	byte fn = stream->readByte();
-	if (stream->eos())
+	byte fn = stream.readByte();
+	if (stream.eos())
 		return;
 
 	surfaces_n = fn - sub_hack;
@@ -47,11 +47,11 @@ void SurfaceList::load(Common::SeekableReadStream *stream, Type type, int sub_ha
 	surfaces = new Surface[surfaces_n];
 
 	for (byte i = 0; i < surfaces_n; ++i) {
-		uint offset = stream->readUint16LE();
-		uint pos = stream->pos();
-		stream->seek(offset);
+		uint offset = stream.readUint16LE();
+		uint pos = stream.pos();
+		stream.seek(offset);
 		surfaces[i].load(stream, Surface::kTypeOns);
-		stream->seek(pos);
+		stream.seek(pos);
 	}
 }
 
diff --git a/engines/teenagent/surface_list.h b/engines/teenagent/surface_list.h
index a199839..fcb4fb2 100644
--- a/engines/teenagent/surface_list.h
+++ b/engines/teenagent/surface_list.h
@@ -33,7 +33,7 @@ public:
 
 	SurfaceList();
 	~SurfaceList();
-	void load(Common::SeekableReadStream *stream, Type type, int sub_hack = 0);
+	void load(Common::SeekableReadStream&, Type type, int sub_hack = 0);
 	void free();
 	void render(Graphics::Surface *surface, const Common::Rect & clip) const;
 
diff --git a/engines/teenagent/teenagent.cpp b/engines/teenagent/teenagent.cpp
index 0289b99..e6a2483 100644
--- a/engines/teenagent/teenagent.cpp
+++ b/engines/teenagent/teenagent.cpp
@@ -386,7 +386,7 @@ bool TeenAgentEngine::showLogo() {
 			}
 
 			Surface s;
-			s.load(frame, Surface::kTypeOns);
+			s.load(*frame, Surface::kTypeOns);
 			if (s.empty()) {
 				free(bg);
 				return true;


Commit: c21f87836e9f292c8d6589ece03f6ccdc40dafc5
    https://github.com/scummvm/scummvm/commit/c21f87836e9f292c8d6589ece03f6ccdc40dafc5
Author: Christoph Mallon (christoph.mallon at gmx.de)
Date: 2011-08-07T06:19:08-07:00

Commit Message:
PSP: Pass the stream as reference to PngLoader.

Changed paths:
    backends/platform/psp/image_viewer.cpp
    backends/platform/psp/png_loader.cpp
    backends/platform/psp/png_loader.h
    backends/platform/psp/pspkeyboard.cpp



diff --git a/backends/platform/psp/image_viewer.cpp b/backends/platform/psp/image_viewer.cpp
index dbc7cc4..98205dd 100644
--- a/backends/platform/psp/image_viewer.cpp
+++ b/backends/platform/psp/image_viewer.cpp
@@ -69,7 +69,7 @@ bool ImageViewer::load(int imageNum) {
 	assert(_renderer);
 
 	// Load a PNG into our buffer and palette. Size it by the actual size of the image
-	PngLoader image(file, *_buffer, *_palette, Buffer::kSizeBySourceSize);
+	PngLoader image(*file, *_buffer, *_palette, Buffer::kSizeBySourceSize);
 
 	PngLoader::Status status = image.allocate();	// allocate the buffers for the file
 
diff --git a/backends/platform/psp/png_loader.cpp b/backends/platform/psp/png_loader.cpp
index 1637753..4de13d1 100644
--- a/backends/platform/psp/png_loader.cpp
+++ b/backends/platform/psp/png_loader.cpp
@@ -78,7 +78,7 @@ PngLoader::Status PngLoader::allocate() {
 bool PngLoader::load() {
 	DEBUG_ENTER_FUNC();
 	// Try to load the image
-	_file->seek(0);	// Go back to start
+	_file.seek(0);	// Go back to start
 
 	if (!loadImageIntoBuffer()) {
 		PSP_DEBUG_PRINT("failed to load image\n");
@@ -99,11 +99,9 @@ void PngLoader::warningFn(png_structp png_ptr, png_const_charp warning_msg) {
 // Read function for png library to be able to read from our SeekableReadStream
 //
 void PngLoader::libReadFunc(png_structp pngPtr, png_bytep data, png_size_t length) {
-	Common::SeekableReadStream *file;
+	Common::SeekableReadStream &file = *(Common::SeekableReadStream *)pngPtr->io_ptr;
 
-	file = (Common::SeekableReadStream *)pngPtr->io_ptr;
-
-	file->read(data, length);
+	file.read(data, length);
 }
 
 bool PngLoader::basicImageLoad() {
@@ -120,7 +118,7 @@ bool PngLoader::basicImageLoad() {
 		return false;
 	}
 	// Set the png lib to use our read function
-	png_set_read_fn(_pngPtr, (void *)_file, libReadFunc);
+	png_set_read_fn(_pngPtr, &_file, libReadFunc);
 
 	unsigned int sig_read = 0;
 
diff --git a/backends/platform/psp/png_loader.h b/backends/platform/psp/png_loader.h
index 0ff9d8a..48a3220 100644
--- a/backends/platform/psp/png_loader.h
+++ b/backends/platform/psp/png_loader.h
@@ -34,7 +34,7 @@ private:
 	static void warningFn(png_structp png_ptr, png_const_charp warning_msg);
 	static void libReadFunc(png_structp pngPtr, png_bytep data, png_size_t length);
 
-	Common::SeekableReadStream *_file;
+	Common::SeekableReadStream &_file;
 	Buffer *_buffer;
 	Palette *_palette;
 
@@ -57,7 +57,7 @@ public:
 		BAD_FILE
 	};
 
-	PngLoader(Common::SeekableReadStream *file, Buffer &buffer, Palette &palette,
+	PngLoader(Common::SeekableReadStream &file, Buffer &buffer, Palette &palette,
 		Buffer::HowToSize sizeBy = Buffer::kSizeByTextureSize) :
 			_file(file), _buffer(&buffer), _palette(&palette),
 			_width(0), _height(0), _paletteSize(0),
diff --git a/backends/platform/psp/pspkeyboard.cpp b/backends/platform/psp/pspkeyboard.cpp
index 43c4cad..66efe91 100644
--- a/backends/platform/psp/pspkeyboard.cpp
+++ b/backends/platform/psp/pspkeyboard.cpp
@@ -298,7 +298,7 @@ bool PSPKeyboard::load() {
 			goto ERROR;
 		}
 
-		PngLoader image(file, _buffers[i], _palettes[i]);
+		PngLoader image(*file, _buffers[i], _palettes[i]);
 
 		if (image.allocate() != PngLoader::OK) {
 			PSP_ERROR("Failed to allocate memory for keyboard image %s\n", _guiStrings[i]);


Commit: 2f23ff72c1d804d9d0e3ac09c46f52fd6b23a68c
    https://github.com/scummvm/scummvm/commit/2f23ff72c1d804d9d0e3ac09c46f52fd6b23a68c
Author: Christoph Mallon (christoph.mallon at gmx.de)
Date: 2011-08-07T06:19:08-07:00

Commit Message:
COMMON: Remove implicit conversion from ScopedPtr<T> to T*.

Changed paths:
    common/ptr.h



diff --git a/common/ptr.h b/common/ptr.h
index c97d7a4..d06a25e 100644
--- a/common/ptr.h
+++ b/common/ptr.h
@@ -231,7 +231,6 @@ public:
 
 	ReferenceType operator*() const { return *_pointer; }
 	PointerType operator->() const { return _pointer; }
-	operator PointerType() const { return _pointer; }
 
 	/**
 	 * Implicit conversion operator to bool for convenience, to make


Commit: a5a8833c059f28c85e392a3cd22c361d38ef95ff
    https://github.com/scummvm/scummvm/commit/a5a8833c059f28c85e392a3cd22c361d38ef95ff
Author: Christoph Mallon (christoph.mallon at gmx.de)
Date: 2011-08-07T06:19:08-07:00

Commit Message:
COMMON: Add DisposablePtr<T>, which replaces many repeated implementations of a dispose flag.

Changed paths:
    audio/audiostream.cpp
    audio/audiostream.h
    audio/decoders/adpcm.cpp
    audio/decoders/adpcm_intern.h
    audio/decoders/mp3.cpp
    audio/decoders/raw.cpp
    audio/decoders/vorbis.cpp
    audio/mixer.cpp
    backends/platform/psp/mp3.cpp
    backends/platform/psp/mp3.h
    common/ptr.h
    common/stream.cpp
    common/substream.h
    engines/agos/sound.cpp
    engines/drascula/drascula.h
    engines/drascula/resource.cpp



diff --git a/audio/audiostream.cpp b/audio/audiostream.cpp
index 547aa77..1c63ce9 100644
--- a/audio/audiostream.cpp
+++ b/audio/audiostream.cpp
@@ -93,7 +93,7 @@ SeekableAudioStream *SeekableAudioStream::openStreamFile(const Common::String &b
 #pragma mark -
 
 LoopingAudioStream::LoopingAudioStream(RewindableAudioStream *stream, uint loops, DisposeAfterUse::Flag disposeAfterUse)
-    : _parent(stream), _disposeAfterUse(disposeAfterUse), _loops(loops), _completeIterations(0) {
+    : _parent(stream, disposeAfterUse), _loops(loops), _completeIterations(0) {
 	assert(stream);
 
 	if (!stream->rewind()) {
@@ -102,11 +102,6 @@ LoopingAudioStream::LoopingAudioStream(RewindableAudioStream *stream, uint loops
 	}
 }
 
-LoopingAudioStream::~LoopingAudioStream() {
-	if (_disposeAfterUse == DisposeAfterUse::YES)
-		delete _parent;
-}
-
 int LoopingAudioStream::readBuffer(int16 *buffer, const int numSamples) {
 	if ((_loops && _completeIterations == _loops) || !numSamples)
 		return 0;
@@ -169,7 +164,7 @@ SubLoopingAudioStream::SubLoopingAudioStream(SeekableAudioStream *stream,
                                              const Timestamp loopStart,
                                              const Timestamp loopEnd,
                                              DisposeAfterUse::Flag disposeAfterUse)
-    : _parent(stream), _disposeAfterUse(disposeAfterUse), _loops(loops),
+    : _parent(stream, disposeAfterUse), _loops(loops),
       _pos(0, getRate() * (isStereo() ? 2 : 1)),
       _loopStart(convertTimeToStreamPos(loopStart, getRate(), isStereo())),
       _loopEnd(convertTimeToStreamPos(loopEnd, getRate(), isStereo())),
@@ -180,11 +175,6 @@ SubLoopingAudioStream::SubLoopingAudioStream(SeekableAudioStream *stream,
 		_done = true;
 }
 
-SubLoopingAudioStream::~SubLoopingAudioStream() {
-	if (_disposeAfterUse == DisposeAfterUse::YES)
-		delete _parent;
-}
-
 int SubLoopingAudioStream::readBuffer(int16 *buffer, const int numSamples) {
 	if (_done)
 		return 0;
@@ -225,7 +215,7 @@ int SubLoopingAudioStream::readBuffer(int16 *buffer, const int numSamples) {
 #pragma mark -
 
 SubSeekableAudioStream::SubSeekableAudioStream(SeekableAudioStream *parent, const Timestamp start, const Timestamp end, DisposeAfterUse::Flag disposeAfterUse)
-    : _parent(parent), _disposeAfterUse(disposeAfterUse),
+    : _parent(parent, disposeAfterUse),
       _start(convertTimeToStreamPos(start, getRate(), isStereo())),
       _pos(0, getRate() * (isStereo() ? 2 : 1)),
       _length(convertTimeToStreamPos(end, getRate(), isStereo()) - _start) {
@@ -234,11 +224,6 @@ SubSeekableAudioStream::SubSeekableAudioStream(SeekableAudioStream *parent, cons
 	_parent->seek(_start);
 }
 
-SubSeekableAudioStream::~SubSeekableAudioStream() {
-	if (_disposeAfterUse)
-		delete _parent;
-}
-
 int SubSeekableAudioStream::readBuffer(int16 *buffer, const int numSamples) {
 	int framesLeft = MIN(_length.frameDiff(_pos), numSamples);
 	int framesRead = _parent->readBuffer(buffer, framesLeft);
diff --git a/audio/audiostream.h b/audio/audiostream.h
index 0ffaa24..9c28e4d 100644
--- a/audio/audiostream.h
+++ b/audio/audiostream.h
@@ -23,6 +23,7 @@
 #ifndef SOUND_AUDIOSTREAM_H
 #define SOUND_AUDIOSTREAM_H
 
+#include "common/ptr.h"
 #include "common/scummsys.h"
 #include "common/str.h"
 #include "common/types.h"
@@ -114,7 +115,6 @@ public:
 	 * @param disposeAfterUse Destroy the stream after the LoopingAudioStream has finished playback.
 	 */
 	LoopingAudioStream(RewindableAudioStream *stream, uint loops, DisposeAfterUse::Flag disposeAfterUse = DisposeAfterUse::YES);
-	~LoopingAudioStream();
 
 	int readBuffer(int16 *buffer, const int numSamples);
 	bool endOfData() const;
@@ -129,8 +129,7 @@ public:
 	 */
 	uint getCompleteIterations() const { return _completeIterations; }
 private:
-	RewindableAudioStream *_parent;
-	DisposeAfterUse::Flag _disposeAfterUse;
+	Common::DisposablePtr<RewindableAudioStream> _parent;
 
 	uint _loops;
 	uint _completeIterations;
@@ -246,7 +245,6 @@ public:
 	                      const Timestamp loopStart,
 	                      const Timestamp loopEnd,
 	                      DisposeAfterUse::Flag disposeAfterUse = DisposeAfterUse::YES);
-	~SubLoopingAudioStream();
 
 	int readBuffer(int16 *buffer, const int numSamples);
 	bool endOfData() const { return _done; }
@@ -254,8 +252,7 @@ public:
 	bool isStereo() const { return _parent->isStereo(); }
 	int getRate() const { return _parent->getRate(); }
 private:
-	SeekableAudioStream *_parent;
-	DisposeAfterUse::Flag _disposeAfterUse;
+	Common::DisposablePtr<SeekableAudioStream> _parent;
 
 	uint _loops;
 	Timestamp _pos;
@@ -283,7 +280,6 @@ public:
 	 * @param disposeAfterUse Whether the parent stream object should be destroyed on destruction of the SubSeekableAudioStream.
 	 */
 	SubSeekableAudioStream(SeekableAudioStream *parent, const Timestamp start, const Timestamp end, DisposeAfterUse::Flag disposeAfterUse = DisposeAfterUse::YES);
-	~SubSeekableAudioStream();
 
 	int readBuffer(int16 *buffer, const int numSamples);
 
@@ -297,8 +293,7 @@ public:
 
 	Timestamp getLength() const { return _length; }
 private:
-	SeekableAudioStream *_parent;
-	DisposeAfterUse::Flag _disposeAfterUse;
+	Common::DisposablePtr<SeekableAudioStream> _parent;
 
 	const Timestamp _start;
 	const Timestamp _length;
diff --git a/audio/decoders/adpcm.cpp b/audio/decoders/adpcm.cpp
index 116f2f7..535652a 100644
--- a/audio/decoders/adpcm.cpp
+++ b/audio/decoders/adpcm.cpp
@@ -41,8 +41,7 @@ namespace Audio {
 //   <http://wiki.multimedia.cx/index.php?title=Microsoft_IMA_ADPCM>.
 
 ADPCMStream::ADPCMStream(Common::SeekableReadStream *stream, DisposeAfterUse::Flag disposeAfterUse, uint32 size, int rate, int channels, uint32 blockAlign)
-	: _stream(stream),
-		_disposeAfterUse(disposeAfterUse),
+	: _stream(stream, disposeAfterUse),
 		_startpos(stream->pos()),
 		_endpos(_startpos + size),
 		_channels(channels),
@@ -52,11 +51,6 @@ ADPCMStream::ADPCMStream(Common::SeekableReadStream *stream, DisposeAfterUse::Fl
 	reset();
 }
 
-ADPCMStream::~ADPCMStream() {
-	if (_disposeAfterUse == DisposeAfterUse::YES)
-		delete _stream;
-}
-
 void ADPCMStream::reset() {
 	memset(&_status, 0, sizeof(_status));
 	_blockPos[0] = _blockPos[1] = _blockAlign; // To make sure first header is read
diff --git a/audio/decoders/adpcm_intern.h b/audio/decoders/adpcm_intern.h
index c9f894f..38514d7 100644
--- a/audio/decoders/adpcm_intern.h
+++ b/audio/decoders/adpcm_intern.h
@@ -33,6 +33,7 @@
 
 #include "audio/audiostream.h"
 #include "common/endian.h"
+#include "common/ptr.h"
 #include "common/stream.h"
 #include "common/textconsole.h"
 
@@ -41,8 +42,7 @@ namespace Audio {
 
 class ADPCMStream : public RewindableAudioStream {
 protected:
-	Common::SeekableReadStream *_stream;
-	const DisposeAfterUse::Flag _disposeAfterUse;
+	Common::DisposablePtr<Common::SeekableReadStream> _stream;
 	const int32 _startpos;
 	const int32 _endpos;
 	const int _channels;
@@ -62,7 +62,6 @@ protected:
 
 public:
 	ADPCMStream(Common::SeekableReadStream *stream, DisposeAfterUse::Flag disposeAfterUse, uint32 size, int rate, int channels, uint32 blockAlign);
-	~ADPCMStream();
 
 	virtual bool endOfData() const { return (_stream->eos() || _stream->pos() >= _endpos); }
 	virtual bool isStereo() const	{ return _channels == 2; }
diff --git a/audio/decoders/mp3.cpp b/audio/decoders/mp3.cpp
index 8d7f006..0066994 100644
--- a/audio/decoders/mp3.cpp
+++ b/audio/decoders/mp3.cpp
@@ -25,6 +25,7 @@
 #ifdef USE_MAD
 
 #include "common/debug.h"
+#include "common/ptr.h"
 #include "common/stream.h"
 #include "common/textconsole.h"
 #include "common/util.h"
@@ -52,8 +53,7 @@ protected:
 		MP3_STATE_EOS		// end of data reached (may need to loop)
 	};
 
-	Common::SeekableReadStream *_inStream;
-	DisposeAfterUse::Flag _disposeAfterUse;
+	Common::DisposablePtr<Common::SeekableReadStream> _inStream;
 
 	uint _posInFrame;
 	State _state;
@@ -95,8 +95,7 @@ protected:
 };
 
 MP3Stream::MP3Stream(Common::SeekableReadStream *inStream, DisposeAfterUse::Flag dispose) :
-	_inStream(inStream),
-	_disposeAfterUse(dispose),
+	_inStream(inStream, dispose),
 	_posInFrame(0),
 	_state(MP3_STATE_INIT),
 	_length(0, 1000),
@@ -134,9 +133,6 @@ MP3Stream::MP3Stream(Common::SeekableReadStream *inStream, DisposeAfterUse::Flag
 
 MP3Stream::~MP3Stream() {
 	deinitStream();
-
-	if (_disposeAfterUse == DisposeAfterUse::YES)
-		delete _inStream;
 }
 
 void MP3Stream::decodeMP3Data() {
diff --git a/audio/decoders/raw.cpp b/audio/decoders/raw.cpp
index 4789fd0..881b8c1 100644
--- a/audio/decoders/raw.cpp
+++ b/audio/decoders/raw.cpp
@@ -51,7 +51,7 @@ template<bool is16Bit, bool isUnsigned, bool isLE>
 class RawStream : public SeekableAudioStream {
 public:
 	RawStream(int rate, bool stereo, DisposeAfterUse::Flag disposeStream, Common::SeekableReadStream *stream, const RawStreamBlockList &blocks)
-		: _rate(rate), _isStereo(stereo), _playtime(0, rate), _stream(stream), _disposeAfterUse(disposeStream), _blocks(blocks), _curBlock(_blocks.begin()), _blockLeft(0), _buffer(0) {
+		: _rate(rate), _isStereo(stereo), _playtime(0, rate), _stream(stream, disposeStream), _blocks(blocks), _curBlock(_blocks.begin()), _blockLeft(0), _buffer(0) {
 
 		assert(_blocks.size() > 0);
 
@@ -82,9 +82,6 @@ public:
 	}
 
 	~RawStream() {
-		if (_disposeAfterUse == DisposeAfterUse::YES)
-			delete _stream;
-
 		delete[] _buffer;
 	}
 
@@ -98,15 +95,14 @@ public:
 
 	bool seek(const Timestamp &where);
 private:
-	const int _rate;                               ///< Sample rate of stream
-	const bool _isStereo;                          ///< Whether this is an stereo stream
-	Timestamp _playtime;                           ///< Calculated total play time
-	Common::SeekableReadStream *_stream;           ///< Stream to read data from
-	const DisposeAfterUse::Flag _disposeAfterUse;  ///< Indicates whether the stream object should be deleted when this RawStream is destructed
-	const RawStreamBlockList _blocks;              ///< Audio block list
-
-	RawStreamBlockList::const_iterator _curBlock;  ///< Current audio block number
-	int32 _blockLeft;                              ///< How many bytes are still left in the current block
+	const int _rate;                                           ///< Sample rate of stream
+	const bool _isStereo;                                      ///< Whether this is an stereo stream
+	Timestamp _playtime;                                       ///< Calculated total play time
+	Common::DisposablePtr<Common::SeekableReadStream> _stream; ///< Stream to read data from
+	const RawStreamBlockList _blocks;                          ///< Audio block list
+
+	RawStreamBlockList::const_iterator _curBlock;              ///< Current audio block number
+	int32 _blockLeft;                                          ///< How many bytes are still left in the current block
 
 	/**
 	 * Advance one block in the stream in case
diff --git a/audio/decoders/vorbis.cpp b/audio/decoders/vorbis.cpp
index e10ec11..455803d 100644
--- a/audio/decoders/vorbis.cpp
+++ b/audio/decoders/vorbis.cpp
@@ -29,6 +29,7 @@
 
 #ifdef USE_VORBIS
 
+#include "common/ptr.h"
 #include "common/stream.h"
 #include "common/textconsole.h"
 #include "common/util.h"
@@ -89,8 +90,7 @@ static ov_callbacks g_stream_wrap = {
 
 class VorbisStream : public SeekableAudioStream {
 protected:
-	Common::SeekableReadStream *_inStream;
-	DisposeAfterUse::Flag _disposeAfterUse;
+	Common::DisposablePtr<Common::SeekableReadStream> _inStream;
 
 	bool _isStereo;
 	int _rate;
@@ -121,8 +121,7 @@ protected:
 };
 
 VorbisStream::VorbisStream(Common::SeekableReadStream *inStream, DisposeAfterUse::Flag dispose) :
-	_inStream(inStream),
-	_disposeAfterUse(dispose),
+	_inStream(inStream, dispose),
 	_length(0, 1000),
 	_bufferEnd(_buffer + ARRAYSIZE(_buffer)) {
 
@@ -150,8 +149,6 @@ VorbisStream::VorbisStream(Common::SeekableReadStream *inStream, DisposeAfterUse
 
 VorbisStream::~VorbisStream() {
 	ov_clear(&_ovFile);
-	if (_disposeAfterUse == DisposeAfterUse::YES)
-		delete _inStream;
 }
 
 int VorbisStream::readBuffer(int16 *buffer, const int numSamples) {
diff --git a/audio/mixer.cpp b/audio/mixer.cpp
index 128224a..9657661 100644
--- a/audio/mixer.cpp
+++ b/audio/mixer.cpp
@@ -163,9 +163,8 @@ private:
 	uint32 _pauseStartTime;
 	uint32 _pauseTime;
 
-	DisposeAfterUse::Flag _autofreeStream;
 	RateConverter *_converter;
-	AudioStream *_stream;
+	Common::DisposablePtr<AudioStream> _stream;
 };
 
 #pragma mark -
@@ -492,8 +491,8 @@ Channel::Channel(Mixer *mixer, Mixer::SoundType type, AudioStream *stream,
                  DisposeAfterUse::Flag autofreeStream, bool reverseStereo, int id, bool permanent)
     : _type(type), _mixer(mixer), _id(id), _permanent(permanent), _volume(Mixer::kMaxChannelVolume),
       _balance(0), _pauseLevel(0), _samplesConsumed(0), _samplesDecoded(0), _mixerTimeStamp(0),
-      _pauseStartTime(0), _pauseTime(0), _autofreeStream(autofreeStream), _converter(0),
-      _stream(stream) {
+      _pauseStartTime(0), _pauseTime(0), _converter(0),
+      _stream(stream, autofreeStream) {
 	assert(mixer);
 	assert(stream);
 
@@ -503,8 +502,6 @@ Channel::Channel(Mixer *mixer, Mixer::SoundType type, AudioStream *stream,
 
 Channel::~Channel() {
 	delete _converter;
-	if (_autofreeStream == DisposeAfterUse::YES)
-		delete _stream;
 }
 
 void Channel::setVolume(const byte volume) {
diff --git a/backends/platform/psp/mp3.cpp b/backends/platform/psp/mp3.cpp
index 266e31e..3dbf311 100644
--- a/backends/platform/psp/mp3.cpp
+++ b/backends/platform/psp/mp3.cpp
@@ -179,8 +179,7 @@ bool Mp3PspStream::loadStartAudioModule(const char *modname, int partition){
 // TODO: make parallel function for unloading the 1.50 modules
 
 Mp3PspStream::Mp3PspStream(Common::SeekableReadStream *inStream, DisposeAfterUse::Flag dispose) :
-	_inStream(inStream),
-	_disposeAfterUse(dispose),
+	_inStream(inStream, dispose),
 	_pcmLength(0),
 	_posInFrame(0),
 	_state(MP3_STATE_INIT),
@@ -274,9 +273,6 @@ Mp3PspStream::~Mp3PspStream() {
 
 	deinitStream();
 	releaseStreamME(); 	// free the memory used for this stream
-
-	if (_disposeAfterUse == DisposeAfterUse::YES)
-		delete _inStream;
 }
 
 void Mp3PspStream::deinitStream() {
diff --git a/backends/platform/psp/mp3.h b/backends/platform/psp/mp3.h
index 8b01fe4..f7bfdda 100644
--- a/backends/platform/psp/mp3.h
+++ b/backends/platform/psp/mp3.h
@@ -23,6 +23,7 @@
 #ifndef SOUND_MP3_PSP_H
 #define SOUND_MP3_PSP_H
 
+#include "common/ptr.h"
 #include "common/types.h"
 #include "common/scummsys.h"
 
@@ -48,8 +49,7 @@ protected:
 	byte _codecInBuffer[3072] __attribute__((aligned(64))); // the codec always needs alignment
 	unsigned long _codecParams[65]__attribute__((aligned(64)));		// TODO: change to struct
 
-	Common::SeekableReadStream *_inStream;
-	DisposeAfterUse::Flag _disposeAfterUse;
+	Common::DisposablePtr<Common::SeekableReadStream> _inStream;
 
 	uint32 _pcmLength;		// how many pcm samples we have for this type of file (x2 this for stereo)
 
diff --git a/common/ptr.h b/common/ptr.h
index d06a25e..2b0670c 100644
--- a/common/ptr.h
+++ b/common/ptr.h
@@ -24,6 +24,7 @@
 
 #include "common/scummsys.h"
 #include "common/noncopyable.h"
+#include "common/types.h"
 
 namespace Common {
 
@@ -273,6 +274,41 @@ private:
 	PointerType _pointer;
 };
 
+
+template<typename T>
+class DisposablePtr : NonCopyable {
+public:
+	typedef T  ValueType;
+	typedef T *PointerType;
+	typedef T &ReferenceType;
+
+	explicit DisposablePtr(PointerType o, DisposeAfterUse::Flag dispose) : _pointer(o), _dispose(dispose) {}
+
+	~DisposablePtr() {
+		if (_dispose) delete _pointer;
+	}
+
+	ReferenceType operator*() const { return *_pointer; }
+	PointerType operator->() const { return _pointer; }
+
+	/**
+	 * Implicit conversion operator to bool for convenience, to make
+	 * checks like "if (scopedPtr) ..." possible.
+	 */
+	operator bool() const { return _pointer; }
+
+	/**
+	 * Returns the plain pointer value.
+	 *
+	 * @return the pointer the DisposablePtr manages
+	 */
+	PointerType get() const { return _pointer; }
+
+private:
+	PointerType           _pointer;
+	DisposeAfterUse::Flag _dispose;
+};
+
 } // End of namespace Common
 
 #endif
diff --git a/common/stream.cpp b/common/stream.cpp
index 60b40d0..30b3bca 100644
--- a/common/stream.cpp
+++ b/common/stream.cpp
@@ -20,6 +20,7 @@
  *
  */
 
+#include "common/ptr.h"
 #include "common/stream.h"
 #include "common/memstream.h"
 #include "common/substream.h"
@@ -258,8 +259,7 @@ namespace {
  */
 class BufferedReadStream : virtual public ReadStream {
 protected:
-	ReadStream *_parentStream;
-	DisposeAfterUse::Flag _disposeParentStream;
+	DisposablePtr<ReadStream> _parentStream;
 	byte *_buf;
 	uint32 _pos;
 	bool _eos; // end of stream
@@ -278,8 +278,7 @@ public:
 };
 
 BufferedReadStream::BufferedReadStream(ReadStream *parentStream, uint32 bufSize, DisposeAfterUse::Flag disposeParentStream)
-	: _parentStream(parentStream),
-	_disposeParentStream(disposeParentStream),
+	: _parentStream(parentStream, disposeParentStream),
 	_pos(0),
 	_eos(false),
 	_bufSize(0),
@@ -291,8 +290,6 @@ BufferedReadStream::BufferedReadStream(ReadStream *parentStream, uint32 bufSize,
 }
 
 BufferedReadStream::~BufferedReadStream() {
-	if (_disposeParentStream)
-		delete _parentStream;
 	delete[] _buf;
 }
 
diff --git a/common/substream.h b/common/substream.h
index f4f79ff..7e67389 100644
--- a/common/substream.h
+++ b/common/substream.h
@@ -23,6 +23,7 @@
 #ifndef COMMON_SUBSTREAM_H
 #define COMMON_SUBSTREAM_H
 
+#include "common/ptr.h"
 #include "common/stream.h"
 #include "common/types.h"
 
@@ -38,24 +39,18 @@ namespace Common {
  */
 class SubReadStream : virtual public ReadStream {
 protected:
-	ReadStream *_parentStream;
-	DisposeAfterUse::Flag _disposeParentStream;
+	DisposablePtr<ReadStream> _parentStream;
 	uint32 _pos;
 	uint32 _end;
 	bool _eos;
 public:
 	SubReadStream(ReadStream *parentStream, uint32 end, DisposeAfterUse::Flag disposeParentStream = DisposeAfterUse::NO)
-		: _parentStream(parentStream),
-		  _disposeParentStream(disposeParentStream),
+		: _parentStream(parentStream, disposeParentStream),
 		  _pos(0),
 		  _end(end),
 		  _eos(false) {
 		assert(parentStream);
 	}
-	~SubReadStream() {
-		if (_disposeParentStream)
-			delete _parentStream;
-	}
 
 	virtual bool eos() const { return _eos | _parentStream->eos(); }
 	virtual bool err() const { return _parentStream->err(); }
diff --git a/engines/agos/sound.cpp b/engines/agos/sound.cpp
index 03932aa..11a1cd7 100644
--- a/engines/agos/sound.cpp
+++ b/engines/agos/sound.cpp
@@ -22,6 +22,7 @@
 
 #include "common/file.h"
 #include "common/memstream.h"
+#include "common/ptr.h"
 #include "common/textconsole.h"
 #include "common/util.h"
 
@@ -43,11 +44,10 @@ namespace AGOS {
 
 class BaseSound : Common::NonCopyable {
 protected:
-	Common::File *_file;
+	Common::DisposablePtr<Common::File> _file;
 	uint32 *_offsets;
 	Audio::Mixer *_mixer;
 	bool _freeOffsets;
-	DisposeAfterUse::Flag _disposeFile;
 
 public:
 	BaseSound(Audio::Mixer *mixer, Common::File *file, uint32 base, bool bigEndian, DisposeAfterUse::Flag disposeFileAfterUse = DisposeAfterUse::YES);
@@ -62,7 +62,7 @@ public:
 };
 
 BaseSound::BaseSound(Audio::Mixer *mixer, Common::File *file, uint32 base, bool bigEndian, DisposeAfterUse::Flag disposeFileAfterUse)
-	: _mixer(mixer), _file(file), _disposeFile(disposeFileAfterUse) {
+	: _mixer(mixer), _file(file, disposeFileAfterUse) {
 
 	uint res = 0;
 	uint32 size;
@@ -96,7 +96,7 @@ BaseSound::BaseSound(Audio::Mixer *mixer, Common::File *file, uint32 base, bool
 }
 
 BaseSound::BaseSound(Audio::Mixer *mixer, Common::File *file, uint32 *offsets, DisposeAfterUse::Flag disposeFileAfterUse)
-	: _mixer(mixer), _file(file), _disposeFile(disposeFileAfterUse) {
+	: _mixer(mixer), _file(file, disposeFileAfterUse) {
 
 	_offsets = offsets;
 	_freeOffsets = false;
@@ -105,8 +105,6 @@ BaseSound::BaseSound(Audio::Mixer *mixer, Common::File *file, uint32 *offsets, D
 BaseSound::~BaseSound() {
 	if (_freeOffsets)
 		free(_offsets);
-	if (_disposeFile == DisposeAfterUse::YES)
-		delete _file;
 }
 
 ///////////////////////////////////////////////////////////////////////////////
@@ -234,7 +232,7 @@ Audio::AudioStream *WavSound::makeAudioStream(uint sound) {
 		return NULL;
 
 	_file->seek(_offsets[sound], SEEK_SET);
-	return Audio::makeWAVStream(_file, DisposeAfterUse::NO);
+	return Audio::makeWAVStream(_file.get(), DisposeAfterUse::NO);
 }
 
 void WavSound::playSound(uint sound, uint loopSound, Audio::Mixer::SoundType type, Audio::SoundHandle *handle, bool loop, int vol) {
@@ -257,7 +255,7 @@ public:
 Audio::AudioStream *VocSound::makeAudioStream(uint sound) {
 	assert(_offsets);
 	_file->seek(_offsets[sound], SEEK_SET);
-	return Audio::makeVOCStream(_file, _flags);
+	return Audio::makeVOCStream(_file.get(), _flags);
 }
 
 void VocSound::playSound(uint sound, uint loopSound, Audio::Mixer::SoundType type, Audio::SoundHandle *handle, bool loop, int vol) {
diff --git a/engines/drascula/drascula.h b/engines/drascula/drascula.h
index 2b6aa0f..5ec4684 100644
--- a/engines/drascula/drascula.h
+++ b/engines/drascula/drascula.h
@@ -30,6 +30,7 @@
 #include "common/file.h"
 #include "common/hash-str.h"
 #include "common/keyboard.h"
+#include "common/ptr.h"
 #include "common/random.h"
 #include "common/savefile.h"
 #include "common/system.h"
@@ -264,15 +265,13 @@ private:
 };
 
 class TextResourceParser {
-	Common::SeekableReadStream *_stream;
-	DisposeAfterUse::Flag _dispose;
+	Common::DisposablePtr<Common::SeekableReadStream> _stream;
 	int _maxLen;
 
 	void getLine(char *buf);
 
 public:
 	TextResourceParser(Common::SeekableReadStream *stream, DisposeAfterUse::Flag dispose);
-	~TextResourceParser();
 
 	void parseInt(int &result);
 	void parseString(char *result);
diff --git a/engines/drascula/resource.cpp b/engines/drascula/resource.cpp
index 61609fb..95a95e3 100644
--- a/engines/drascula/resource.cpp
+++ b/engines/drascula/resource.cpp
@@ -42,7 +42,7 @@ Common::SeekableReadStream *ArchiveMan::open(const Common::String &filename) {
 }
 
 TextResourceParser::TextResourceParser(Common::SeekableReadStream *stream, DisposeAfterUse::Flag dispose) :
-	_stream(stream), _dispose(dispose) {
+	_stream(stream, dispose) {
 
 	// NOTE: strangely enough, the code before this refactoring used the size of
 	// the stream as a fixed maximum length for the parser. Using an updated
@@ -50,12 +50,6 @@ TextResourceParser::TextResourceParser(Common::SeekableReadStream *stream, Dispo
 	_maxLen = _stream->size();
 }
 
-TextResourceParser::~TextResourceParser() {
-	if (_dispose == DisposeAfterUse::YES) {
-		delete _stream;
-	}
-}
-
 void TextResourceParser::getLine(char *buf) {
 	byte c;
 	char *b;


Commit: e3e0a317e703fe355275a197043ec8e05005ec7b
    https://github.com/scummvm/scummvm/commit/e3e0a317e703fe355275a197043ec8e05005ec7b
Author: Christoph Mallon (christoph.mallon at gmx.de)
Date: 2011-08-07T06:19:08-07:00

Commit Message:
AUDIO: Simplify complicated loop condition.

- The loop is exited with break; when stream gets assigned, so stream == NULL is always true.
- When iterating using the length of an array a terminator element is unnecessary.

Changed paths:
    audio/audiostream.cpp



diff --git a/audio/audiostream.cpp b/audio/audiostream.cpp
index 1c63ce9..1c5c435 100644
--- a/audio/audiostream.cpp
+++ b/audio/audiostream.cpp
@@ -61,15 +61,13 @@ static const StreamFileFormat STREAM_FILEFORMATS[] = {
 	{ "MPEG Layer 3", ".mp3",  makeMP3Stream },
 #endif
 	{ "MPEG-4 Audio",   ".m4a",  makeQuickTimeStream },
-
-	{ NULL, NULL, NULL } // Terminator
 };
 
 SeekableAudioStream *SeekableAudioStream::openStreamFile(const Common::String &basename) {
 	SeekableAudioStream *stream = NULL;
 	Common::File *fileHandle = new Common::File();
 
-	for (int i = 0; i < ARRAYSIZE(STREAM_FILEFORMATS)-1 && stream == NULL; ++i) {
+	for (int i = 0; i < ARRAYSIZE(STREAM_FILEFORMATS); ++i) {
 		Common::String filename = basename + STREAM_FILEFORMATS[i].fileExtension;
 		fileHandle->open(filename);
 		if (fileHandle->isOpen()) {


Commit: ab80b20a305728ecbe402ab0461c9a10cd7570b5
    https://github.com/scummvm/scummvm/commit/ab80b20a305728ecbe402ab0461c9a10cd7570b5
Author: Christoph Mallon (christoph.mallon at gmx.de)
Date: 2011-08-07T06:19:08-07:00

Commit Message:
COMMON: Replace x + ARRAYSIZE(x) by the simpler ARRAYEND(x).

Changed paths:
    audio/decoders/vorbis.cpp
    audio/mods/maxtrax.cpp
    common/util.h
    devtools/create_kyradat/create_kyradat.cpp
    devtools/create_kyradat/extract.cpp
    engines/kyra/kyra_hof.cpp
    engines/kyra/scene_hof.cpp
    engines/kyra/scene_mr.cpp
    engines/kyra/staticres.cpp
    test/common/algorithm.h



diff --git a/audio/decoders/vorbis.cpp b/audio/decoders/vorbis.cpp
index 455803d..64cacb4 100644
--- a/audio/decoders/vorbis.cpp
+++ b/audio/decoders/vorbis.cpp
@@ -123,7 +123,7 @@ protected:
 VorbisStream::VorbisStream(Common::SeekableReadStream *inStream, DisposeAfterUse::Flag dispose) :
 	_inStream(inStream, dispose),
 	_length(0, 1000),
-	_bufferEnd(_buffer + ARRAYSIZE(_buffer)) {
+	_bufferEnd(ARRAYEND(_buffer)) {
 
 	int res = ov_open_callbacks(inStream, &_ovFile, NULL, 0, g_stream_wrap);
 	if (res < 0) {
diff --git a/audio/mods/maxtrax.cpp b/audio/mods/maxtrax.cpp
index 953bb8f..252c0e3 100644
--- a/audio/mods/maxtrax.cpp
+++ b/audio/mods/maxtrax.cpp
@@ -707,7 +707,7 @@ int8 MaxTrax::noteOn(ChannelContext &channel, const byte note, uint16 volume, ui
 	if ((channel.flags & ChannelContext::kFlagMono) == 0) {
 		voiceNum = pickvoice((channel.flags & ChannelContext::kFlagRightChannel) != 0 ? 1 : 0, pri);
 	} else {
-		VoiceContext *voice = _voiceCtx + ARRAYSIZE(_voiceCtx) - 1;
+		VoiceContext *voice = ARRAYEND(_voiceCtx) - 1;
 		for (voiceNum = ARRAYSIZE(_voiceCtx) - 1; voiceNum >= 0 && voice->channel != &channel; --voiceNum, --voice)
 			;
 		if (voiceNum < 0)
diff --git a/common/util.h b/common/util.h
index 6e14188..a96c7a6 100644
--- a/common/util.h
+++ b/common/util.h
@@ -58,6 +58,11 @@ template<typename T> inline void SWAP(T &a, T &b) { T tmp = a; a = b; b = tmp; }
  */
 #define ARRAYSIZE(x) ((int)(sizeof(x) / sizeof(x[0])))
 
+/**
+ * Compute a pointer to one past the last element of an array.
+ */
+#define ARRAYEND(x) ((x) + ARRAYSIZE((x)))
+
 
 /**
  * @def SCUMMVM_CURRENT_FUNCTION
diff --git a/devtools/create_kyradat/create_kyradat.cpp b/devtools/create_kyradat/create_kyradat.cpp
index ddcc8ad..627b517 100644
--- a/devtools/create_kyradat/create_kyradat.cpp
+++ b/devtools/create_kyradat/create_kyradat.cpp
@@ -331,7 +331,7 @@ const TypeTable gameTable[] = {
 };
 
 byte getGameID(int game) {
-	return std::find(gameTable, gameTable + ARRAYSIZE(gameTable) - 1, game)->value;
+	return std::find(gameTable, ARRAYEND(gameTable) - 1, game)->value;
 }
 
 const TypeTable languageTable[] = {
@@ -347,7 +347,7 @@ const TypeTable languageTable[] = {
 };
 
 byte getLanguageID(int lang) {
-	return std::find(languageTable, languageTable + ARRAYSIZE(languageTable) - 1, lang)->value;
+	return std::find(languageTable, ARRAYEND(languageTable) - 1, lang)->value;
 }
 
 const TypeTable platformTable[] = {
@@ -360,7 +360,7 @@ const TypeTable platformTable[] = {
 };
 
 byte getPlatformID(int platform) {
-	return std::find(platformTable, platformTable + ARRAYSIZE(platformTable) - 1, platform)->value;
+	return std::find(platformTable, ARRAYEND(platformTable) - 1, platform)->value;
 }
 
 const TypeTable specialTable[] = {
@@ -373,7 +373,7 @@ const TypeTable specialTable[] = {
 };
 
 byte getSpecialID(int special) {
-	return std::find(specialTable, specialTable + ARRAYSIZE(specialTable) - 1, special)->value;
+	return std::find(specialTable, ARRAYEND(specialTable) - 1, special)->value;
 }
 
 // filename processing
diff --git a/devtools/create_kyradat/extract.cpp b/devtools/create_kyradat/extract.cpp
index 2aa9fc0..371f2f4 100644
--- a/devtools/create_kyradat/extract.cpp
+++ b/devtools/create_kyradat/extract.cpp
@@ -127,7 +127,7 @@ const ExtractType *findExtractType(const int type) {
 }
 
 byte getTypeID(int type) {
-	return std::find(typeTable, typeTable + ARRAYSIZE(typeTable) - 1, type)->value;
+	return std::find(typeTable, ARRAYEND(typeTable) - 1, type)->value;
 }
 // Extractor implementation
 
diff --git a/engines/kyra/kyra_hof.cpp b/engines/kyra/kyra_hof.cpp
index d38868a..432cf1a 100644
--- a/engines/kyra/kyra_hof.cpp
+++ b/engines/kyra/kyra_hof.cpp
@@ -1084,7 +1084,7 @@ void KyraEngine_HoF::loadNPCScript() {
 #pragma mark -
 
 void KyraEngine_HoF::resetScaleTable() {
-	Common::set_to(_scaleTable, _scaleTable + ARRAYSIZE(_scaleTable), 0x100);
+	Common::set_to(_scaleTable, ARRAYEND(_scaleTable), 0x100);
 }
 
 void KyraEngine_HoF::setScaleTableItem(int item, int data) {
@@ -1674,7 +1674,7 @@ void KyraEngine_HoF::setCauldronState(uint8 state, bool paletteFade) {
 }
 
 void KyraEngine_HoF::clearCauldronTable() {
-	Common::set_to(_cauldronTable, _cauldronTable+ARRAYSIZE(_cauldronTable), -1);
+	Common::set_to(_cauldronTable, ARRAYEND(_cauldronTable), -1);
 }
 
 void KyraEngine_HoF::addFrontCauldronTable(int item) {
diff --git a/engines/kyra/scene_hof.cpp b/engines/kyra/scene_hof.cpp
index e85e691..f6cd77c 100644
--- a/engines/kyra/scene_hof.cpp
+++ b/engines/kyra/scene_hof.cpp
@@ -95,7 +95,7 @@ void KyraEngine_HoF::enterNewScene(uint16 newScene, int facing, int unk1, int un
 			_emc->run(&_sceneScriptState);
 	}
 
-	Common::for_each(_wsaSlots, _wsaSlots+ARRAYSIZE(_wsaSlots), Common::mem_fun(&WSAMovie_v2::close));
+	Common::for_each(_wsaSlots, ARRAYEND(_wsaSlots), Common::mem_fun(&WSAMovie_v2::close));
 	_specialExitCount = 0;
 	memset(_specialExitTable, -1, sizeof(_specialExitTable));
 
diff --git a/engines/kyra/scene_mr.cpp b/engines/kyra/scene_mr.cpp
index 6b234d9..74d2e89 100644
--- a/engines/kyra/scene_mr.cpp
+++ b/engines/kyra/scene_mr.cpp
@@ -83,7 +83,7 @@ void KyraEngine_MR::enterNewScene(uint16 sceneId, int facing, int unk1, int unk2
 	}
 
 	_specialExitCount = 0;
-	Common::set_to(_specialExitTable, _specialExitTable+ARRAYSIZE(_specialExitTable), 0xFFFF);
+	Common::set_to(_specialExitTable, ARRAYEND(_specialExitTable), 0xFFFF);
 
 	_mainCharacter.sceneId = sceneId;
 	_sceneList[sceneId].flags &= ~1;
@@ -388,7 +388,7 @@ void KyraEngine_MR::initSceneScript(int unk1) {
 	strcat(filename, ".CPS");
 	_screen->loadBitmap(filename, 3, 3, 0);
 
-	Common::set_to(_specialSceneScriptState, _specialSceneScriptState+ARRAYSIZE(_specialSceneScriptState), false);
+	Common::set_to(_specialSceneScriptState, ARRAYEND(_specialSceneScriptState), false);
 	_sceneEnterX1 = 160;
 	_sceneEnterY1 = 0;
 	_sceneEnterX2 = 296;
diff --git a/engines/kyra/staticres.cpp b/engines/kyra/staticres.cpp
index dc1a4fd..f6d5992 100644
--- a/engines/kyra/staticres.cpp
+++ b/engines/kyra/staticres.cpp
@@ -80,7 +80,7 @@ const IndexTable iGameTable[] = {
 };
 
 byte getGameID(const GameFlags &flags) {
-	return Common::find(iGameTable, iGameTable + ARRAYSIZE(iGameTable) - 1, flags.gameID)->value;
+	return Common::find(iGameTable, ARRAYEND(iGameTable) - 1, flags.gameID)->value;
 }
 
 const IndexTable iLanguageTable[] = {
@@ -95,7 +95,7 @@ const IndexTable iLanguageTable[] = {
 };
 
 byte getLanguageID(const GameFlags &flags) {
-	return Common::find(iLanguageTable, iLanguageTable + ARRAYSIZE(iLanguageTable) - 1, flags.lang)->value;
+	return Common::find(iLanguageTable, ARRAYEND(iLanguageTable) - 1, flags.lang)->value;
 }
 
 const IndexTable iPlatformTable[] = {
@@ -108,7 +108,7 @@ const IndexTable iPlatformTable[] = {
 };
 
 byte getPlatformID(const GameFlags &flags) {
-	return Common::find(iPlatformTable, iPlatformTable + ARRAYSIZE(iPlatformTable) - 1, flags.platform)->value;
+	return Common::find(iPlatformTable, ARRAYEND(iPlatformTable) - 1, flags.platform)->value;
 }
 
 byte getSpecialID(const GameFlags &flags) {
diff --git a/test/common/algorithm.h b/test/common/algorithm.h
index beba495..6eecae3 100644
--- a/test/common/algorithm.h
+++ b/test/common/algorithm.h
@@ -38,30 +38,30 @@ public:
 		const int arraySorted[] = { 1, 2, 3, 3, 4, 5 };
 		const int arrayUnsorted[] = { 5, 3, 1, 2, 4, 3 };
 
-		TS_ASSERT_EQUALS(checkSort(arraySorted, arraySorted + ARRAYSIZE(arraySorted), Common::Less<int>()), true);
-		TS_ASSERT_EQUALS(checkSort(arraySorted, arraySorted + ARRAYSIZE(arraySorted), Common::Greater<int>()), false);
+		TS_ASSERT_EQUALS(checkSort(arraySorted, ARRAYEND(arraySorted), Common::Less<int>()), true);
+		TS_ASSERT_EQUALS(checkSort(arraySorted, ARRAYEND(arraySorted), Common::Greater<int>()), false);
 
-		TS_ASSERT_EQUALS(checkSort(arrayUnsorted, arrayUnsorted + ARRAYSIZE(arrayUnsorted), Common::Less<int>()), false);
-		TS_ASSERT_EQUALS(checkSort(arrayUnsorted, arrayUnsorted + ARRAYSIZE(arrayUnsorted), Common::Greater<int>()), false);
+		TS_ASSERT_EQUALS(checkSort(arrayUnsorted, ARRAYEND(arrayUnsorted), Common::Less<int>()), false);
+		TS_ASSERT_EQUALS(checkSort(arrayUnsorted, ARRAYEND(arrayUnsorted), Common::Greater<int>()), false);
 	}
 
 	void test_pod_sort() {
 		{
 			int array[] = { 63, 11, 31, 72, 1, 48, 32, 69, 38, 31 };
-			Common::sort(array, array + ARRAYSIZE(array));
-			TS_ASSERT_EQUALS(checkSort(array, array + ARRAYSIZE(array), Common::Less<int>()), true);
+			Common::sort(array, ARRAYEND(array));
+			TS_ASSERT_EQUALS(checkSort(array, ARRAYEND(array), Common::Less<int>()), true);
 
 			// already sorted
-			Common::sort(array, array + ARRAYSIZE(array));
-			TS_ASSERT_EQUALS(checkSort(array, array + ARRAYSIZE(array), Common::Less<int>()), true);
+			Common::sort(array, ARRAYEND(array));
+			TS_ASSERT_EQUALS(checkSort(array, ARRAYEND(array), Common::Less<int>()), true);
 		}
 		{
 			int array[] = { 90, 80, 70, 60, 50, 40, 30, 20, 10 };
-			Common::sort(array, array + ARRAYSIZE(array));
-			TS_ASSERT_EQUALS(checkSort(array, array + ARRAYSIZE(array), Common::Less<int>()), true);
+			Common::sort(array, ARRAYEND(array));
+			TS_ASSERT_EQUALS(checkSort(array, ARRAYEND(array), Common::Less<int>()), true);
 
-			Common::sort(array, array + ARRAYSIZE(array), Common::Greater<int>());
-			TS_ASSERT_EQUALS(checkSort(array, array + ARRAYSIZE(array), Common::Greater<int>()), true);
+			Common::sort(array, ARRAYEND(array), Common::Greater<int>());
+			TS_ASSERT_EQUALS(checkSort(array, ARRAYEND(array), Common::Greater<int>()), true);
 		}
 	}
 


Commit: 3ee307e6b33d31206bcc9bfc160407c9550b9adf
    https://github.com/scummvm/scummvm/commit/3ee307e6b33d31206bcc9bfc160407c9550b9adf
Author: Christoph Mallon (christoph.mallon at gmx.de)
Date: 2011-08-07T06:19:08-07:00

Commit Message:
KYRA: Simplify initializing a buffer with a string.

Changed paths:
    engines/kyra/kyra_hof.cpp



diff --git a/engines/kyra/kyra_hof.cpp b/engines/kyra/kyra_hof.cpp
index 432cf1a..b82099f 100644
--- a/engines/kyra/kyra_hof.cpp
+++ b/engines/kyra/kyra_hof.cpp
@@ -1052,8 +1052,7 @@ void KyraEngine_HoF::runStartScript(int script, int unk1) {
 void KyraEngine_HoF::loadNPCScript() {
 	_emc->unload(&_npcScriptData);
 
-	char filename[12];
-	strcpy(filename, "_NPC.EMC");
+	char filename[] = "_NPC.EMC";
 
 	if (_flags.platform != Common::kPlatformPC || _flags.isTalkie) {
 		switch (_lang) {


Commit: d1688d22d4ad9919d31e1364e9f36e795de929a4
    https://github.com/scummvm/scummvm/commit/d1688d22d4ad9919d31e1364e9f36e795de929a4
Author: Christoph Mallon (christoph.mallon at gmx.de)
Date: 2011-08-07T06:19:08-07:00

Commit Message:
AUDIO: Simplify iterating backwards over an array.

Changed paths:
    audio/mods/maxtrax.cpp



diff --git a/audio/mods/maxtrax.cpp b/audio/mods/maxtrax.cpp
index 252c0e3..344d678 100644
--- a/audio/mods/maxtrax.cpp
+++ b/audio/mods/maxtrax.cpp
@@ -707,8 +707,8 @@ int8 MaxTrax::noteOn(ChannelContext &channel, const byte note, uint16 volume, ui
 	if ((channel.flags & ChannelContext::kFlagMono) == 0) {
 		voiceNum = pickvoice((channel.flags & ChannelContext::kFlagRightChannel) != 0 ? 1 : 0, pri);
 	} else {
-		VoiceContext *voice = ARRAYEND(_voiceCtx) - 1;
-		for (voiceNum = ARRAYSIZE(_voiceCtx) - 1; voiceNum >= 0 && voice->channel != &channel; --voiceNum, --voice)
+		VoiceContext *voice = ARRAYEND(_voiceCtx);
+		for (voiceNum = ARRAYSIZE(_voiceCtx); voiceNum-- != 0 && --voice->channel != &channel;)
 			;
 		if (voiceNum < 0)
 			voiceNum = pickvoice((channel.flags & ChannelContext::kFlagRightChannel) != 0 ? 1 : 0, pri);


Commit: b4b6ce0954f4a636be0b7b88197376b3917af31f
    https://github.com/scummvm/scummvm/commit/b4b6ce0954f4a636be0b7b88197376b3917af31f
Author: Christoph Mallon (christoph.mallon at gmx.de)
Date: 2011-08-07T06:19:09-07:00

Commit Message:
ALL: Use Graphics::skipThumbnail() where appropriate.

Changed paths:
    engines/agi/saveload.cpp
    engines/saga/saveload.cpp



diff --git a/engines/agi/saveload.cpp b/engines/agi/saveload.cpp
index dae3dd4..f0d976b 100644
--- a/engines/agi/saveload.cpp
+++ b/engines/agi/saveload.cpp
@@ -290,11 +290,7 @@ int AgiEngine::loadGame(const char *fileName, bool checkId) {
 
 	if (saveVersion >= 4) {
 		// We don't need the thumbnail here, so just read it and discard it
-		Graphics::Surface *thumbnail = new Graphics::Surface();
-		assert(thumbnail);
-		Graphics::loadThumbnail(*in, *thumbnail);
-		delete thumbnail;
-		thumbnail = 0;
+		Graphics::skipThumbnail(*in);
 
 		in->readUint32BE();	// save date
 		in->readUint16BE(); // save time
diff --git a/engines/saga/saveload.cpp b/engines/saga/saveload.cpp
index 8d7b718..9e0789f 100644
--- a/engines/saga/saveload.cpp
+++ b/engines/saga/saveload.cpp
@@ -295,12 +295,7 @@ void SagaEngine::load(const char *fileName) {
 
 	if (_saveHeader.version >= 6) {
 		// We don't need the thumbnail here, so just read it and discard it
-		Graphics::Surface *thumbnail = new Graphics::Surface();
-		assert(thumbnail);
-		Graphics::loadThumbnail(*in, *thumbnail);
-		thumbnail->free();
-		delete thumbnail;
-		thumbnail = 0;
+		Graphics::skipThumbnail(*in);
 
 		in->readUint32BE();	// save date
 		in->readUint16BE(); // save time


Commit: e35b4f20c1041b13361aa2ebc4e758873bb1cee3
    https://github.com/scummvm/scummvm/commit/e35b4f20c1041b13361aa2ebc4e758873bb1cee3
Author: Christoph Mallon (christoph.mallon at gmx.de)
Date: 2011-08-07T06:19:09-07:00

Commit Message:
GRAPHICS: Simplify the interface of Graphics::loadThumbnail().

Now it returns the Surface, so the caller does not need to create one and pass it.

Changed paths:
    engines/agi/detection.cpp
    engines/cruise/saveload.cpp
    engines/draci/saveload.cpp
    engines/hugo/detection.cpp
    engines/kyra/saveload.cpp
    engines/saga/detection.cpp
    engines/sci/detection.cpp
    engines/scumm/saveload.cpp
    engines/sword1/detection.cpp
    engines/teenagent/detection.cpp
    engines/toon/detection.cpp
    engines/tsage/saveload.cpp
    graphics/thumbnail.cpp
    graphics/thumbnail.h



diff --git a/engines/agi/detection.cpp b/engines/agi/detection.cpp
index a0736d0..93fcd2d 100644
--- a/engines/agi/detection.cpp
+++ b/engines/agi/detection.cpp
@@ -258,12 +258,7 @@ SaveStateDescriptor AgiMetaEngine::querySaveMetaInfos(const char *target, int sl
 
 		char saveVersion = in->readByte();
 		if (saveVersion >= 4) {
-			Graphics::Surface *thumbnail = new Graphics::Surface();
-			assert(thumbnail);
-			if (!Graphics::loadThumbnail(*in, *thumbnail)) {
-				delete thumbnail;
-				thumbnail = 0;
-			}
+			Graphics::Surface *const thumbnail = Graphics::loadThumbnail(*in);
 
 			desc.setThumbnail(thumbnail);
 
diff --git a/engines/cruise/saveload.cpp b/engines/cruise/saveload.cpp
index 6392009..c3d1ea6 100644
--- a/engines/cruise/saveload.cpp
+++ b/engines/cruise/saveload.cpp
@@ -62,12 +62,9 @@ bool readSavegameHeader(Common::InSaveFile *in, CruiseSavegameHeader &header) {
 	while ((ch = (char)in->readByte()) != '\0') header.saveName += ch;
 
 	// Get the thumbnail
-	header.thumbnail = new Graphics::Surface();
-	if (!Graphics::loadThumbnail(*in, *header.thumbnail)) {
-		delete header.thumbnail;
-		header.thumbnail = NULL;
+	header.thumbnail = Graphics::loadThumbnail(*in);
+	if (!header.thumbnail)
 		return false;
-	}
 
 	return true;
 }
diff --git a/engines/draci/saveload.cpp b/engines/draci/saveload.cpp
index 1479dd3..78315d1 100644
--- a/engines/draci/saveload.cpp
+++ b/engines/draci/saveload.cpp
@@ -58,13 +58,9 @@ bool readSavegameHeader(Common::InSaveFile *in, DraciSavegameHeader &header) {
 	header.playtime = in->readUint32LE();
 
 	// Get the thumbnail
-	header.thumbnail = new Graphics::Surface();
-	if (!Graphics::loadThumbnail(*in, *header.thumbnail)) {
-		header.thumbnail->free();
-		delete header.thumbnail;
-		header.thumbnail = NULL;
+	header.thumbnail = Graphics::loadThumbnail(*in);
+	if (!header.thumbnail)
 		return false;
-	}
 
 	return true;
 }
diff --git a/engines/hugo/detection.cpp b/engines/hugo/detection.cpp
index f70a21a..5d972f5 100644
--- a/engines/hugo/detection.cpp
+++ b/engines/hugo/detection.cpp
@@ -241,12 +241,7 @@ SaveStateDescriptor HugoMetaEngine::querySaveMetaInfos(const char *target, int s
 
 		SaveStateDescriptor desc(slot, saveName);
 
-		Graphics::Surface *thumbnail = new Graphics::Surface();
-		assert(thumbnail);
-		if (!Graphics::loadThumbnail(*file, *thumbnail)) {
-			delete thumbnail;
-			thumbnail = 0;
-		}
+		Graphics::Surface *const thumbnail = Graphics::loadThumbnail(*file);
 		desc.setThumbnail(thumbnail);
 
 		desc.setDeletableFlag(true);
diff --git a/engines/kyra/saveload.cpp b/engines/kyra/saveload.cpp
index f41cf0c..42c5d3e 100644
--- a/engines/kyra/saveload.cpp
+++ b/engines/kyra/saveload.cpp
@@ -113,12 +113,7 @@ KyraEngine_v1::kReadSaveHeaderError KyraEngine_v1::readSaveHeader(Common::Seekab
 
 	if (header.version >= 14) {
 		if (loadThumbnail) {
-			header.thumbnail = new Graphics::Surface();
-			assert(header.thumbnail);
-			if (!Graphics::loadThumbnail(*in, *header.thumbnail)) {
-				delete header.thumbnail;
-				header.thumbnail = 0;
-			}
+			header.thumbnail = Graphics::loadThumbnail(*in);
 		} else {
 			Graphics::skipThumbnail(*in);
 		}
diff --git a/engines/saga/detection.cpp b/engines/saga/detection.cpp
index 2f1b61e..091ec8d 100644
--- a/engines/saga/detection.cpp
+++ b/engines/saga/detection.cpp
@@ -256,13 +256,7 @@ SaveStateDescriptor SagaMetaEngine::querySaveMetaInfos(const char *target, int s
 		desc.setWriteProtectedFlag(false);
 
 		if (version >= 6) {
-			Graphics::Surface *thumbnail = new Graphics::Surface();
-			assert(thumbnail);
-			if (!Graphics::loadThumbnail(*in, *thumbnail)) {
-				delete thumbnail;
-				thumbnail = 0;
-			}
-
+			Graphics::Surface *const thumbnail = Graphics::loadThumbnail(*in);
 			desc.setThumbnail(thumbnail);
 
 			uint32 saveDate = in->readUint32BE();
diff --git a/engines/sci/detection.cpp b/engines/sci/detection.cpp
index 82f762e..33ca3a6 100644
--- a/engines/sci/detection.cpp
+++ b/engines/sci/detection.cpp
@@ -676,13 +676,7 @@ SaveStateDescriptor SciMetaEngine::querySaveMetaInfos(const char *target, int sl
 
 		SaveStateDescriptor desc(slot, meta.name);
 
-		Graphics::Surface *thumbnail = new Graphics::Surface();
-		assert(thumbnail);
-		if (!Graphics::loadThumbnail(*in, *thumbnail)) {
-			delete thumbnail;
-			thumbnail = 0;
-		}
-
+		Graphics::Surface *const thumbnail = Graphics::loadThumbnail(*in);
 		desc.setThumbnail(thumbnail);
 
 		desc.setDeletableFlag(true);
diff --git a/engines/scumm/saveload.cpp b/engines/scumm/saveload.cpp
index 3cc710c..870ec8c 100644
--- a/engines/scumm/saveload.cpp
+++ b/engines/scumm/saveload.cpp
@@ -686,12 +686,7 @@ Graphics::Surface *ScummEngine::loadThumbnailFromSlot(const char *target, int sl
 
 	Graphics::Surface *thumb = 0;
 	if (Graphics::checkThumbnailHeader(*in)) {
-		thumb = new Graphics::Surface();
-		assert(thumb);
-		if (!Graphics::loadThumbnail(*in, *thumb)) {
-			delete thumb;
-			thumb = 0;
-		}
+		thumb = Graphics::loadThumbnail(*in);
 	}
 
 	delete in;
diff --git a/engines/sword1/detection.cpp b/engines/sword1/detection.cpp
index 0c1e740..4da636b 100644
--- a/engines/sword1/detection.cpp
+++ b/engines/sword1/detection.cpp
@@ -274,13 +274,7 @@ SaveStateDescriptor SwordMetaEngine::querySaveMetaInfos(const char *target, int
 			in->skip(1);
 
 		if (Graphics::checkThumbnailHeader(*in)) {
-			Graphics::Surface *thumbnail = new Graphics::Surface();
-			assert(thumbnail);
-			if (!Graphics::loadThumbnail(*in, *thumbnail)) {
-				delete thumbnail;
-				thumbnail = 0;
-			}
-
+			Graphics::Surface *const thumbnail = Graphics::loadThumbnail(*in);
 			desc.setThumbnail(thumbnail);
 		}
 
diff --git a/engines/teenagent/detection.cpp b/engines/teenagent/detection.cpp
index 72a3386..fa5a578 100644
--- a/engines/teenagent/detection.cpp
+++ b/engines/teenagent/detection.cpp
@@ -177,9 +177,8 @@ public:
 		ssd.setDeletableFlag(true);
 
 		//checking for the thumbnail
-		Common::ScopedPtr<Graphics::Surface> thumb(new Graphics::Surface);
-		if (Graphics::loadThumbnail(*in, *thumb))
-			ssd.setThumbnail(thumb.release());
+		if (Graphics::Surface *const thumb = Graphics::loadThumbnail(*in))
+			ssd.setThumbnail(thumb);
 
 		return ssd;
 	}
diff --git a/engines/toon/detection.cpp b/engines/toon/detection.cpp
index 810a377..ac4caae 100644
--- a/engines/toon/detection.cpp
+++ b/engines/toon/detection.cpp
@@ -224,12 +224,7 @@ SaveStateDescriptor ToonMetaEngine::querySaveMetaInfos(const char *target, int s
 
 		SaveStateDescriptor desc(slot, saveName);
 
-		Graphics::Surface *thumbnail = new Graphics::Surface();
-		assert(thumbnail);
-		if (!Graphics::loadThumbnail(*file, *thumbnail)) {
-			delete thumbnail;
-			thumbnail = 0;
-		}
+		Graphics::Surface *const thumbnail = Graphics::loadThumbnail(*file);
 		desc.setThumbnail(thumbnail);
 
 		desc.setDeletableFlag(true);
diff --git a/engines/tsage/saveload.cpp b/engines/tsage/saveload.cpp
index 40444cd..e07964d 100644
--- a/engines/tsage/saveload.cpp
+++ b/engines/tsage/saveload.cpp
@@ -249,12 +249,9 @@ bool Saver::readSavegameHeader(Common::InSaveFile *in, tSageSavegameHeader &head
 	while ((ch = (char)in->readByte()) != '\0') header.saveName += ch;
 
 	// Get the thumbnail
-	header.thumbnail = new Graphics::Surface();
-	if (!Graphics::loadThumbnail(*in, *header.thumbnail)) {
-		delete header.thumbnail;
-		header.thumbnail = NULL;
+	header.thumbnail = Graphics::loadThumbnail(*in);
+	if (!header.thumbnail)
 		return false;
-	}
 
 	// Read in save date/time
 	header.saveYear = in->readSint16LE();
diff --git a/graphics/thumbnail.cpp b/graphics/thumbnail.cpp
index e9576ef..3684974 100644
--- a/graphics/thumbnail.cpp
+++ b/graphics/thumbnail.cpp
@@ -94,23 +94,24 @@ bool skipThumbnail(Common::SeekableReadStream &in) {
 	return true;
 }
 
-bool loadThumbnail(Common::SeekableReadStream &in, Graphics::Surface &to) {
+Graphics::Surface* loadThumbnail(Common::SeekableReadStream &in) {
 	ThumbnailHeader header;
 
 	if (!loadHeader(in, header, true))
-		return false;
+		return 0;
 
 	if (header.bpp != 2) {
 		warning("trying to load thumbnail with unsupported bit depth %d", header.bpp);
-		return false;
+		return 0;
 	}
 
 	Graphics::PixelFormat format = g_system->getOverlayFormat();
-	to.create(header.width, header.height, format);
+	Graphics::Surface *const to = new Graphics::Surface();
+	to->create(header.width, header.height, format);
 
-	OverlayColor *pixels = (OverlayColor *)to.pixels;
-	for (int y = 0; y < to.h; ++y) {
-		for (int x = 0; x < to.w; ++x) {
+	OverlayColor *pixels = (OverlayColor *)to->pixels;
+	for (int y = 0; y < to->h; ++y) {
+		for (int x = 0; x < to->w; ++x) {
 			uint8 r, g, b;
 			colorToRGB<ColorMasks<565> >(in.readUint16BE(), r, g, b);
 
@@ -119,7 +120,7 @@ bool loadThumbnail(Common::SeekableReadStream &in, Graphics::Surface &to) {
 		}
 	}
 
-	return true;
+	return to;
 }
 
 bool saveThumbnail(Common::WriteStream &out) {
diff --git a/graphics/thumbnail.h b/graphics/thumbnail.h
index 452125c..babc35b 100644
--- a/graphics/thumbnail.h
+++ b/graphics/thumbnail.h
@@ -53,7 +53,7 @@ bool skipThumbnail(Common::SeekableReadStream &in);
  * The loaded thumbnail will be automatically converted to the
  * current overlay pixelformat.
  */
-bool loadThumbnail(Common::SeekableReadStream &in, Graphics::Surface &to);
+Graphics::Surface* loadThumbnail(Common::SeekableReadStream &in);
 
 /**
  * Saves a thumbnail to the given write stream.






More information about the Scummvm-git-logs mailing list