Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix android compilation: missing cast when formatting value in string #22382

Merged
merged 2 commits into from
Sep 2, 2022
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Fix android compilation: missing cast when formatting value in string
  • Loading branch information
andy31415 committed Sep 2, 2022
commit d76fa5cf8fb37ceb38a9e299dbca97c3c5729630
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ static CHIP_ERROR pairApp(bool printHeader, size_t index)
if (printHeader)
{
char str[64];
sprintf(str, "udc-commission %ld\r\n", (long) index);
sprintf(str, "udc-commission %ld\r\n", static_cast<long>(index));
strcat(response, str);
}

Expand All @@ -57,7 +57,7 @@ static CHIP_ERROR pairApp(bool printHeader, size_t index)
if (state == nullptr)
{
char str[64];
sprintf(str, "udc client[%d] null \r\n", index);
sprintf(str, "udc client[%ld] null \r\n", static_cast<long>(index));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@andy31415 This should probably have just cast to unsigned long instead of long.....

strcat(response, str);
}
else
Expand Down Expand Up @@ -367,7 +367,7 @@ JNI_METHOD(jstring, OnExecuteCommand)(JNIEnv * env, jobject, jobjectArray string
// Fill in argv
for (int i = 0; i < argc; i++)
{
jstring string = (jstring)(env->GetObjectArrayElement(stringArray, i));
jstring string = (jstring) (env->GetObjectArrayElement(stringArray, i));
argv[i] = (char *) env->GetStringUTFChars(string, 0);
}

Expand All @@ -378,7 +378,7 @@ JNI_METHOD(jstring, OnExecuteCommand)(JNIEnv * env, jobject, jobjectArray string
for (int i = 0; i < argc; i++)
{
ChipLogProgress(DeviceLayer, " Value=%s ", argv[i]);
jstring string = (jstring)(env->GetObjectArrayElement(stringArray, i));
jstring string = (jstring) (env->GetObjectArrayElement(stringArray, i));
env->ReleaseStringUTFChars(string, argv[i]);
}

Expand Down