summaryrefslogtreecommitdiffstats
path: root/sql
diff options
context:
space:
mode:
authorElliott Hughes <enh@google.com>2009-09-09 18:15:23 -0700
committerElliott Hughes <enh@google.com>2009-09-10 10:28:12 -0700
commit80e88aa4b239511ea5cdedc7183d05bcbaba908e (patch)
treea57d2734424c79302644f4bf0ce3da166ccfeefd /sql
parent91e2974c5b1f3b938a4f1f1c57447d01973ad0ba (diff)
downloadlibcore-80e88aa4b239511ea5cdedc7183d05bcbaba908e.zip
libcore-80e88aa4b239511ea5cdedc7183d05bcbaba908e.tar.gz
libcore-80e88aa4b239511ea5cdedc7183d05bcbaba908e.tar.bz2
Use GetStringRegion/GetStringUTFRegion where appropriate.
Note that the changes to DecimalFormatInterface.cpp and RBNFInterface.cpp are just minor tidy-ups, fixing an issue where the early error exit wouldn't call ReleaseStringChars to undo the earlier call to GetStringChars. Also remove a dead function and fix a comment in ExpatParser.cpp. Tested on sapphire-eng. Bug: 1639287
Diffstat (limited to 'sql')
-rw-r--r--sql/src/main/native/sqlite_jni.c25
1 files changed, 8 insertions, 17 deletions
diff --git a/sql/src/main/native/sqlite_jni.c b/sql/src/main/native/sqlite_jni.c
index 4923869..44c16f3 100644
--- a/sql/src/main/native/sqlite_jni.c
+++ b/sql/src/main/native/sqlite_jni.c
@@ -331,16 +331,10 @@ trans2iso(JNIEnv *env, int haveutf, jstring enc, jstring src,
dest->result = 0;
dest->tofree = 0;
if (haveutf) {
- const char *utf = (*env)->GetStringUTFChars(env, src, 0);
-
- if (!utf) {
- return dest->result;
- }
- dest->tofree = malloc(strlen(utf) + 1);
- dest->result = dest->tofree;
- strcpy(dest->result, utf);
- (*env)->ReleaseStringUTFChars(env, src, utf);
- return dest->result;
+ const jsize utfLength = (*env)->GetStringUTFLength(env, src);
+ dest->result = dest->tofree = malloc(utfLength + 1);
+ (*env)->GetStringUTFRegion(env, src, 0, utfLength, dest->result);
+ return dest->result;
}
if (enc) {
bytes = (*env)->CallObjectMethod(env, src,
@@ -3674,19 +3668,16 @@ Java_SQLite_Stmt_bind__ILjava_lang_String_2(JNIEnv *env, jobject obj,
return;
}
if (val) {
- len = (*env)->GetStringLength(env, val);
+ const jsize charCount = (*env)->GetStringLength(env, val);
+ len = charCount * sizeof(jchar);
if (len > 0) {
- const jchar *ch;
-
- len *= sizeof (jchar);
data = sqlite3_malloc(len);
if (!data) {
throwoom(env, "unable to get blob parameter");
return;
}
- ch = (*env)->GetStringChars(env, val, 0);
- memcpy(data, ch, len);
- (*env)->ReleaseStringChars(env, val, ch);
+
+ (*env)->GetStringRegion(env, val, 0, charCount, (jchar*) data);
ret = sqlite3_bind_text16((sqlite3_stmt *) v->vm,
pos, data, len, sqlite3_free);
} else {