Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(4848)

Unified Diff: base/android/linker/legacy_linker_jni.cc

Issue 1246633002: Comment on ConvertJavaStringToUTF8() / GetStringUTFChars() (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/android/linker/legacy_linker_jni.cc
diff --git a/base/android/linker/legacy_linker_jni.cc b/base/android/linker/legacy_linker_jni.cc
index 14c260f71c13673fcf9d943903244f069c6adda3..f8d6e2b0a7f94dcec0b1d7dc171828e1e415566a 100644
--- a/base/android/linker/legacy_linker_jni.cc
+++ b/base/android/linker/legacy_linker_jni.cc
@@ -71,8 +71,19 @@ String::String(JNIEnv* env, jstring str) {
size_ = env->GetStringUTFLength(str);
ptr_ = static_cast<char*>(::malloc(size_ + 1));
- // Note: the result contains Java "modified UTF-8" bytes.
- // Good enough for the linker though.
+ // Note: This runs before browser native code is loaded, and so cannot
+ // rely on anything from base/. This means that we must use
+ // GetStringUTFChars() and not base::android::ConvertJavaStringToUTF8().
+ //
+ // GetStringUTFChars() suffices because the only strings used here are
+ // paths to APK files or names of shared libraries, all of which are
+ // plain ASCII, defined and hard-coded by the Chromium Android build.
+ //
+ // For more: see
+ // https://crbug.com/508876
+ //
+ // Note: GetStringUTFChars() returns Java UTF-8 bytes. This is good
+ // enough for the linker though.
const char* bytes = env->GetStringUTFChars(str, NULL);
::memcpy(ptr_, bytes, size_);
ptr_[size_] = '\0';
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698