Skip to content

Commit 894b883

Browse files
vincentriemerfacebook-github-bot
authored andcommitted
Adjust RawPropsPropNameLength's type to account for increased number 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
1 parent b012027 commit 894b883

File tree

3 files changed

+7
-4
lines changed

3 files changed

+7
-4
lines changed

packages/react-native/ReactCommon/react/renderer/core/RawPropsKeyMap.cpp

+2
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ void RawPropsKeyMap::insert(
3838
item.value = value;
3939
key.render(item.name, &item.length);
4040
items_.push_back(item);
41+
react_native_assert(
42+
items_.size() < std::numeric_limits<RawPropsPropNameLength>::max());
4143
}
4244

4345
void RawPropsKeyMap::reindex() noexcept {

packages/react-native/ReactCommon/react/renderer/core/RawPropsParser.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ RawValue const *RawPropsParser::at(
4242
// This is not thread-safe part; this happens only during initialization of
4343
// a `ComponentDescriptor` where it is actually safe.
4444
keys_.push_back(key);
45+
react_native_assert(size < std::numeric_limits<RawPropsValueIndex>::max());
4546
nameToIndex_.insert(key, static_cast<RawPropsValueIndex>(size));
4647
return nullptr;
4748
}

packages/react-native/ReactCommon/react/renderer/core/RawPropsPrimitives.h

+4-4
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,11 @@ namespace facebook::react {
1515
/*
1616
* Type used to represent an index of some stored values in small arrays.
1717
*/
18-
using RawPropsValueIndex = uint8_t;
18+
using RawPropsValueIndex = uint16_t;
1919
static_assert(
20-
sizeof(RawPropsValueIndex) == 1,
21-
"RawPropsValueIndex must be one byte size.");
22-
using RawPropsPropNameLength = uint8_t;
20+
sizeof(RawPropsValueIndex) == 2,
21+
"RawPropsValueIndex must be two byte size.");
22+
using RawPropsPropNameLength = uint16_t;
2323
using RawPropsPropNameHash = uint32_t;
2424

2525
/*

0 commit comments

Comments
 (0)