diff options
author | Max Horn | 2009-03-09 22:26:02 +0000 |
---|---|---|
committer | Max Horn | 2009-03-09 22:26:02 +0000 |
commit | 5181546c639b67fa821b849ca18e37f4bf846cb1 (patch) | |
tree | bcd7a4e1302f78dc96a81f3cc9e12da04fb6d928 /engines/kyra | |
parent | 6c932497151f54f31d7b6fbf34a2ee24fd362d63 (diff) | |
download | scummvm-rg350-5181546c639b67fa821b849ca18e37f4bf846cb1.tar.gz scummvm-rg350-5181546c639b67fa821b849ca18e37f4bf846cb1.tar.bz2 scummvm-rg350-5181546c639b67fa821b849ca18e37f4bf846cb1.zip |
Rewrote Common::List iterator code to ensure const correctness is preserved.
We tried to implement the list iterators in a clever way, to reduce code
duplication. But this is essentially impossible to do properly, sadly --
this is one of the places where the ugly drawbacks of C++ really show.
As a consequence, our implementation had a bug which allowed one to
convert any const_iterator to an iterator, thus allowing modifying
elements of const lists.
This rewrite reintroduces code duplication but at least ensures that no
const list is written to accidentally.
Also fix some places which incorrectly used iterator instead of const_iterator
or (in the kyra code) accidentally wrote into a const list.
svn-id: r39279
Diffstat (limited to 'engines/kyra')
-rw-r--r-- | engines/kyra/resource_intern.cpp | 9 |
1 files changed, 5 insertions, 4 deletions
diff --git a/engines/kyra/resource_intern.cpp b/engines/kyra/resource_intern.cpp index 23fe2e530b..0c2cda893c 100644 --- a/engines/kyra/resource_intern.cpp +++ b/engines/kyra/resource_intern.cpp @@ -37,7 +37,7 @@ namespace Kyra { PlainArchive::PlainArchive(Common::SharedPtr<Common::ArchiveMember> file, const FileInputList &files) : _file(file), _files() { - for (FileInputList::iterator i = files.begin(); i != files.end(); ++i) { + for (FileInputList::const_iterator i = files.begin(); i != files.end(); ++i) { Entry entry; entry.offset = i->offset; @@ -85,14 +85,15 @@ Common::SeekableReadStream *PlainArchive::createReadStreamForMember(const Common CachedArchive::CachedArchive(const FileInputList &files) : _files() { - for (FileInputList::iterator i = files.begin(); i != files.end(); ++i) { + for (FileInputList::const_iterator i = files.begin(); i != files.end(); ++i) { Entry entry; entry.data = i->data; entry.size = i->size; - i->name.toLowercase(); - _files[i->name] = entry; + Common::String name = i->name; + name.toLowercase(); + _files[name] = entry; } } |