summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorWally Yau <wyau@google.com>2014-08-26 09:47:23 -0700
committerElliott Hughes <enh@google.com>2014-08-27 17:22:29 +0000
commit8a46cf0fcf82b8c76e05be7e066ec854f974603a (patch)
tree7a90435ae22b5401bcf5d4f820135d25d5befaff /tests
parent84d0683a824fa02dbaa6d1b56a79223804b54e80 (diff)
downloadbionic-8a46cf0fcf82b8c76e05be7e066ec854f974603a.zip
bionic-8a46cf0fcf82b8c76e05be7e066ec854f974603a.tar.gz
bionic-8a46cf0fcf82b8c76e05be7e066ec854f974603a.tar.bz2
call uselocale() before freelocale() to make sure that g_local_key has a valid locale.
For tests that call uselocale(), the locale is stored in the g_userlocale_key thread-specific key. If freelocale() is called later, then g_uselocal_key points to a deleted pointer. CTS eventually calls vfprintf to print the result, which calls MB_CUR_MAX and MB_CUR_MAX accesses the deleted locale stored in g_uselocale_key, causing unpredictable errors. Fixed the tests by calling uselocale() with the old locale before calling freelocale. Bug: 17299565 Change-Id: I87efa2a9b16999a11d587f68d3aeedcbe6ac8a2c
Diffstat (limited to 'tests')
-rw-r--r--tests/locale_test.cpp3
-rw-r--r--tests/stdio_test.cpp3
2 files changed, 4 insertions, 2 deletions
diff --git a/tests/locale_test.cpp b/tests/locale_test.cpp
index 325f6ce..7ec607a 100644
--- a/tests/locale_test.cpp
+++ b/tests/locale_test.cpp
@@ -114,11 +114,12 @@ TEST(locale, mb_cur_max) {
locale_t cloc = newlocale(LC_ALL, "C", 0);
locale_t cloc_utf8 = newlocale(LC_ALL, "C.UTF-8", 0);
- uselocale(cloc);
+ locale_t old_locale = uselocale(cloc);
ASSERT_EQ(1U, MB_CUR_MAX);
uselocale(cloc_utf8);
ASSERT_EQ(4U, MB_CUR_MAX);
+ uselocale(old_locale);
freelocale(cloc);
freelocale(cloc_utf8);
}
diff --git a/tests/stdio_test.cpp b/tests/stdio_test.cpp
index bb86509..8c8c235 100644
--- a/tests/stdio_test.cpp
+++ b/tests/stdio_test.cpp
@@ -428,7 +428,7 @@ TEST(stdio, snprintf_negative_zero_5084292) {
TEST(stdio, snprintf_utf8_15439554) {
locale_t cloc = newlocale(LC_ALL, "C.UTF-8", 0);
- uselocale(cloc);
+ locale_t old_locale = uselocale(cloc);
// http://b/15439554
char buf[BUFSIZ];
@@ -446,6 +446,7 @@ TEST(stdio, snprintf_utf8_15439554) {
snprintf(buf, sizeof(buf), "%d\xf0\xa4\xad\xa2%d", 1, 2);
EXPECT_STREQ("1𤭢2", buf);
+ uselocale(old_locale);
freelocale(cloc);
}