Skip to content

Commit 7570974

Browse files
committed
Merge: These fields are optional
1 parent 0268348 commit 7570974

2 files changed

Lines changed: 32 additions & 24 deletions

File tree

binaryninjaapi.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22449,9 +22449,9 @@ namespace BinaryNinja {
2244922449
DiffObject(BNDiffObject* object);
2245022450
virtual ~DiffObject();
2245122451

22452-
std::string GetBase() const;
22453-
std::string GetLeft() const;
22454-
std::string GetRight() const;
22452+
std::optional<std::string> GetBase() const;
22453+
std::optional<std::string> GetLeft() const;
22454+
std::optional<std::string> GetRight() const;
2245522455

2245622456
std::unordered_map<std::string, Ref<DiffObject>> GetChildren() const;
2245722457

merge.cpp

Lines changed: 29 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
// IN THE SOFTWARE.
2020

2121
#include "binaryninjaapi.h"
22+
#include "ffi.h"
2223

2324
using namespace BinaryNinja;
2425
using namespace std;
@@ -65,7 +66,9 @@ Ref<Metadata> DatabaseObject::GetMetadata() const
6566
{
6667
BNMetadata* metadata = BNGetDatabaseObjectMetadata(m_object);
6768
if (!metadata)
69+
{
6870
return nullptr;
71+
}
6972
return new Metadata(metadata);
7073
}
7174

@@ -96,15 +99,9 @@ std::unordered_map<std::string, Ref<DatabaseObject>> DatabaseObject::GetChildren
9699

97100
std::vector<std::string> DatabaseObject::GetDependencies() const
98101
{
99-
size_t count;
102+
size_t count = 0;
100103
char** deps = BNGetDatabaseObjectDependencies(m_object, &count);
101-
102-
std::vector<std::string> result;
103-
for (size_t i = 0; i < count; i++)
104-
{
105-
result.push_back(deps[i]);
106-
}
107-
104+
std::vector<std::string> result = ParseStringList(deps, count);
108105
BNFreeStringList(deps, count);
109106
return result;
110107
}
@@ -127,15 +124,9 @@ DiffState::~DiffState() = default;
127124

128125
std::vector<std::string> DiffState::GetErrors() const
129126
{
130-
size_t count;
127+
size_t count = 0;
131128
char** errors = BNGetDiffStateErrors(m_object, &count);
132-
133-
std::vector<std::string> result;
134-
for (size_t i = 0; i < count; i++)
135-
{
136-
result.push_back(errors[i]);
137-
}
138-
129+
std::vector<std::string> result = ParseStringList(errors, count);
139130
BNFreeStringList(errors, count);
140131
return result;
141132
}
@@ -177,8 +168,13 @@ bool DiffState::ApplyDiff(
177168
)
178169
{
179170
return BNDiffStateApplyDiff(
180-
m_object, diff->GetObject(), base->GetObject(),
181-
left->GetObject(), right->GetObject(), result->GetObject());
171+
m_object,
172+
diff->GetObject(),
173+
base->GetObject(),
174+
left->GetObject(),
175+
right->GetObject(),
176+
result->GetObject()
177+
);
182178
}
183179

184180

@@ -203,27 +199,39 @@ DiffObject::DiffObject(BNDiffObject* object)
203199
DiffObject::~DiffObject() = default;
204200

205201

206-
std::string DiffObject::GetBase() const
202+
std::optional<std::string> DiffObject::GetBase() const
207203
{
208204
char* base = BNGetDiffObjectBase(m_object);
205+
if (!base)
206+
{
207+
return std::nullopt;
208+
}
209209
std::string result = base;
210210
BNFreeString(base);
211211
return result;
212212
}
213213

214214

215-
std::string DiffObject::GetLeft() const
215+
std::optional<std::string> DiffObject::GetLeft() const
216216
{
217217
char* left = BNGetDiffObjectLeft(m_object);
218+
if (!left)
219+
{
220+
return std::nullopt;
221+
}
218222
std::string result = left;
219223
BNFreeString(left);
220224
return result;
221225
}
222226

223227

224-
std::string DiffObject::GetRight() const
228+
std::optional<std::string> DiffObject::GetRight() const
225229
{
226230
char* right = BNGetDiffObjectRight(m_object);
231+
if (!right)
232+
{
233+
return std::nullopt;
234+
}
227235
std::string result = right;
228236
BNFreeString(right);
229237
return result;

0 commit comments

Comments
 (0)