+ fix: prevent _ctype assertions in Scintilla's lexer

This commit is contained in:
Rainer Kottenhoff 2019-09-19 09:26:44 +02:00
parent 892fa44e1b
commit 1d28edf6e5
17 changed files with 37 additions and 37 deletions

View File

@ -409,7 +409,7 @@ void SCI_METHOD LexerAHKL::Lex(Sci_PositionU startPos, Sci_Position lengthDoc, i
sc.SetState(SCE_AHKL_NEUTRAL);
} else if ((OnlySpaces || isspace(sc.chPrev)) &&
((sc.ch == '@' && isalnum(sc.chNext)) || valDocComment.Contains(sc.ch))) {
((sc.ch == '@' && isalnum(sc.chNext & 0xFF)) || valDocComment.Contains(sc.ch))) {
if (valDocComment.Contains(sc.ch))
inDocComment = true;
@ -442,7 +442,7 @@ void SCI_METHOD LexerAHKL::Lex(Sci_PositionU startPos, Sci_Position lengthDoc, i
if (isspace(sc.ch) || SynOperator.Contains(sc.ch))
sc.SetState(SCE_AHKL_NEUTRAL);
else if (!isxdigit(sc.ch))
else if (!isxdigit(sc.ch & 0xFF))
sc.ChangeState(SCE_AHKL_IDENTIFIER);
break;
}

View File

@ -76,12 +76,12 @@ static inline bool IsTypeCharacter(const int ch)
}
static inline bool IsAWordChar(const int ch)
{
return (ch < 0x80) && (isalnum(ch) || ch == '_');
return ((IsASCII(ch) && isalnum(ch)) || ch == '_');
}
static inline bool IsAWordStart(const int ch)
{
return (ch < 0x80) && (isalnum(ch) || ch == '_' || ch == '@' || ch == '#' || ch == '$' || ch == '.');
return ((IsASCII(ch) && isalnum(ch)) || ch == '_' || ch == '@' || ch == '#' || ch == '$' || ch == '.');
}
static inline bool IsAOperator(char ch) {
@ -140,7 +140,7 @@ static int GetSendKey(const char *szLine, char *szKey)
// Save second portion into var...
szSpecial[nSpecPos++] = cTemp;
// check if Second portion is all numbers for repeat fuction
if (isdigit(cTemp) == false) {nSpecNum = 0;}
if (isdigit(cTemp & 0xFF) == false) {nSpecNum = 0;}
}
}
nPos++; // skip to next char

View File

