Kaydet (Commit) 7778d9f5 authored tarafından Stephan Bergmann's avatar Stephan Bergmann

Prevent calls to rtl/character.hxx functions with (signed) char arguments

...that would implicitly be sign extended (for plain char only if it is signed),
so non-ASCII char values would trigger the isUnicodeCodePoint assert.

Change-Id: Iaf8024ad509e64525558e882fe3fd078cfb4ea91
Reviewed-on: https://gerrit.libreoffice.org/35523Tested-by: 's avatarJenkins <ci@libreoffice.org>
Reviewed-by: 's avatarStephan Bergmann <sbergman@redhat.com>
üst 02bccbe0
......@@ -321,7 +321,7 @@ void SbiSymDef::SetType( SbxDataType t )
sal_Unicode cu = aName[0];
if( cu < 256 )
{
char ch = (char)cu;
unsigned char ch = (unsigned char)cu;
if( ch == '_' )
{
ch = 'Z';
......
......@@ -375,7 +375,7 @@ bool isdigitAsciiString(const OUString &rString)
{
return std::all_of(
rString.getStr(), rString.getStr() + rString.getLength(),
rtl::isAsciiDigit);
[](sal_Unicode c){ return rtl::isAsciiDigit(c); });
}
namespace
......
......@@ -238,7 +238,8 @@ private:
inline char tocharlower(char c)
{
return static_cast<char>(rtl::toAsciiLowerCase(c));
return static_cast<char>(
rtl::toAsciiLowerCase(static_cast<unsigned char>(c)));
}
#endif
......
......@@ -460,7 +460,7 @@ bool HelpCompiler::compile()
std::string appl = module.substr(1);
for (char & i : appl)
{
i=rtl::toAsciiUpperCase(i);
i=rtl::toAsciiUpperCase(static_cast<unsigned char>(i));
}
xmlNodePtr docResolved = clone(xmlDocGetRootElement(docResolvedOrg), appl);
myparser aparser(documentId, fileName, title);
......
......@@ -581,7 +581,8 @@ static void getOutlineNumStr(int style, int level, int num, hchar * hstr)
ptr = buf;
while (*ptr)
{
*ptr = sal::static_int_cast<char>(rtl::toAsciiUpperCase(*ptr));
*ptr = sal::static_int_cast<char>(
rtl::toAsciiUpperCase(static_cast<unsigned char>(*ptr)));
ptr++;
}
}
......@@ -683,7 +684,7 @@ hchar_string Outline::GetUnicode() const
char *ptr = dest;
while( *ptr )
{
*ptr = sal::static_int_cast<char>(rtl::toAsciiUpperCase(*ptr));
*ptr = sal::static_int_cast<char>(rtl::toAsciiUpperCase(static_cast<unsigned char>(*ptr)));
ptr++;
}
}
......
......@@ -418,15 +418,16 @@ void make_keyword( char *keyword, const char *token)
memcpy(keyword, token, len);
keyword[len] = 0;
if( (token[0] & 0x80) || rtl::isAsciiLowerCase(token[0]) || strlen(token) < 2 )
if( (token[0] & 0x80) || rtl::isAsciiLowerCase(static_cast<unsigned char>(token[0])) || strlen(token) < 2 )
return;
bool capital = rtl::isAsciiUpperCase(keyword[1]);
bool capital = rtl::isAsciiUpperCase(
static_cast<unsigned char>(keyword[1]));
for( ptr = keyword + 2; *ptr && result; ptr++ )
{
if( (*ptr & 0x80) ||
(!capital && rtl::isAsciiUpperCase(*ptr)) ||
(capital && rtl::isAsciiLowerCase(*ptr)) )
(!capital && rtl::isAsciiUpperCase(static_cast<unsigned char>(*ptr))) ||
(capital && rtl::isAsciiLowerCase(static_cast<unsigned char>(*ptr))) )
{
result = false;
}
......@@ -437,8 +438,9 @@ void make_keyword( char *keyword, const char *token)
ptr = keyword;
while( *ptr )
{
if( rtl::isAsciiUpperCase(*ptr) )
*ptr = sal::static_int_cast<char>(rtl::toAsciiLowerCase(*ptr));
if( rtl::isAsciiUpperCase(static_cast<unsigned char>(*ptr)) )
*ptr = sal::static_int_cast<char>(
rtl::toAsciiLowerCase(static_cast<unsigned char>(*ptr)));
ptr++;
}
}
......@@ -689,8 +691,10 @@ static char eq2ltxconv(MzString& sstr, istream *strm, const char *sentinel)
key[0] = '\\';
strcpy(key + 1, eq->key);
}
if( (eq->flag & EQ_CASE) && rtl::isAsciiUpperCase(token[0]) )
key[1] = sal::static_int_cast<char>(rtl::toAsciiUpperCase(key[1]));
if( (eq->flag & EQ_CASE)
&& rtl::isAsciiUpperCase(static_cast<unsigned char>(token[0])) )
key[1] = sal::static_int_cast<char>(
rtl::toAsciiUpperCase(static_cast<unsigned char>(key[1])));
token = key;
}
......
......@@ -57,6 +57,13 @@ inline bool isAscii(sal_uInt32 code)
return code <= 0x7F;
}
#if defined LIBO_INTERNAL_ONLY
bool isAscii(char) = delete;
bool isAscii(signed char) = delete;
template<typename T> inline bool isAscii(T code)
{ return isAscii(sal_uInt32(code)); }
#endif
/** Check for ASCII lower case character.
@param code A Unicode code point.
......@@ -72,6 +79,13 @@ inline bool isAsciiLowerCase(sal_uInt32 code)
return code >= 'a' && code <= 'z';
}
#if defined LIBO_INTERNAL_ONLY
bool isAsciiLowerCase(char) = delete;
bool isAsciiLowerCase(signed char) = delete;
template<typename T> inline bool isAsciiLowerCase(T code)
{ return isAsciiLowerCase(sal_uInt32(code)); }
#endif
/** Check for ASCII upper case character.
@param code A Unicode code point.
......@@ -87,6 +101,13 @@ inline bool isAsciiUpperCase(sal_uInt32 code)
return code >= 'A' && code <= 'Z';
}
#if defined LIBO_INTERNAL_ONLY
bool isAsciiUpperCase(char) = delete;
bool isAsciiUpperCase(signed char) = delete;
template<typename T> inline bool isAsciiUpperCase(T code)
{ return isAsciiUpperCase(sal_uInt32(code)); }
#endif
/** Check for ASCII alphabetic character.
@param code A Unicode code point.
......@@ -102,6 +123,13 @@ inline bool isAsciiAlpha(sal_uInt32 code)
return isAsciiLowerCase(code) || isAsciiUpperCase(code);
}
#if defined LIBO_INTERNAL_ONLY
bool isAsciiAlpha(char) = delete;
bool isAsciiAlpha(signed char) = delete;
template<typename T> inline bool isAsciiAlpha(T code)
{ return isAsciiAlpha(sal_uInt32(code)); }
#endif
/** Check for ASCII digit character.
@param code A Unicode code point.
......@@ -117,6 +145,13 @@ inline bool isAsciiDigit(sal_uInt32 code)
return code >= '0' && code <= '9';
}
#if defined LIBO_INTERNAL_ONLY
bool isAsciiDigit(char) = delete;
bool isAsciiDigit(signed char) = delete;
template<typename T> inline bool isAsciiDigit(T code)
{ return isAsciiDigit(sal_uInt32(code)); }
#endif
/** Check for ASCII alphanumeric character.
@param code A Unicode code point.
......@@ -132,6 +167,13 @@ inline bool isAsciiAlphanumeric(sal_uInt32 code)
return isAsciiDigit(code) || isAsciiAlpha(code);
}
#if defined LIBO_INTERNAL_ONLY
bool isAsciiAlphanumeric(char) = delete;
bool isAsciiAlphanumeric(signed char) = delete;
template<typename T> inline bool isAsciiAlphanumeric(T code)
{ return isAsciiAlphanumeric(sal_uInt32(code)); }
#endif
/** Check for ASCII canonic hexadecimal digit character.
@param code A Unicode code point.
......@@ -147,6 +189,13 @@ inline bool isAsciiCanonicHexDigit(sal_uInt32 code)
return isAsciiDigit(code) || (code >= 'A' && code <= 'F');
}
#if defined LIBO_INTERNAL_ONLY
bool isAsciiCanonicHexDigit(char) = delete;
bool isAsciiCanonicHexDigit(signed char) = delete;
template<typename T> inline bool isAsciiCanonicHexDigit(T code)
{ return isAsciiCanonicHexDigit(sal_uInt32(code)); }
#endif
/** Check for ASCII hexadecimal digit character.
@param code A Unicode code point.
......@@ -162,6 +211,13 @@ inline bool isAsciiHexDigit(sal_uInt32 code)
return isAsciiCanonicHexDigit(code) || (code >= 'a' && code <= 'f');
}
#if defined LIBO_INTERNAL_ONLY
bool isAsciiHexDigit(char) = delete;
bool isAsciiHexDigit(signed char) = delete;
template<typename T> inline bool isAsciiHexDigit(T code)
{ return isAsciiHexDigit(sal_uInt32(code)); }
#endif
/** Check for ASCII octal digit character.
@param code A Unicode code point.
......@@ -176,6 +232,12 @@ inline bool isAsciiOctalDigit(sal_uInt32 code)
return code >= '0' && code <= '7';
}
#if defined LIBO_INTERNAL_ONLY
bool isAsciiOctalDigit(char) = delete;
bool isAsciiOctalDigit(signed char) = delete;
template<typename T> inline bool isAsciiOctalDigit(T code)
{ return isAsciiOctalDigit(sal_uInt32(code)); }
#endif
/** Convert a character, if ASCII, to upper case.
......@@ -191,6 +253,13 @@ inline sal_uInt32 toAsciiUpperCase(sal_uInt32 code)
return isAsciiLowerCase(code) ? code - 32 : code;
}
#if defined LIBO_INTERNAL_ONLY
sal_uInt32 toAsciiUpperCase(char) = delete;
sal_uInt32 toAsciiUpperCase(signed char) = delete;
template<typename T> inline sal_uInt32 toAsciiUpperCase(T code)
{ return toAsciiUpperCase(sal_uInt32(code)); }
#endif
/** Convert a character, if ASCII, to lower case.
@param code A Unicode code point.
......@@ -205,6 +274,13 @@ inline sal_uInt32 toAsciiLowerCase(sal_uInt32 code)
return isAsciiUpperCase(code) ? code + 32 : code;
}
#if defined LIBO_INTERNAL_ONLY
sal_uInt32 toAsciiLowerCase(char) = delete;
sal_uInt32 toAsciiLowerCase(signed char) = delete;
template<typename T> inline sal_uInt32 toAsciiLowerCase(T code)
{ return toAsciiLowerCase(sal_uInt32(code)); }
#endif
/** Compare two characters ignoring ASCII case.
@param code1 A Unicode code point.
......
......@@ -61,7 +61,8 @@ static int startsAsciiCaseInsensitive(const std::string &s1, const std::string &
min = s2.length();
for(i = 0; i < min && s2[i] && s1[i] && !ret; i++){
ret = rtl::toAsciiUpperCase(s1[i]) - rtl::toAsciiUpperCase(s2[i]);
ret = rtl::toAsciiUpperCase(static_cast<unsigned char>(s1[i]))
- rtl::toAsciiUpperCase(static_cast<unsigned char>(s2[i]));
if(s1[i] == '.' || s2[i] == '.') {ret = 0;} //. is a neutral character
}
return ret;
......
......@@ -110,7 +110,7 @@ char * RscChar::MakeUTF8( char * pStr, sal_uInt16 nTextEncoding )
{
if( isdigit( *pStr ) )
nChar = nChar * 16 + (sal_uInt8)*pStr - (sal_uInt8)'0';
else if( rtl::isAsciiUpperCase( *pStr ) )
else if( rtl::isAsciiUpperCase( static_cast<unsigned char>(*pStr) ) )
nChar = nChar * 16 + (sal_uInt8)*pStr - (sal_uInt8)'A' +10;
else
nChar = nChar * 16 + (sal_uInt8)*pStr - (sal_uInt8)'a' +10;
......
......@@ -918,8 +918,12 @@ double SAL_CALL rtl_math_stringToDouble(sal_Char const * pBegin,
sal_Char const ** pParsedEnd)
SAL_THROW_EXTERN_C()
{
return stringToDouble(pBegin, pEnd, cDecSeparator, cGroupSeparator, pStatus,
pParsedEnd);
return stringToDouble(
reinterpret_cast<unsigned char const *>(pBegin),
reinterpret_cast<unsigned char const *>(pEnd),
static_cast<unsigned char>(cDecSeparator),
static_cast<unsigned char>(cGroupSeparator), pStatus,
reinterpret_cast<unsigned char const **>(pParsedEnd));
}
double SAL_CALL rtl_math_uStringToDouble(sal_Unicode const * pBegin,
......
......@@ -30,7 +30,11 @@ void IncludesCollection::add_to_collection(const string& dirPath) {
}
do {
string winFileName(FindFileData.cFileName);
transform(winFileName.begin(), winFileName.end(), winFileName.begin(), rtl::toAsciiLowerCase);
transform(
winFileName.begin(), winFileName.end(), winFileName.begin(),
[](char c) {
return rtl::toAsciiLowerCase(static_cast<unsigned char>(c));
});
dirContent.insert(winFileName);
} while (FindNextFile(hFind, &FindFileData));
#else
......@@ -52,7 +56,11 @@ void IncludesCollection::add_to_collection(const string& dirPath) {
bool IncludesCollection::exists(string filePath) {
#if defined(_WIN32)
transform(filePath.begin(), filePath.end(), filePath.begin(), rtl::toAsciiLowerCase);
transform(
filePath.begin(), filePath.end(), filePath.begin(),
[](char c) {
return rtl::toAsciiLowerCase(static_cast<unsigned char>(c));
});
#endif // defined( WNT )
PathFilePair dirFile = split_path(filePath);
string dirPath = dirFile.first;
......
......@@ -892,7 +892,9 @@ bool equalIgnoreCase(const sal_Char * pBegin1,
while (*pString2 != 0)
if (pBegin1 == pEnd1
|| rtl::toAsciiUpperCase(*pBegin1++) != rtl::toAsciiUpperCase(*pString2++))
|| (rtl::toAsciiUpperCase(static_cast<unsigned char>(*pBegin1++))
!= rtl::toAsciiUpperCase(
static_cast<unsigned char>(*pString2++))))
return false;
return pBegin1 == pEnd1;
}
......@@ -1154,7 +1156,9 @@ bool INetMIME::equalIgnoreCase(const sal_Unicode * pBegin1,
while (*pString2 != 0)
if (pBegin1 == pEnd1
|| rtl::toAsciiUpperCase(*pBegin1++) != rtl::toAsciiUpperCase(*pString2++))
|| (rtl::toAsciiUpperCase(*pBegin1++)
!= rtl::toAsciiUpperCase(
static_cast<unsigned char>(*pString2++))))
return false;
return pBegin1 == pEnd1;
}
......@@ -1317,7 +1321,9 @@ OUString INetMIME::decodeHeaderFieldBody(const OString& rBody)
default:
if (pLanguageBegin != nullptr
&& (!rtl::isAsciiAlpha(cChar) || ++nAlphaCount > 8))
&& (!rtl::isAsciiAlpha(
static_cast<unsigned char>(cChar))
|| ++nAlphaCount > 8))
pLanguageBegin = nullptr;
break;
}
......
......@@ -57,7 +57,9 @@ static const sal_Char *months[12] =
static sal_uInt16 ParseNumber(const OString& rStr, sal_Int32& nIndex)
{
sal_Int32 n = nIndex;
while ((n < rStr.getLength()) && rtl::isAsciiDigit(rStr[n])) n++;
while ((n < rStr.getLength())
&& rtl::isAsciiDigit(static_cast<unsigned char>(rStr[n])))
n++;
OString aNum(rStr.copy(nIndex, (n - nIndex)));
nIndex = n;
......@@ -68,7 +70,9 @@ static sal_uInt16 ParseNumber(const OString& rStr, sal_Int32& nIndex)
static sal_uInt16 ParseMonth(const OString& rStr, sal_Int32& nIndex)
{
sal_Int32 n = nIndex;
while ((n < rStr.getLength()) && rtl::isAsciiAlpha(rStr[n])) n++;
while ((n < rStr.getLength())
&& rtl::isAsciiAlpha(static_cast<unsigned char>(rStr[n])))
n++;
OString aMonth(rStr.copy(nIndex, 3));
nIndex = n;
......@@ -99,7 +103,7 @@ bool INetMIMEMessage::ParseDateField (
while (
(nIndex < aDateField.getLength()) &&
(rtl::isAsciiAlpha (aDateField[nIndex]) ||
(rtl::isAsciiAlpha (static_cast<unsigned char>(aDateField[nIndex])) ||
(aDateField[nIndex] == ',') ))
nIndex++;
......@@ -107,7 +111,7 @@ bool INetMIMEMessage::ParseDateField (
(aDateField[nIndex] == ' '))
nIndex++;
if (rtl::isAsciiAlpha (aDateField[nIndex]))
if (rtl::isAsciiAlpha (static_cast<unsigned char>(aDateField[nIndex])))
{
// Format: ctime().
if ((aDateField.getLength() - nIndex) < 20) return false;
......
......@@ -188,7 +188,7 @@ bool SvGlobalName::MakeId( const OUString & rIdStr )
if( isdigit( *pStr ) )
nFirst = nFirst * 16 + (*pStr - '0');
else
nFirst = nFirst * 16 + (rtl::toAsciiUpperCase( *pStr ) - 'A' + 10 );
nFirst = nFirst * 16 + (rtl::toAsciiUpperCase( static_cast<unsigned char>(*pStr) ) - 'A' + 10 );
else
return false;
pStr++;
......@@ -202,7 +202,7 @@ bool SvGlobalName::MakeId( const OUString & rIdStr )
if( isdigit( *pStr ) )
nSec = nSec * 16 + (*pStr - '0');
else
nSec = nSec * 16 + (sal_uInt16)(rtl::toAsciiUpperCase( *pStr ) - 'A' + 10 );
nSec = nSec * 16 + (sal_uInt16)(rtl::toAsciiUpperCase( static_cast<unsigned char>(*pStr) ) - 'A' + 10 );
else
return false;
pStr++;
......@@ -216,7 +216,7 @@ bool SvGlobalName::MakeId( const OUString & rIdStr )
if( isdigit( *pStr ) )
nThird = nThird * 16 + (*pStr - '0');
else
nThird = nThird * 16 + (sal_uInt16)(rtl::toAsciiUpperCase( *pStr ) - 'A' + 10 );
nThird = nThird * 16 + (sal_uInt16)(rtl::toAsciiUpperCase( static_cast<unsigned char>(*pStr) ) - 'A' + 10 );
else
return false;
pStr++;
......@@ -231,7 +231,7 @@ bool SvGlobalName::MakeId( const OUString & rIdStr )
if( isdigit( *pStr ) )
szRemain[i/2] = szRemain[i/2] * 16 + (*pStr - '0');
else
szRemain[i/2] = szRemain[i/2] * 16 + (sal_Int8)(rtl::toAsciiUpperCase( *pStr ) - 'A' + 10 );
szRemain[i/2] = szRemain[i/2] * 16 + (sal_Int8)(rtl::toAsciiUpperCase( static_cast<unsigned char>(*pStr) ) - 'A' + 10 );
else
return false;
pStr++;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment