1919// IN THE SOFTWARE.
2020
2121#include " binaryninjaapi.h"
22+ #include " ffi.h"
2223
2324using namespace BinaryNinja ;
2425using 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
97100std::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
128125std::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)
203199DiffObject::~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