1

I'm following an online course. It's about JNI. And this code below is in my test.cpp file.

__android_log_print(ANDROID_LOG_ERROR,"testjni JNI: c_str1 = %s", c_str1);

Then it shows "error: format string is not a string literal (potentially insecure) [-Werror,-Wformat-security]" How should I change it? Thanks!

The full method and implementation

JNIEXPORT jstring JNICALL Java_com_example_carapp_OBOJNI_test_1jni_1api3
        (JNIEnv *env, jobject obj, jstring j_str1, jstring j_str2){

    const char *c_str1 = NULL;
    const char *c_str2 = NULL;

    c_str1 = env->GetStringUTFChars(j_str1,0);
    __android_log_print(ANDROID_LOG_ERROR,"testjni JNI: c_str1 = %s", c_str1);
    env->ReleaseStringUTFChars(j_str1,c_str1);

    jstring ret_j_string = env->NewStringUTF("JNI return String");
    return ret_j_string;
Botje
  • 26,269
  • 3
  • 31
  • 41
anonymous
  • 67
  • 8
  • The code you've shown seems to have a string literal as the format string, and therefore should not generate that error message. I suspect there's more to this than you've shared. – user3386109 Sep 13 '19 at 21:07
  • @user3386109 I've add my full implementation of the method. Sorry for not being explicit at the beginning. – anonymous Sep 13 '19 at 21:23
  • I did a little searching and [found this answer](https://stackoverflow.com/a/55390773/3386109). Evidently, the second argument to `__android_log_print` is *not* the format string, but instead is a tag string. – user3386109 Sep 13 '19 at 21:36
  • @user3386109 thank you so much! – anonymous Sep 13 '19 at 22:18

0 Answers0