Merge "Fix newlocale with a NULL locale name."

This commit is contained in:
Elliott Hughes 2014-11-05 02:20:55 +00:00 committed by Gerrit Code Review
commit c13a2044e3
2 changed files with 16 additions and 6 deletions

View File

@ -123,8 +123,8 @@ void freelocale(locale_t l) {
}
locale_t newlocale(int category_mask, const char* locale_name, locale_t /*base*/) {
// Is 'category_mask' valid?
if ((category_mask & ~LC_ALL_MASK) != 0) {
// Are 'category_mask' and 'locale_name' valid?
if ((category_mask & ~LC_ALL_MASK) != 0 || locale_name == NULL) {
errno = EINVAL;
return NULL;
}

View File

@ -71,20 +71,30 @@ TEST(locale, setlocale) {
EXPECT_EQ(ENOENT, errno); // POSIX specified, not an implementation detail!
}
TEST(locale, newlocale) {
TEST(locale, newlocale_invalid_category_mask) {
errno = 0;
EXPECT_EQ(0, newlocale(1 << 20, "C", 0));
EXPECT_EQ(EINVAL, errno);
}
locale_t l = newlocale(LC_ALL, "C", 0);
ASSERT_TRUE(l != NULL);
freelocale(l);
TEST(locale, newlocale_NULL_locale_name) {
errno = 0;
EXPECT_EQ(0, newlocale(LC_ALL, NULL, 0));
EXPECT_EQ(EINVAL, errno);
}
TEST(locale, newlocale_bad_locale_name) {
errno = 0;
EXPECT_EQ(0, newlocale(LC_ALL, "this-is-not-a-locale", 0));
EXPECT_EQ(ENOENT, errno); // POSIX specified, not an implementation detail!
}
TEST(locale, newlocale) {
locale_t l = newlocale(LC_ALL, "C", 0);
ASSERT_TRUE(l != NULL);
freelocale(l);
}
TEST(locale, duplocale) {
locale_t cloned_global = duplocale(LC_GLOBAL_LOCALE);
ASSERT_TRUE(cloned_global != NULL);