Skip to content

Commit 83684ec

Browse files
committed
[DSC] Use BNAllocStringWithLength when copying strings for the API
We're copying `std::string` objects that know their length. There's no reason to force a call to `strlen`.
1 parent a2ccfa2 commit 83684ec

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

view/sharedcache/core/ffi.cpp

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ using namespace BinaryNinja::DSC;
77
BNSharedCacheImage ImageToApi(const CacheImage& image)
88
{
99
BNSharedCacheImage apiImage;
10-
apiImage.name = BNAllocString(image.path.c_str());
10+
apiImage.name = BNAllocStringWithLength(image.path.c_str(), image.path.size());
1111
apiImage.headerAddress = image.headerAddress;
1212
apiImage.regionStartCount = image.regionStarts.size();
1313
uint64_t* regionStarts = new uint64_t[image.regionStarts.size()];
@@ -65,7 +65,7 @@ BNSharedCacheRegion RegionToApi(const CacheRegion& region)
6565
{
6666
BNSharedCacheRegion apiRegion;
6767
apiRegion.vmAddress = region.start;
68-
apiRegion.name = BNAllocString(region.name.c_str());
68+
apiRegion.name = BNAllocStringWithLength(region.name.c_str(), region.name.size());
6969
apiRegion.size = region.size;
7070
apiRegion.flags = region.flags;
7171
apiRegion.regionType = RegionTypeToApi(region.type);
@@ -88,7 +88,7 @@ CacheRegion RegionFromApi(const BNSharedCacheRegion& apiRegion)
8888
BNSharedCacheSymbol SymbolToApi(const CacheSymbol& symbol)
8989
{
9090
BNSharedCacheSymbol apiSymbol;
91-
apiSymbol.name = BNAllocString(symbol.name.c_str());
91+
apiSymbol.name = BNAllocStringWithLength(symbol.name.data(), symbol.name.size());
9292
apiSymbol.address = symbol.address;
9393
apiSymbol.symbolType = symbol.type;
9494
return apiSymbol;
@@ -133,8 +133,10 @@ BNSharedCacheMappingInfo MappingToApi(const dyld_cache_mapping_info& mapping)
133133
BNSharedCacheEntry EntryToApi(const CacheEntry& entry)
134134
{
135135
BNSharedCacheEntry apiEntry;
136-
apiEntry.path = BNAllocString(entry.GetFilePath().c_str());
137-
apiEntry.name = BNAllocString(entry.GetFileName().c_str());
136+
auto path = entry.GetFilePath();
137+
auto name = entry.GetFileName();
138+
apiEntry.path = BNAllocStringWithLength(path.c_str(), path.size());
139+
apiEntry.name = BNAllocStringWithLength(name.c_str(), name.size());
138140
apiEntry.entryType = EntryTypeToApi(entry.GetType());
139141
const auto& mappings = entry.GetMappings();
140142
apiEntry.mappingCount = mappings.size();

0 commit comments

Comments
 (0)