Skip to content

Commit

Permalink
Adjust RawPropsPropNameLength's type to account for increased number …
Browse files Browse the repository at this point in the history
…of props (#39008)

Summary:
Pull Request resolved: #39008

Changelog: [Internal] - Adjust RawPropsPropNameLength's type to account for increased number of props

While investigating why we needed to back out D48288752 I discovered that the root cause was that the `items_` vector in `RawProsKeyMap` was now a size greater than 255 which becomes an issue because `items_`'s indices are statically cast to `RawPropsPropNameLength` (previously alias to `uint8_t`).

This diff updates `RawPropsPropNameLength` to be an alias to `uint16_t` so the current issue is resolved as well as adding an assert to ensure (however unlikely) that this happens again.

Reviewed By: rozele

Differential Revision: D48331909

fbshipit-source-id: f6bc3e4825f2f293d79d8cd90c40ced7cba0e3c5
  • Loading branch information
vincentriemer authored and facebook-github-bot committed Aug 15, 2023
1 parent b012027 commit 894b883
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ void RawPropsKeyMap::insert(
item.value = value;
key.render(item.name, &item.length);
items_.push_back(item);
react_native_assert(
items_.size() < std::numeric_limits<RawPropsPropNameLength>::max());
}

void RawPropsKeyMap::reindex() noexcept {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ RawValue const *RawPropsParser::at(
// This is not thread-safe part; this happens only during initialization of
// a `ComponentDescriptor` where it is actually safe.
keys_.push_back(key);
react_native_assert(size < std::numeric_limits<RawPropsValueIndex>::max());
nameToIndex_.insert(key, static_cast<RawPropsValueIndex>(size));
return nullptr;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@ namespace facebook::react {
/*
* Type used to represent an index of some stored values in small arrays.
*/
using RawPropsValueIndex = uint8_t;
using RawPropsValueIndex = uint16_t;
static_assert(
sizeof(RawPropsValueIndex) == 1,
"RawPropsValueIndex must be one byte size.");
using RawPropsPropNameLength = uint8_t;
sizeof(RawPropsValueIndex) == 2,
"RawPropsValueIndex must be two byte size.");
using RawPropsPropNameLength = uint16_t;
using RawPropsPropNameHash = uint32_t;

/*
Expand Down

0 comments on commit 894b883

Please sign in to comment.