Skip to content

Commit c338fff

Browse files
Andrei Shikovfacebook-github-bot
authored andcommitted
Cast MapBuffer bytes to struct to read header
Summary: The struct is copied directly to the buffer, so it is safe to read it back. Changelog: [Internal] Reviewed By: javache Differential Revision: D33624036 fbshipit-source-id: 7ee2b28b815690ab471832c0c622a075b5dd7d78
1 parent 5b489d5 commit c338fff

File tree

1 file changed

+5
-15
lines changed

1 file changed

+5
-15
lines changed

ReactCommon/react/renderer/mapbuffer/MapBuffer.cpp

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -15,22 +15,12 @@ namespace react {
1515
// TODO T83483191: Extend MapBuffer C++ implementation to support basic random
1616
// access
1717
MapBuffer::MapBuffer(std::vector<uint8_t> data) : bytes_(std::move(data)) {
18-
memcpy(
19-
reinterpret_cast<uint8_t *>(&count_),
20-
bytes_.data() + HEADER_COUNT_OFFSET,
21-
UINT16_SIZE);
22-
23-
// TODO T83483191: extract memcpy calls into an inline function to simplify
24-
// the code
25-
uint32_t dataSize;
26-
memcpy(
27-
reinterpret_cast<uint8_t *>(&dataSize),
28-
bytes_.data() + HEADER_BUFFER_SIZE_OFFSET,
29-
INT_SIZE);
18+
auto header = reinterpret_cast<Header const *>(bytes_.data());
19+
count_ = header->count;
3020

31-
if (dataSize != bytes_.size()) {
32-
LOG(ERROR) << "Error: Data size does not match, expected " << dataSize
33-
<< " found: " << bytes_.size();
21+
if (header->bufferSize != bytes_.size()) {
22+
LOG(ERROR) << "Error: Data size does not match, expected "
23+
<< header->bufferSize << " found: " << bytes_.size();
3424
abort();
3525
}
3626
}

0 commit comments

Comments
 (0)