@ -27,7 +27,7 @@
using namespace Scintilla;
static inline bool IsAWordChar(const int ch) {
return (ch < 0x80) && (isalnum(ch) || ch == '_');
return IsASCII(ch) && (isalnum(ch) || ch == '_');
}
static inline bool IsAWordStart(int ch) {
@ -37,7 +37,7 @@ static inline bool IsAWordStart(int ch) {
static inline bool IsANumberChar(int ch) {
// Not exactly following number definition (several dots are seen as OK, etc.)
// but probably enough in most cases.
return (ch < 0x80) && (isdigit(ch) || ch == '.' || ch == '-' || ch == '+');
return IsASCII(ch) && (isdigit(ch) || ch == '.' || ch == '-' || ch == '+');
}
static void ColouriseAvsDoc(

View File

@ -35,17 +35,17 @@
using namespace Scintilla;
static inline bool IsAWordChar(const int ch) {
return (ch < 0x80) && (isalnum(ch) || ch == '.' ||
return IsASCII(ch) && (isalnum(ch) || ch == '.' ||
ch == '_' || ch == '?');
}
static inline bool IsAWordStart(const int ch) {
return (ch < 0x80) && (isalnum(ch) || ch == '_' || ch == '.' ||
return IsASCII(ch) && (isalnum(ch) || ch == '_' || ch == '.' ||
ch == '%' || ch == '@' || ch == '$' || ch == '?');
}
static inline bool IsAsmOperator(const int ch) {
if ((ch < 0x80) && (isalnum(ch)))
if (IsASCII(ch) && (isalnum(ch)))
return false;
// '.' left out as it is used to make up numbers
if (ch == '*' || ch == '/' || ch == '-' || ch == '+' ||

View File

@ -1151,7 +1151,7 @@ void SCI_METHOD LexerCPP::Lex(Sci_PositionU startPos, Sci_Position length, int i
sc.SetState(SCE_C_DEFAULT|activitySet);
} else if (! inRERange && sc.ch == '/') {
sc.Forward();
while ((sc.ch < 0x80) && islower(sc.ch))
while (IsASCII(sc.ch) && islower(sc.ch))
sc.Forward(); // gobble regex flags
sc.SetState(SCE_C_DEFAULT|activitySet);
} else if (sc.ch == '\\' && ((sc.currentPos+1) < lineEndNext)) {

View File

@ -41,11 +41,11 @@ static inline bool IsAWordChar(const unsigned int ch) {
* Unfortunately, we are only getting string bytes here, and not full unicode characters. We cannot guarantee
* that our byte is between U+0080 - U+00A0 (to return false), so we have to allow all characters U+0080 and higher
*/
return ch >= 0x80 || isalnum(ch) || ch == '-' || ch == '_';
return ch >= 0x80 || isalnum(ch & 0xFF) || ch == '-' || ch == '_';
}
inline bool IsCssOperator(const int ch) {
if (!((ch < 0x80) && isalnum(ch)) &&
if (!(IsASCII(ch) && isalnum(ch)) &&
(ch == '{' || ch == '}' || ch == ':' || ch == ',' || ch == ';' ||
ch == '.' || ch == '#' || ch == '!' || ch == '@' ||
/* CSS2 */

View File

@ -239,7 +239,7 @@ static void ColouriseCoffeeScriptDoc(Sci_PositionU startPos, Sci_Position length
sc.SetState(SCE_COFFEESCRIPT_DEFAULT);
} else if (sc.ch == '/') {
sc.Forward();
while ((sc.ch < 0x80) && islower(sc.ch))
while (IsASCII(sc.ch) && islower(sc.ch))
sc.Forward(); // gobble regex flags
sc.SetState(SCE_COFFEESCRIPT_DEFAULT);
} else if (sc.ch == '\\') {

View File

@ -39,11 +39,11 @@ enum script_type { eScriptNone = 0, eScriptJS, eScriptVBS, eScriptPython, eScrip
enum script_mode { eHtml = 0, eNonHtmlScript, eNonHtmlPreProc, eNonHtmlScriptPreProc };
inline bool IsAWordChar(const int ch) {
return (ch < 0x80) && (isalnum(ch) || ch == '.' || ch == '_');
return IsASCII(ch) && (isalnum(ch) || ch == '.' || ch == '_');
}
inline bool IsAWordStart(const int ch) {
return (ch < 0x80) && (isalnum(ch) || ch == '_');
return IsASCII(ch) && (isalnum(ch) || ch == '_');
}
inline bool IsOperator(int ch) {
@ -1676,7 +1676,7 @@ void SCI_METHOD LexerHTML::Lex(Sci_PositionU startPos, Sci_Position length, int
case SCE_H_SGML_SPECIAL:
if (!(IsASCII(ch) && isupper(ch))) {
styler.ColourTo(i - 1, StateToPrint);
if (isalnum(ch)) {
if (isalnum(ch & 0xFF)) {
state = SCE_H_SGML_ERROR;
} else {
state = SCE_H_SGML_DEFAULT;

View File

@ -60,7 +60,7 @@ constexpr bool IsLetter(const int ch) noexcept {
}
bool IsAWordChar(const int ch) noexcept {
return ch < 0x80 && (isalnum(ch) || ch == '_' || ch == '.');
return IsASCII(ch) && (isalnum(ch) || ch == '_' || ch == '.');
}
int IsNumHex(const StyleContext &sc) noexcept {
@ -804,4 +804,4 @@ void SCI_METHOD LexerNim::Fold(Sci_PositionU startPos, Sci_Position length, int,
}
}
LexerModule lmNim(SCLEX_NIM, LexerNim::LexerFactoryNim, "nim", nimWordListDesc);
LexerModule lmNim(SCLEX_NIM, LexerNim::LexerFactoryNim, "nim", nimWordListDesc);

View File

@ -27,7 +27,7 @@ using namespace Scintilla;
// Extended to accept accented characters
static inline bool IsAWordChar(int ch) {
return ch >= 0x80 || isalnum(ch) || ch == '-' || ch == '_';
return IsASCII(ch) || isalnum(ch) || ch == '-' || ch == '_';
}
static void ColourisePowerShellDoc(Sci_PositionU startPos, Sci_Position length, int initStyle,

View File

@ -186,7 +186,7 @@ int GetPyStringState(Accessor &styler, Sci_Position i, Sci_PositionU *nextIndex,
}
inline bool IsAWordChar(int ch, bool unicodeIdentifiers) {
if (ch < 0x80)
if (IsASCII(ch))
return (isalnum(ch) || ch == '.' || ch == '_');
if (!unicodeIdentifiers)
@ -197,7 +197,7 @@ inline bool IsAWordChar(int ch, bool unicodeIdentifiers) {
}
inline bool IsAWordStart(int ch, bool unicodeIdentifiers) {
if (ch < 0x80)
if (IsASCII(ch))
return (isalpha(ch) || ch == '_');
if (!unicodeIdentifiers)

View File

@ -27,11 +27,11 @@
using namespace Scintilla;
static inline bool IsAWordChar(const int ch) {
return (ch < 0x80) && (isalnum(ch) || ch == '.' || ch == '_');
return IsASCII(ch) && (isalnum(ch) || ch == '.' || ch == '_');
}
static inline bool IsAWordStart(const int ch) {
return (ch < 0x80) && (isalnum(ch) || ch == '_');
return IsASCII(ch) && (isalnum(ch) || ch == '_');
}
static inline bool IsAnOperator(const int ch) {

View File

@ -54,7 +54,7 @@ static inline bool isSafeWordcharOrHigh(char ch) {
// Error: scintilla's KeyWords.h includes '.' as a word-char
// we want to separate things that can take methods from the
// methods.
return isHighBitChar(ch) || isalnum(ch) || ch == '_';
return isHighBitChar(ch) || isalnum(ch & 0xFF) || ch == '_';
}
static bool inline iswhitespace(char ch) {

View File

@ -37,17 +37,17 @@ using namespace Scintilla;
static inline bool IsAWordChar(int ch, bool sqlAllowDottedWord) {
if (!sqlAllowDottedWord)
return (ch < 0x80) && (isalnum(ch) || ch == '_');
return IsASCII(ch) && (isalnum(ch) || ch == '_');
else
return (ch < 0x80) && (isalnum(ch) || ch == '_' || ch == '.');
return IsASCII(ch) && (isalnum(ch) || ch == '_' || ch == '.');
}
static inline bool IsAWordStart(int ch) {
return (ch < 0x80) && (isalpha(ch) || ch == '_');
return IsASCII(ch) && (isalpha(ch) || ch == '_');
}
static inline bool IsADoxygenChar(int ch) {
return (islower(ch) || ch == '$' || ch == '@' ||
return ((IsASCII(ch) && islower(ch)) || ch == '$' || ch == '@' ||
ch == '\\' || ch == '&' || ch == '<' ||
ch == '>' || ch == '#' || ch == '{' ||
ch == '}' || ch == '[' || ch == ']');
@ -56,7 +56,7 @@ static inline bool IsADoxygenChar(int ch) {
static inline bool IsANumberChar(int ch, int chPrev) {
// Not exactly following number definition (several dots are seen as OK, etc.)
// but probably enough in most cases.
return (ch < 0x80) &&
return IsASCII(ch) &&
(isdigit(ch) || toupper(ch) == 'E' ||
ch == '.' || ((ch == '-' || ch == '+') && chPrev < 0x80 && toupper(chPrev) == 'E'));
}

View File

@ -28,11 +28,11 @@ using namespace Scintilla;
// Extended to accept accented characters
static inline bool IsAWordChar(int ch) {
return ch >= 0x80 ||
(isalnum(ch) || ch == '_' || ch ==':' || ch=='.'); // : name space separator
(isalnum(ch & 0xFF) || ch == '_' || ch ==':' || ch=='.'); // : name space separator
}
static inline bool IsAWordStart(int ch) {
return ch >= 0x80 || (ch ==':' || isalpha(ch) || ch == '_');
return ch >= 0x80 || (ch ==':' || isalpha(ch & 0xFF) || ch == '_');
}
static inline bool IsANumberChar(int ch) {

View File

@ -40,18 +40,18 @@ static inline bool IsTypeCharacter(int ch) {
// Extended to accept accented characters
static inline bool IsAWordChar(int ch) {
return ch >= 0x80 ||
(isalnum(ch) || ch == '.' || ch == '_');
(isalnum(ch & 0xFF) || ch == '.' || ch == '_');
}
static inline bool IsAWordStart(int ch) {
return ch >= 0x80 ||
(isalpha(ch) || ch == '_');
(isalpha(ch & 0xFF) || ch == '_');
}
static inline bool IsANumberChar(int ch) {
// Not exactly following number definition (several dots are seen as OK, etc.)
// but probably enough in most cases.
return (ch < 0x80) &&
return IsASCII(ch) &&
(isdigit(ch) || toupper(ch) == 'E' ||
ch == '.' || ch == '-' || ch == '+' || ch == '_');
}

View File

@ -40,12 +40,12 @@ static void ColouriseVHDLDoc(
/***************************************/
static inline bool IsAWordChar(const int ch) {
return (ch < 0x80) && (isalnum(ch) || ch == '.' || ch == '_' );
return IsASCII(ch) && (isalnum(ch) || ch == '.' || ch == '_' );
}
/***************************************/
static inline bool IsAWordStart(const int ch) {
return (ch < 0x80) && (isalnum(ch) || ch == '_');
return IsASCII(ch) && (isalnum(ch) || ch == '_');
}
/***************************************/