致命信号11(SIGSEGV),代码2,故障地址0xb3d5e488在tid 8058

时间:2016-06-03 12:26:37

标签: java android android-ndk

我的应用程序中有一个简单的ndk代码,我在logcat中继续收到此错误,应用程序一直在崩溃。以下是app崩溃的方法:

char VAL1[] = "abcdef";
char VAL2[] = "123456";
char VAL3[] = "helloworld";
JNIEXPORT jstring JNICALL Java_com_livetv_android_apps_uktvnow_utils_Constants_getValue(JNIEnv *env , jobject thiz, jstring date, jstring completeUrl, jstring params){
const char *nativeDate = (env)->GetStringUTFChars(date, 0);
const char *nativeUrl = (env)->GetStringUTFChars(completeUrl,0);
const char *nativeParams = (env)->GetStringUTFChars(params,0);

char token[] = "";
jstring returnVal;
strcat(token,nativeDate);
strcat(token,VAL1);
strcat(token,nativeUrl);
strcat(token,VAL2);
strcat(token,nativeParams);
strcat(token,VAL3);

(env)->ReleaseStringUTFChars(date, nativeDate);
(env)->ReleaseStringUTFChars(completeUrl, nativeUrl);
(env)->ReleaseStringUTFChars(params, nativeParams);
returnVal =  (env)->NewStringUTF(token);
return returnVal;
}

此方法的要点是从java代码接收一些字符串,并将该字符串与其他一些值连接起来并返回jstring。贝娄是我的LOGCAT:

06-03 17:20:05.452 8861-8861/com.livetv.android.apps.uktvnow A/libc:Fatal signal 11 (SIGSEGV), code 2, fault addr 0x745f7773 in tid 8861 (id.apps.uktvnow)
06-03 17:20:05.504 193-193/? I/DEBUG: *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
06-03 17:20:05.504 193-193/? I/DEBUG: Build fingerprint: 'google/occam/mako:5.1.1/LMY48T/2237560:user/release-keys'
06-03 17:20:05.504 193-193/? I/DEBUG: Revision: '11'
06-03 17:20:05.504 193-193/? I/DEBUG: ABI: 'arm'
06-03 17:20:05.504 193-193/? I/DEBUG: pid: 8861, tid: 8861, name: id.apps.uktvnow  >>> com.livetv.android.apps.uktvnow <<<
06-03 17:20:05.504 193-193/? I/DEBUG: signal 11 (SIGSEGV), code 2 (SEGV_ACCERR), fault addr 0x745f7773
06-03 17:20:05.518 1320-1457/? I/Icing: Indexing done 56E76EE85DF9759742239162095EE2BD5D47F19A
06-03 17:20:05.525 193-193/? I/DEBUG:     r0 b75c5408  r1 6e656b70  r2 6e656b6f  r3 745f7777
06-03 17:20:05.526 193-193/? I/DEBUG:     r4 745f776f  r5 be872fa0  r6 b6e55dd4  r7 781cdd54
06-03 17:20:05.526 193-193/? I/DEBUG:     r8 be872ee4  r9 be872ef4  sl b520b2f0  fp b75c1370
06-03 17:20:05.526 193-193/? I/DEBUG:     ip b6e5196c  sp be872dc8  lr b4ff49f7  pc b517a92c  cpsr 300b0030
06-03 17:20:05.526 193-193/? I/DEBUG: backtrace:
06-03 17:20:05.526 193-193/? I/DEBUG:     #00 pc 0023992c  /system/lib/libart.so (art::Thread::DecodeJObject(_jobject*) const+151)
06-03 17:20:05.526 193-193/? I/DEBUG:     #01 pc 000b39f3  /system/lib/libart.so (art::ScopedCheck::CheckInstance(art::ScopedCheck::InstanceKind, _jobject*)+74)
06-03 17:20:05.526 193-193/? I/DEBUG:     #02 pc 000b45ef  /system/lib/libart.so (_ZN3art11ScopedCheck5CheckEbPKcz.constprop.129+762)
06-03 17:20:05.526 193-193/? I/DEBUG:     #03 pc 000be575  /system/lib/libart.so (art::CheckJNI::ReleaseStringUTFChars(_JNIEnv*, _jstring*, char const*)+68)
06-03 17:20:05.527 193-193/? I/DEBUG:     #04 pc 00000e69  /data/app/com.livetv.android.apps.uktvnow-2/lib/arm/libConstants.so (Java_com_livetv_android_apps_uktvnow_utils_Constants_getValue+156)
06-03 17:20:05.527 193-193/? I/DEBUG:     #05 pc 0114fe2a  /dev/ashmem/dalvik-non moving space (deleted)

那么请有人帮我这个吗? 感谢。

1 个答案:

答案 0 :(得分:0)

char[] token = "";

这意味着token[]是一个长度为1的数组,并且您已向其追加总长度超过1的多个字符串,因此您破坏了它以外的内存。

解决方案:声明它足够大,足以容纳您要输入的数据。