Skip to content

Commit 15996cf

Browse files
committed
Improve nullptr checks across Extensions API
1 parent 6558227 commit 15996cf

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

pluginmanager.cpp

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ using namespace std;
77
do \
88
{ \
99
char* contents = (char*)(s); \
10-
string result(contents); \
10+
string result(contents ? contents : ""); \
1111
BNFreeString(contents); \
1212
return result; \
1313
} while (0)
@@ -387,10 +387,16 @@ bool RepositoryManager::AddRepository(const std::string& url,
387387

388388
Ref<Repository> RepositoryManager::GetRepositoryByPath(const std::string& repoPath)
389389
{
390-
return new Repository(BNRepositoryGetRepositoryByPath(repoPath.c_str()));
390+
BNRepository* repo = BNRepositoryGetRepositoryByPath(repoPath.c_str());
391+
if (!repo)
392+
return nullptr;
393+
return new Repository(repo);
391394
}
392395

393396
Ref<Repository> RepositoryManager::GetDefaultRepository()
394397
{
395-
return new Repository(BNRepositoryManagerGetDefaultRepository());
398+
BNRepository* repo = BNRepositoryManagerGetDefaultRepository();
399+
if (!repo)
400+
return nullptr;
401+
return new Repository(repo);
396402
}

0 commit comments

Comments
 (0)