Skip to content

Commit

Permalink
Checking for null data on the targetNavigation_navigateTarget command…
Browse files Browse the repository at this point in the history
… in JNI
  • Loading branch information
sharadb-amazon committed Nov 17, 2022
1 parent d71e90d commit ebfb7fe
Showing 1 changed file with 7 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1358,7 +1358,7 @@ JNI_METHOD(jboolean, targetNavigator_1navigateTarget)

ChipLogProgress(AppServer, "JNI_METHOD targetNavigator_navigateTarget called");

const char * nativeData = env->GetStringUTFChars(data, 0);
const char * nativeData = (data != nullptr ? env->GetStringUTFChars(data, 0) : nullptr);

TargetEndpointInfo endpoint;
CHIP_ERROR err = convertJContentAppToTargetEndpointInfo(contentApp, endpoint);
Expand All @@ -1371,12 +1371,16 @@ JNI_METHOD(jboolean, targetNavigator_1navigateTarget)
ChipLogError(AppServer, "MatterCallbackHandlerJNI.SetUp failed %" CHIP_ERROR_FORMAT, err.Format()));

err = CastingServer::GetInstance()->TargetNavigator_NavigateTarget(
&endpoint, static_cast<uint8_t>(target), chip::MakeOptional(CharSpan::fromCharString(nativeData)),
&endpoint, static_cast<uint8_t>(target),
(nativeData != nullptr ? chip::MakeOptional(CharSpan::fromCharString(nativeData)) : chip::NullOptional),
[](CHIP_ERROR err) { TvCastingAppJNIMgr().getMediaCommandResponseHandler(TargetNavigator_NavigateTarget).Handle(err); });
VerifyOrExit(CHIP_NO_ERROR == err,
ChipLogError(AppServer, "CastingServer.TargetNavigator_NavigateTarget failed %" CHIP_ERROR_FORMAT, err.Format()));

env->ReleaseStringUTFChars(data, nativeData);
if (nativeData != nullptr)
{
env->ReleaseStringUTFChars(data, nativeData);
}
exit:
if (err != CHIP_NO_ERROR)
{
Expand Down

0 comments on commit ebfb7fe

Please sign in to comment.