From: Ingo Ruhnke Date: Fri, 20 Nov 2009 21:10:12 +0000 (+0000) Subject: Use some more auto_ptr<> X-Git-Url: https://git.verplant.org/?a=commitdiff_plain;h=d4069941bec58168e09a54c678aaa5230244a27b;p=supertux.git Use some more auto_ptr<> SVN-Revision: 6072 --- diff --git a/src/addon/addon_manager.cpp b/src/addon/addon_manager.cpp index 4b54a2d54..d90a4ee16 100644 --- a/src/addon/addon_manager.cpp +++ b/src/addon/addon_manager.cpp @@ -20,6 +20,7 @@ #include #include +#include #include #include #include @@ -135,39 +136,41 @@ AddonManager::check_online() if(!addons_lisp) throw std::runtime_error("Downloaded file is not an Add-on list"); lisp::ListIterator iter(addons_lisp); - while(iter.next()) { + while(iter.next()) + { const std::string& token = iter.item(); - if(token != "supertux-addoninfo") { + if(token != "supertux-addoninfo") + { log_warning << "Unknown token '" << token << "' in Add-on list" << std::endl; continue; } - Addon* addon_ptr = new Addon(); - Addon& addon = *addon_ptr; - addon.parse(*(iter.lisp())); - addon.installed = false; - addon.loaded = false; + std::auto_ptr addon(new Addon()); + addon->parse(*(iter.lisp())); + addon->installed = false; + addon->loaded = false; // make sure the list of known Add-ons does not already contain this one bool exists = false; for (std::vector::const_iterator i = addons.begin(); i != addons.end(); i++) { - if (**i == addon) { + if (**i == *addon) { exists = true; break; } - } - if (exists) { - delete addon_ptr; - continue; } - // make sure the Add-on's file name does not contain weird characters - if (addon.suggested_filename.find_first_not_of("match.quiz-proxy_gwenblvdjfks0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ") != std::string::npos) { - log_warning << "Add-on \"" << addon.title << "\" contains unsafe file name. Skipping." << std::endl; - delete addon_ptr; - continue; + if (exists) + { + // do nothing + } + else if (addon->suggested_filename.find_first_not_of("match.quiz-proxy_gwenblvdjfks0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ") != std::string::npos) + { + // make sure the Add-on's file name does not contain weird characters + log_warning << "Add-on \"" << addon->title << "\" contains unsafe file name. Skipping." << std::endl; + } + else + { + addons.push_back(addon.release()); } - - addons.push_back(addon_ptr); } } catch(std::exception& e) { std::stringstream msg; diff --git a/src/supertux/tile_set.cpp b/src/supertux/tile_set.cpp index 74a8fd67e..48306eb54 100644 --- a/src/supertux/tile_set.cpp +++ b/src/supertux/tile_set.cpp @@ -16,6 +16,7 @@ #include "supertux/tile_set.hpp" +#include #include #include @@ -52,7 +53,7 @@ TileSet::TileSet(const std::string& filename) : lisp::ListIterator iter(tiles_lisp); while(iter.next()) { if(iter.item() == "tile") { - Tile* tile = new Tile(this); + std::auto_ptr tile(new Tile(this)); uint32_t id = tile->parse(*(iter.lisp())); if(id >= tiles.size()) @@ -60,9 +61,8 @@ TileSet::TileSet(const std::string& filename) : if(tiles[id] != 0) { log_warning << "Tile with ID " << id << " redefined" << std::endl; - delete tile; } else { - tiles[id] = tile; + tiles[id] = tile.release(); } } else if(iter.item() == "tilegroup") { /* tilegroups are only interesting for the editor */ @@ -135,13 +135,12 @@ TileSet::TileSet(const std::string& filename) : int x = 32*(i % width); int y = 32*(i / width); - Tile* tile = new Tile(this, images, Rect(x, y, x + 32, y + 32), - (has_attributes ? attributes[i] : 0), (has_datas ? datas[i] : 0), animfps); + std::auto_ptr tile(new Tile(this, images, Rect(x, y, x + 32, y + 32), + (has_attributes ? attributes[i] : 0), (has_datas ? datas[i] : 0), animfps)); if (tiles[ids[i]] == 0) { - tiles[ids[i]] = tile; + tiles[ids[i]] = tile.release(); } else { log_warning << "Tile with ID " << ids[i] << " redefined" << std::endl; - delete tile; } } } else if(iter.item() == "properties") {