From 36aed904bc49bbe23a7d69d6b26bf65eee5de597 Mon Sep 17 00:00:00 2001 From: Michael Hoisie Date: Fri, 12 Apr 2024 16:25:48 +0000 Subject: Use "C" numeric locale for consistency in strtof In Android, strtof is used in places such as PathParser to parse floats in path expressions in drawables, i.e. "C0.2,0 0.1,1 0.5, 1 L 1,1". In certain locales (e.g. Germany), commas are interpreted as part of numbers, so this is not parsed correctly. Use the minimal "C" numeric locale to ensure consistency when doing strtof and other floating point parsing operations. This is also done in LayoutlibLoader. Bug: 334093536 Test: ShadowNativePathParserTest in Google3 Change-Id: I21e7115240045ebf065362a6e28f6af710509a13 --- core/jni/RobolectricNativeRuntime.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/core/jni/RobolectricNativeRuntime.cpp b/core/jni/RobolectricNativeRuntime.cpp index d11a4b71ecef..fcbc89e788fb 100644 --- a/core/jni/RobolectricNativeRuntime.cpp +++ b/core/jni/RobolectricNativeRuntime.cpp @@ -4,6 +4,7 @@ #include #include +#include #include #include #include @@ -214,5 +215,10 @@ JNIEXPORT jint JNI_OnLoad(JavaVM* vm, void*) { } env->ReleaseStringUTFChars(stringPath, icuPath); env->ReleaseStringUTFChars(stringLanguageTag, languageTag); + + // Use minimal "C" locale for number format to ensure correct parsing of floats when using + // strtof (e.g. in PathParser). + setlocale(LC_NUMERIC, "C"); + return JNI_VERSION_1_6; } -- cgit v1.2.3