Add explicit casts to unsigned char before calling ctype functions.

Fixes the value range on platforms with signed char.


git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@180940 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Joerg Sonnenberger 2013-05-02 19:17:48 +00:00
parent 15467189c3
commit 63d8f7e341
6 changed files with 9 additions and 9 deletions

View File

@ -1068,28 +1068,28 @@ ctype_byname<char>::~ctype_byname()
char char
ctype_byname<char>::do_toupper(char_type c) const 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* const char*
ctype_byname<char>::do_toupper(char_type* low, const char_type* high) const ctype_byname<char>::do_toupper(char_type* low, const char_type* high) const
{ {
for (; low != high; ++low) 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; return low;
} }
char char
ctype_byname<char>::do_tolower(char_type c) const 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* const char*
ctype_byname<char>::do_tolower(char_type* low, const char_type* high) const ctype_byname<char>::do_tolower(char_type* low, const char_type* high) const
{ {
for (; low != high; ++low) 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; return low;
} }

View File

@ -32,7 +32,7 @@ int main()
assert(f.tolower('.') == '.'); assert(f.tolower('.') == '.');
assert(f.tolower('a') == 'a'); assert(f.tolower('a') == 'a');
assert(f.tolower('1') == '1'); assert(f.tolower('1') == '1');
assert(f.tolower('\xDA') == '\xDA'); assert(f.tolower('\xDA') == '\xFA');
assert(f.tolower('\xFA') == '\xFA'); assert(f.tolower('\xFA') == '\xFA');
} }
} }

View File

@ -29,7 +29,7 @@ int main()
std::string in("\xDA A\x07.a1"); std::string in("\xDA A\x07.a1");
assert(f.tolower(&in[0], in.data() + in.size()) == in.data() + in.size()); 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[1] == ' ');
assert(in[2] == 'a'); assert(in[2] == 'a');
assert(in[3] == '\x07'); assert(in[3] == '\x07');

View File

@ -33,7 +33,7 @@ int main()
assert(f.toupper('a') == 'A'); assert(f.toupper('a') == 'A');
assert(f.toupper('1') == '1'); assert(f.toupper('1') == '1');
assert(f.toupper('\xDA') == '\xDA'); assert(f.toupper('\xDA') == '\xDA');
assert(f.toupper('\xFA') == '\xFA'); assert(f.toupper('\xFA') == '\xDA');
} }
} }
{ {

View File

@ -29,7 +29,7 @@ int main()
std::string in("\xFA A\x07.a1"); std::string in("\xFA A\x07.a1");
assert(f.toupper(&in[0], in.data() + in.size()) == in.data() + in.size()); 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[1] == ' ');
assert(in[2] == 'A'); assert(in[2] == 'A');
assert(in[3] == '\x07'); assert(in[3] == '\x07');

View File

@ -38,7 +38,7 @@ int main()
assert(t.translate_nocase('.') == '.'); assert(t.translate_nocase('.') == '.');
assert(t.translate_nocase('a') == 'a'); assert(t.translate_nocase('a') == 'a');
assert(t.translate_nocase('1') == '1'); assert(t.translate_nocase('1') == '1');
assert(t.translate_nocase('\xDA') == '\xDA'); assert(t.translate_nocase('\xDA') == '\xFA');
assert(t.translate_nocase('\xFA') == '\xFA'); assert(t.translate_nocase('\xFA') == '\xFA');
} }
{ {