[libcxx] r180940 - Add explicit casts to unsigned char before calling ctype functions.
Joerg Sonnenberger
joerg at bec.de
Thu May 2 12:17:48 PDT 2013
Author: joerg
Date: Thu May 2 14:17:48 2013
New Revision: 180940
URL: http://llvm.org/viewvc/llvm-project?rev=180940&view=rev
Log:
Add explicit casts to unsigned char before calling ctype functions.
Fixes the value range on platforms with signed char.
Modified:
libcxx/trunk/src/locale.cpp
libcxx/trunk/test/localization/locale.categories/category.ctype/locale.ctype.byname/tolower_1.pass.cpp
libcxx/trunk/test/localization/locale.categories/category.ctype/locale.ctype.byname/tolower_many.pass.cpp
libcxx/trunk/test/localization/locale.categories/category.ctype/locale.ctype.byname/toupper_1.pass.cpp
libcxx/trunk/test/localization/locale.categories/category.ctype/locale.ctype.byname/toupper_many.pass.cpp
libcxx/trunk/test/re/re.traits/translate_nocase.pass.cpp
Modified: libcxx/trunk/src/locale.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/src/locale.cpp?rev=180940&r1=180939&r2=180940&view=diff
==============================================================================
--- libcxx/trunk/src/locale.cpp (original)
+++ libcxx/trunk/src/locale.cpp Thu May 2 14:17:48 2013
@@ -1068,28 +1068,28 @@ ctype_byname<char>::~ctype_byname()
char
ctype_byname<char>::do_toupper(char_type c) const
{
- return static_cast<char>(toupper_l(c, __l));
+ return static_cast<char>(toupper_l(static_cast<unsigned char>(c), __l));
}
const char*
ctype_byname<char>::do_toupper(char_type* low, const char_type* high) const
{
for (; low != high; ++low)
- *low = static_cast<char>(toupper_l(*low, __l));
+ *low = static_cast<char>(toupper_l(static_cast<unsigned char>(*low), __l));
return low;
}
char
ctype_byname<char>::do_tolower(char_type c) const
{
- return static_cast<char>(tolower_l(c, __l));
+ return static_cast<char>(tolower_l(static_cast<unsigned char>(c), __l));
}
const char*
ctype_byname<char>::do_tolower(char_type* low, const char_type* high) const
{
for (; low != high; ++low)
- *low = static_cast<char>(tolower_l(*low, __l));
+ *low = static_cast<char>(tolower_l(static_cast<unsigned char>(*low), __l));
return low;
}
Modified: libcxx/trunk/test/localization/locale.categories/category.ctype/locale.ctype.byname/tolower_1.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/localization/locale.categories/category.ctype/locale.ctype.byname/tolower_1.pass.cpp?rev=180940&r1=180939&r2=180940&view=diff
==============================================================================
--- libcxx/trunk/test/localization/locale.categories/category.ctype/locale.ctype.byname/tolower_1.pass.cpp (original)
+++ libcxx/trunk/test/localization/locale.categories/category.ctype/locale.ctype.byname/tolower_1.pass.cpp Thu May 2 14:17:48 2013
@@ -32,7 +32,7 @@ int main()
assert(f.tolower('.') == '.');
assert(f.tolower('a') == 'a');
assert(f.tolower('1') == '1');
- assert(f.tolower('\xDA') == '\xDA');
+ assert(f.tolower('\xDA') == '\xFA');
assert(f.tolower('\xFA') == '\xFA');
}
}
Modified: libcxx/trunk/test/localization/locale.categories/category.ctype/locale.ctype.byname/tolower_many.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/localization/locale.categories/category.ctype/locale.ctype.byname/tolower_many.pass.cpp?rev=180940&r1=180939&r2=180940&view=diff
==============================================================================
--- libcxx/trunk/test/localization/locale.categories/category.ctype/locale.ctype.byname/tolower_many.pass.cpp (original)
+++ libcxx/trunk/test/localization/locale.categories/category.ctype/locale.ctype.byname/tolower_many.pass.cpp Thu May 2 14:17:48 2013
@@ -29,7 +29,7 @@ int main()
std::string in("\xDA A\x07.a1");
assert(f.tolower(&in[0], in.data() + in.size()) == in.data() + in.size());
- assert(in[0] == '\xDA');
+ assert(in[0] == '\xFA');
assert(in[1] == ' ');
assert(in[2] == 'a');
assert(in[3] == '\x07');
Modified: libcxx/trunk/test/localization/locale.categories/category.ctype/locale.ctype.byname/toupper_1.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/localization/locale.categories/category.ctype/locale.ctype.byname/toupper_1.pass.cpp?rev=180940&r1=180939&r2=180940&view=diff
==============================================================================
--- libcxx/trunk/test/localization/locale.categories/category.ctype/locale.ctype.byname/toupper_1.pass.cpp (original)
+++ libcxx/trunk/test/localization/locale.categories/category.ctype/locale.ctype.byname/toupper_1.pass.cpp Thu May 2 14:17:48 2013
@@ -33,7 +33,7 @@ int main()
assert(f.toupper('a') == 'A');
assert(f.toupper('1') == '1');
assert(f.toupper('\xDA') == '\xDA');
- assert(f.toupper('\xFA') == '\xFA');
+ assert(f.toupper('\xFA') == '\xDA');
}
}
{
Modified: libcxx/trunk/test/localization/locale.categories/category.ctype/locale.ctype.byname/toupper_many.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/localization/locale.categories/category.ctype/locale.ctype.byname/toupper_many.pass.cpp?rev=180940&r1=180939&r2=180940&view=diff
==============================================================================
--- libcxx/trunk/test/localization/locale.categories/category.ctype/locale.ctype.byname/toupper_many.pass.cpp (original)
+++ libcxx/trunk/test/localization/locale.categories/category.ctype/locale.ctype.byname/toupper_many.pass.cpp Thu May 2 14:17:48 2013
@@ -29,7 +29,7 @@ int main()
std::string in("\xFA A\x07.a1");
assert(f.toupper(&in[0], in.data() + in.size()) == in.data() + in.size());
- assert(in[0] == '\xFA');
+ assert(in[0] == '\xDA');
assert(in[1] == ' ');
assert(in[2] == 'A');
assert(in[3] == '\x07');
Modified: libcxx/trunk/test/re/re.traits/translate_nocase.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/re/re.traits/translate_nocase.pass.cpp?rev=180940&r1=180939&r2=180940&view=diff
==============================================================================
--- libcxx/trunk/test/re/re.traits/translate_nocase.pass.cpp (original)
+++ libcxx/trunk/test/re/re.traits/translate_nocase.pass.cpp Thu May 2 14:17:48 2013
@@ -38,7 +38,7 @@ int main()
assert(t.translate_nocase('.') == '.');
assert(t.translate_nocase('a') == 'a');
assert(t.translate_nocase('1') == '1');
- assert(t.translate_nocase('\xDA') == '\xDA');
+ assert(t.translate_nocase('\xDA') == '\xFA');
assert(t.translate_nocase('\xFA') == '\xFA');
}
{
More information about the cfe-commits
mailing list