From ae13a9a2121de5dd4c4f1c464edf5ef0352b97d7 Mon Sep 17 00:00:00 2001 From: Kein-Hong Man Date: Thu, 10 Dec 2015 13:07:42 +1100 Subject: Flag incomplete here doc delimiters as syntax errors, matching bash 4.3. Avoid heap allocations for here delimiter and quote stack. --- cppcheck.suppress | 2 +- doc/ScintillaHistory.html | 4 ++++ lexers/LexBash.cxx | 26 ++++++++++---------------- 3 files changed, 15 insertions(+), 17 deletions(-) diff --git a/cppcheck.suppress b/cppcheck.suppress index aea0ad98f..46e814ddc 100644 --- a/cppcheck.suppress +++ b/cppcheck.suppress @@ -15,7 +15,7 @@ unusedPrivateFunction:scintilla/win32/PlatWin.cxx // Suppress most lexer warnings since the lexers are maintained by others useInitializationList:scintilla/lexers/LexAsm.cxx useInitializationList:scintilla/lexers/LexBasic.cxx -noCopyConstructor:scintilla/lexers/LexBash.cxx +uninitMemberVar:scintilla/lexers/LexBash.cxx variableScope:scintilla/lexers/LexBash.cxx variableScope:scintilla/lexers/LexBatch.cxx variableScope:scintilla/lexers/LexCmake.cxx diff --git a/doc/ScintillaHistory.html b/doc/ScintillaHistory.html index fa2ae5acf..4b1b43f2a 100644 --- a/doc/ScintillaHistory.html +++ b/doc/ScintillaHistory.html @@ -504,6 +504,10 @@ the document is already styled when the user scrolls to it.
  • + Bash lexer flags incomplete here doc delimiters as syntax errors. + Bug #1789. +
  • +
  • Send SCN_UPDATEUI with SC_UPDATE_SELECTION when the application changes multiple selection.
  • diff --git a/lexers/LexBash.cxx b/lexers/LexBash.cxx index 21c47e577..f9d4d2a25 100644 --- a/lexers/LexBash.cxx +++ b/lexers/LexBash.cxx @@ -126,14 +126,13 @@ static void ColouriseBashDoc(Sci_PositionU startPos, Sci_Position length, int in bool Quoted; // true if Quote in ('\'','"','`') bool Indent; // indented delimiter (for <<-) int DelimiterLength; // strlen(Delimiter) - char *Delimiter; // the Delimiter, 256: sizeof PL_tokenbuf + char Delimiter[HERE_DELIM_MAX]; // the Delimiter HereDocCls() { State = 0; Quote = 0; Quoted = false; Indent = 0; DelimiterLength = 0; - Delimiter = new char[HERE_DELIM_MAX]; Delimiter[0] = '\0'; } void Append(int ch) { @@ -141,7 +140,6 @@ static void ColouriseBashDoc(Sci_PositionU startPos, Sci_Position length, int in Delimiter[DelimiterLength] = '\0'; } ~HereDocCls() { - delete []Delimiter; } }; HereDocCls HereDoc; @@ -173,18 +171,15 @@ static void ColouriseBashDoc(Sci_PositionU startPos, Sci_Position length, int in int Up, Down; int Style; int Depth; // levels pushed - int *CountStack; - int *UpStack; - int *StyleStack; + int CountStack[BASH_DELIM_STACK_MAX]; + int UpStack [BASH_DELIM_STACK_MAX]; + int StyleStack[BASH_DELIM_STACK_MAX]; QuoteStackCls() { Count = 0; Up = '\0'; Down = '\0'; Style = 0; Depth = 0; - CountStack = new int[BASH_DELIM_STACK_MAX]; - UpStack = new int[BASH_DELIM_STACK_MAX]; - StyleStack = new int[BASH_DELIM_STACK_MAX]; } void Start(int u, int s) { Count = 1; @@ -214,9 +209,6 @@ static void ColouriseBashDoc(Sci_PositionU startPos, Sci_Position length, int in Down = opposite(Up); } ~QuoteStackCls() { - delete []CountStack; - delete []UpStack; - delete []StyleStack; } }; QuoteStackCls QuoteStack; @@ -584,12 +576,14 @@ static void ColouriseBashDoc(Sci_PositionU startPos, Sci_Position length, int in HereDoc.State = 2; if (HereDoc.Quoted) { if (sc.state == SCE_SH_HERE_DELIM) { - // Missing quote at end of string! We are stricter than bash. - // Colour here-doc anyway while marking this bit as an error. + // Missing quote at end of string! Syntax error in bash 4.3 + // Mark this bit as an error, do not colour any here-doc sc.ChangeState(SCE_SH_ERROR); + sc.SetState(SCE_SH_DEFAULT); + } else { + // HereDoc.Quote always == '\'' + sc.SetState(SCE_SH_HERE_Q); } - // HereDoc.Quote always == '\'' - sc.SetState(SCE_SH_HERE_Q); } else if (HereDoc.DelimiterLength == 0) { // no delimiter, illegal (but '' and "" are legal) sc.ChangeState(SCE_SH_ERROR); -- cgit v1.2.3