From: Tobias Markus Date: Sat, 28 Feb 2015 16:12:48 +0000 (+0100) Subject: Revert "Proposed fix for coverity #29372" because of causing Segmentation X-Git-Url: https://git.verplant.org/?a=commitdiff_plain;h=219ec61655edf6785ef483905b162604a215f5f4;p=supertux.git Revert "Proposed fix for coverity #29372" because of causing Segmentation faults. [ci skip] This reverts commit c0b5cfa3eadebef8101f87cd593eb221bdef9280. --- diff --git a/src/physfs/buffered_ifile_stream.cpp b/src/physfs/buffered_ifile_stream.cpp deleted file mode 100644 index 85eee6c4f..000000000 --- a/src/physfs/buffered_ifile_stream.cpp +++ /dev/null @@ -1,43 +0,0 @@ -// SuperTux -// Copyright (C) 2015 Tobias Markus -// -// This program is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program. If not, see . - -#ifndef HEADER_SUPERTUX_PHYSFS_BUFFERED_IFILE_STREAM_CPP -#define HEADER_SUPERTUX_PHYSFS_BUFFERED_IFILE_STREAM_CPP - -#include "physfs/buffered_ifile_stream.hpp" - -BufferedIFileStream::BufferedIFileStream(const std::string& filename) -{ - buffer = new IFileStreambuf(filename); - stream = new IFileStream(buffer); -} - -BufferedIFileStream::~BufferedIFileStream() -{ - delete buffer; - delete stream; - buffer = NULL; - stream = NULL; -} - -IFileStream* BufferedIFileStream::get_stream() -{ - return stream; -} - -#endif - -/* EOF */ diff --git a/src/physfs/buffered_ifile_stream.hpp b/src/physfs/buffered_ifile_stream.hpp deleted file mode 100644 index 578dd48dd..000000000 --- a/src/physfs/buffered_ifile_stream.hpp +++ /dev/null @@ -1,39 +0,0 @@ -// SuperTux -// Copyright (C) 2015 Tobias Markus -// -// This program is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program. If not, see . - -#ifndef HEADER_SUPERTUX_PHYSFS_BUFFERED_IFILE_STREAM_HPP -#define HEADER_SUPERTUX_PHYSFS_BUFFERED_IFILE_STREAM_HPP - -#include -#include -#include "physfs/ifile_stream.hpp" -#include "physfs/ifile_streambuf.hpp" - -class BufferedIFileStream { - -private: - IFileStream* stream; - IFileStreambuf* buffer; - -public: - BufferedIFileStream(const std::string& filename); - ~BufferedIFileStream(); - - IFileStream* get_stream(); -}; -#endif - -/* EOF */ diff --git a/src/physfs/ifile_stream.cpp b/src/physfs/ifile_stream.cpp index f4cb889e9..4a09394dc 100644 --- a/src/physfs/ifile_stream.cpp +++ b/src/physfs/ifile_stream.cpp @@ -16,8 +16,10 @@ #include "physfs/ifile_stream.hpp" -IFileStream::IFileStream(IFileStreambuf* buf) : - std::istream(buf) +#include "physfs/ifile_streambuf.hpp" + +IFileStream::IFileStream(const std::string& filename) : + std::istream(new IFileStreambuf(filename)) { } diff --git a/src/physfs/ifile_stream.hpp b/src/physfs/ifile_stream.hpp index f160d1ca8..263e44dbe 100644 --- a/src/physfs/ifile_stream.hpp +++ b/src/physfs/ifile_stream.hpp @@ -20,12 +20,10 @@ #include #include -#include "physfs/ifile_streambuf.hpp" - class IFileStream : public std::istream { public: - IFileStream(IFileStreambuf* buf); + IFileStream(const std::string& filename); ~IFileStream(); }; diff --git a/src/physfs/physfs_file_system.cpp b/src/physfs/physfs_file_system.cpp index 65ac0677b..15d9f768c 100644 --- a/src/physfs/physfs_file_system.cpp +++ b/src/physfs/physfs_file_system.cpp @@ -16,7 +16,7 @@ #include "physfs/physfs_file_system.hpp" -#include "physfs/buffered_ifile_stream.hpp" +#include "physfs/ifile_stream.hpp" PhysFSFileSystem::PhysFSFileSystem() { @@ -40,8 +40,7 @@ PhysFSFileSystem::open_directory(const std::string& pathname) std::unique_ptr PhysFSFileSystem::open_file(const std::string& filename) { - BufferedIFileStream* stream = new BufferedIFileStream(filename); - return std::unique_ptr(stream->get_stream()); + return std::unique_ptr(new IFileStream(filename)); } /* EOF */ diff --git a/src/scripting/functions.cpp b/src/scripting/functions.cpp index 2c906ffb4..893191bb2 100644 --- a/src/scripting/functions.cpp +++ b/src/scripting/functions.cpp @@ -20,7 +20,7 @@ #include "math/random_generator.hpp" #include "object/camera.hpp" #include "object/player.hpp" -#include "physfs/buffered_ifile_stream.hpp" +#include "physfs/ifile_stream.hpp" #include "supertux/fadeout.hpp" #include "supertux/game_session.hpp" #include "supertux/gameconfig.hpp" @@ -127,8 +127,7 @@ void load_level(const std::string& filename) void import(HSQUIRRELVM vm, const std::string& filename) { - BufferedIFileStream* stream = new BufferedIFileStream(filename); - IFileStream* in = stream->get_stream(); + IFileStream in(filename); if(SQ_FAILED(sq_compile(vm, squirrel_read_char, &in, filename.c_str(), SQTrue))) diff --git a/src/scripting/scripting.cpp b/src/scripting/scripting.cpp index b19c13b6b..1e27640f9 100644 --- a/src/scripting/scripting.cpp +++ b/src/scripting/scripting.cpp @@ -23,7 +23,7 @@ #include #include -#include "physfs/buffered_ifile_stream.hpp" +#include "physfs/ifile_stream.hpp" #include "scripting/squirrel_error.hpp" #include "scripting/wrapper.hpp" #include "squirrel_util.hpp" @@ -106,9 +106,8 @@ Scripting::Scripting(bool enable_debugger) // try to load default script try { std::string filename = "scripts/default.nut"; - BufferedIFileStream* buffered_stream = new BufferedIFileStream(filename); - IFileStream* stream = buffered_stream->get_stream(); - scripting::compile_and_run(global_vm, *stream, filename); + IFileStream stream(filename); + scripting::compile_and_run(global_vm, stream, filename); } catch(std::exception& e) { log_warning << "Couldn't load default.nut: " << e.what() << std::endl; } diff --git a/src/supertux/console.cpp b/src/supertux/console.cpp index 7244191f4..1d27bc87b 100644 --- a/src/supertux/console.cpp +++ b/src/supertux/console.cpp @@ -19,7 +19,7 @@ #include #include -#include "physfs/buffered_ifile_stream.hpp" +#include "physfs/ifile_stream.hpp" #include "scripting/scripting.hpp" #include "scripting/squirrel_util.hpp" #include "supertux/gameconfig.hpp" @@ -175,9 +175,8 @@ Console::ready_vm() try { std::string filename = "scripts/console.nut"; - BufferedIFileStream* buffered_stream = new BufferedIFileStream(filename); - IFileStream* stream = buffered_stream->get_stream(); - scripting::compile_and_run(m_vm, *stream, filename); + IFileStream stream(filename); + scripting::compile_and_run(m_vm, stream, filename); } catch(std::exception& e) { log_warning << "Couldn't load console.nut: " << e.what() << std::endl; }