|
@@ -79,14 +79,14 @@ public:
|
|
|
// A load_command and its associated data
|
|
|
struct RawLoadCommand
|
|
|
{
|
|
|
- uint32_t type(const cmMachOHeaderAndLoadCommands* m) const
|
|
|
+ uint32_t type(const cmMachOHeaderAndLoadCommands& m) const
|
|
|
{
|
|
|
if (this->LoadCommand.size() < sizeof(load_command)) {
|
|
|
return 0;
|
|
|
}
|
|
|
const load_command* cmd =
|
|
|
reinterpret_cast<const load_command*>(&this->LoadCommand[0]);
|
|
|
- return m->swap(cmd->cmd);
|
|
|
+ return m.swap(cmd->cmd);
|
|
|
}
|
|
|
std::vector<char> LoadCommand;
|
|
|
};
|
|
@@ -186,8 +186,11 @@ class cmMachOInternal
|
|
|
{
|
|
|
public:
|
|
|
cmMachOInternal(const char* fname);
|
|
|
+ cmMachOInternal(const cmMachOInternal&) = delete;
|
|
|
~cmMachOInternal();
|
|
|
|
|
|
+ cmMachOInternal& operator=(const cmMachOInternal&) = delete;
|
|
|
+
|
|
|
// read a Mach-O file
|
|
|
bool read_mach_o(uint32_t file_offset);
|
|
|
|
|
@@ -202,7 +205,7 @@ public:
|
|
|
std::string ErrorMessage;
|
|
|
|
|
|
// the list of Mach-O's
|
|
|
- std::vector<cmMachOHeaderAndLoadCommands*> MachOList;
|
|
|
+ std::vector<std::unique_ptr<cmMachOHeaderAndLoadCommands>> MachOList;
|
|
|
};
|
|
|
|
|
|
cmMachOInternal::cmMachOInternal(const char* fname)
|
|
@@ -260,12 +263,7 @@ cmMachOInternal::cmMachOInternal(const char* fname)
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-cmMachOInternal::~cmMachOInternal()
|
|
|
-{
|
|
|
- for (auto& i : this->MachOList) {
|
|
|
- delete i;
|
|
|
- }
|
|
|
-}
|
|
|
+cmMachOInternal::~cmMachOInternal() = default;
|
|
|
|
|
|
bool cmMachOInternal::read_mach_o(uint32_t file_offset)
|
|
|
{
|
|
@@ -280,25 +278,25 @@ bool cmMachOInternal::read_mach_o(uint32_t file_offset)
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
- cmMachOHeaderAndLoadCommands* f = nullptr;
|
|
|
+ std::unique_ptr<cmMachOHeaderAndLoadCommands> f;
|
|
|
if (magic == MH_CIGAM || magic == MH_MAGIC) {
|
|
|
bool swap = false;
|
|
|
if (magic == MH_CIGAM) {
|
|
|
swap = true;
|
|
|
}
|
|
|
- f = new cmMachOHeaderAndLoadCommandsImpl<mach_header>(swap);
|
|
|
+ f = cm::make_unique<cmMachOHeaderAndLoadCommandsImpl<mach_header>>(swap);
|
|
|
} else if (magic == MH_CIGAM_64 || magic == MH_MAGIC_64) {
|
|
|
bool swap = false;
|
|
|
if (magic == MH_CIGAM_64) {
|
|
|
swap = true;
|
|
|
}
|
|
|
- f = new cmMachOHeaderAndLoadCommandsImpl<mach_header_64>(swap);
|
|
|
+ f =
|
|
|
+ cm::make_unique<cmMachOHeaderAndLoadCommandsImpl<mach_header_64>>(swap);
|
|
|
}
|
|
|
|
|
|
if (f && f->read_mach_o(this->Fin)) {
|
|
|
- this->MachOList.push_back(f);
|
|
|
+ this->MachOList.push_back(std::move(f));
|
|
|
} else {
|
|
|
- delete f;
|
|
|
this->ErrorMessage = "Failed to read Mach-O header.";
|
|
|
return false;
|
|
|
}
|
|
@@ -333,11 +331,12 @@ bool cmMachO::GetInstallName(std::string& install_name)
|
|
|
}
|
|
|
|
|
|
// grab the first Mach-O and get the install name from that one
|
|
|
- cmMachOHeaderAndLoadCommands* macho = this->Internal->MachOList[0];
|
|
|
+ std::unique_ptr<cmMachOHeaderAndLoadCommands>& macho =
|
|
|
+ this->Internal->MachOList[0];
|
|
|
for (size_t i = 0; i < macho->load_commands().size(); i++) {
|
|
|
const cmMachOHeaderAndLoadCommands::RawLoadCommand& cmd =
|
|
|
macho->load_commands()[i];
|
|
|
- uint32_t lc_cmd = cmd.type(macho);
|
|
|
+ uint32_t lc_cmd = cmd.type(*macho);
|
|
|
if (lc_cmd == LC_ID_DYLIB || lc_cmd == LC_LOAD_WEAK_DYLIB ||
|
|
|
lc_cmd == LC_LOAD_DYLIB) {
|
|
|
if (sizeof(dylib_command) < cmd.LoadCommand.size()) {
|