问题描述
我的应用程序中有一个简单的ndk代码,即时消息不断在logcat中出现此错误,并且应用程序不断崩溃.这是应用程序崩溃的方法:
I have a simple ndk code in my app and im keep getting this error in the logcat and app keep crashing. Here is the method where app is crashing:
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:
The point of this method is to receive some string from java code and concatenate that string with some other values and return a jstring
. Bellow is my 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)
所以请有人帮我这个忙吗?谢谢.
So can please someone help me with this?Thanks.
推荐答案
char[] token = "";
这意味着token[]
是一个长度为1的数组,并且您向其添加了总长度大于1的多个字符串,因此您破坏了它以外的内存.
This means that token[]
is an array of length 1, and you've appended a number of string to it of total length much more than 1, so you've corrupted the memory beyond it.
解决方案:声明它足够大,足以容纳您要输入的数据.
Solution: declare it big enough for the data you're gout to put into it.
这篇关于TID 8058中的致命信号11(SIGSEGV),代码2,故障加法器0xb3d5e488的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!