最佳答案
罗布 · 戈登的《基本 JNI: Java本地接口》一书中包含了以下将 jstring 转换为 c string 的代码示例:
const char* utf_string;
jboolean isCopy;
utf_string = env->GetStringUTFChars(str, &isCopy);
/* ... use string ... */
if (isCopy == JNI_TRUE) {
env->ReleaseStringUTFChars(str, utf_string);
}
Note that it only calls ReleaseStringUTFChars
if isCopy
is true.
但是书 Java本地接口: 程序员指南及规格(备用链接: http://192.9.162.55/docs/books/jni/html/objtypes.html#5161
)说:
ReleaseString-Chars 调用是 GetStringChars 是否有 设置 * isCopy to JNI _ TRUE or JNI _ FALSE。 ReleaseStringChars 要么释放 复制或取消引脚实例,取决于 upon whether GetStringChars has 是否归还副本。
我猜这是戈登书里的漏洞,没错吧?