From 3ef7570fb5e0bda26bb592b43619fdd5233749c1 Mon Sep 17 00:00:00 2001 From: Filip Gawin Date: Sat, 25 Aug 2018 19:20:31 +0200 Subject: [PATCH] Replace raw ptr in SCMFile with unique_ptr --- rwengine/src/script/SCMFile.cpp | 4 ++-- rwengine/src/script/SCMFile.hpp | 17 ++++++++++------- 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/rwengine/src/script/SCMFile.cpp b/rwengine/src/script/SCMFile.cpp index d5cdaefd..7ffb025b 100644 --- a/rwengine/src/script/SCMFile.cpp +++ b/rwengine/src/script/SCMFile.cpp @@ -4,8 +4,8 @@ #include void SCMFile::loadFile(char *data, unsigned int size) { - _data = new SCMByte[size]; - std::copy(data, data + size, _data); + _data = std::make_unique(size); + std::copy(data, data + size, _data.get()); // Bytes required to hop over a jump opcode. const unsigned int jumpOpSize = 2u + 1u + 4u; diff --git a/rwengine/src/script/SCMFile.hpp b/rwengine/src/script/SCMFile.hpp index ea443a30..29d22cf8 100644 --- a/rwengine/src/script/SCMFile.hpp +++ b/rwengine/src/script/SCMFile.hpp @@ -17,24 +17,27 @@ public: enum SCMTarget { NoTarget = 0, GTAIII = 0xC6, GTAVC = 0x6D, GTASA = 0x73 }; SCMFile() = default; + SCMFile(SCMFile&& info) = default; + SCMFile(SCMFile& info) = delete; - ~SCMFile() { - delete[] _data; - } + ~SCMFile() = default; + + SCMFile& operator=(SCMFile&& info) = default; + SCMFile& operator=(SCMFile& info) = delete; operator bool() { - return _data; + return _data.get(); } void loadFile(char* data, unsigned int size); SCMByte* data() const { - return _data; + return _data.get(); } template T read(unsigned int offset) const { - return bit_cast(*(_data + offset)); + return bit_cast(*(_data.get() + offset)); } uint32_t getMainSize() const { @@ -70,7 +73,7 @@ public: } private: - SCMByte* _data = nullptr; + std::unique_ptr _data; SCMTarget _target{NoTarget};