Fix undefined behavior in MethodInvoker (#46188)

Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/46188

UBSAN identified undefined behavior when argCount == 0 (defining a variable array of zero length).

Plus variable arrays in C++ are a clang extension.

[ChangeLog]: [General] [Fixed] - Undefined behavior fix in MethodInvoker

Reviewed By: nlutsenko

Differential Revision: D61725776

fbshipit-source-id: 3729080eae8e78b65a558305f68782ae99edbc0a
This commit is contained in:
Riley Berton
2024-08-23 15:34:16 -07:00
committed by Facebook GitHub Bot
parent 8d3c4fb475
commit 09e88448ce
@@ -229,7 +229,9 @@ MethodCallResult MethodInvoker::invoke(
auto env = Environment::current();
auto argCount = signature_.size() - 2;
JniLocalScope scope(env, static_cast<int>(argCount));
jvalue args[argCount];
std::vector<jvalue> argsStorage(
argCount + 1); // ensure we have at least 1 element
jvalue* args = argsStorage.data();
std::transform(
signature_.begin() + 2,
signature_.end(),