1
0
mirror of https://github.com/rwengine/openrw.git synced 2024-09-15 06:52:34 +02:00

Replace raw ptr in SCMFile with unique_ptr

This commit is contained in:
Filip Gawin 2018-08-25 19:20:31 +02:00
parent 711fa70950
commit 3ef7570fb5
2 changed files with 12 additions and 9 deletions

View File

@ -4,8 +4,8 @@
#include <cstddef>
void SCMFile::loadFile(char *data, unsigned int size) {
_data = new SCMByte[size];
std::copy(data, data + size, _data);
_data = std::make_unique<SCMByte[]>(size);
std::copy(data, data + size, _data.get());
// Bytes required to hop over a jump opcode.
const unsigned int jumpOpSize = 2u + 1u + 4u;

View File

@ -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 <class T>
T read(unsigned int offset) const {
return bit_cast<T>(*(_data + offset));
return bit_cast<T>(*(_data.get() + offset));
}
uint32_t getMainSize() const {
@ -70,7 +73,7 @@ public:
}
private:
SCMByte* _data = nullptr;
std::unique_ptr<SCMByte[]> _data;
SCMTarget _target{NoTarget};