diff options
author | nyamatongwe <devnull@localhost> | 2012-03-21 23:29:03 +1100 |
---|---|---|
committer | nyamatongwe <devnull@localhost> | 2012-03-21 23:29:03 +1100 |
commit | 47bf829182a41587ec200ece1dfdfa0bad93a55d (patch) | |
tree | bfc80e353c915e02b93600d2050287e2a0b0b1ab /lexers/LexOthers.cxx | |
parent | f9ae1745b534a9fe0a07e69deed4679bcb469ca9 (diff) | |
download | scintilla-mirror-47bf829182a41587ec200ece1dfdfa0bad93a55d.tar.gz |
Bug #3508602. Avoid hang with diff files. From zenico.
Diffstat (limited to 'lexers/LexOthers.cxx')
-rw-r--r-- | lexers/LexOthers.cxx | 21 |
1 files changed, 16 insertions, 5 deletions
diff --git a/lexers/LexOthers.cxx b/lexers/LexOthers.cxx index 5f4eaed2d..259059fd9 100644 --- a/lexers/LexOthers.cxx +++ b/lexers/LexOthers.cxx @@ -500,6 +500,10 @@ static void ColouriseBatchDoc( } } +#define DIFF_BUFFER_START_SIZE 16 +// Note that ColouriseDiffLine analyzes only the first DIFF_BUFFER_START_SIZE +// characters of each line to classify the line. + static void ColouriseDiffLine(char *lineBuffer, int endLine, Accessor &styler) { // It is needed to remember the current state to recognize starting // comment lines before the first "diff " or "--- ". If a real @@ -556,20 +560,27 @@ static void ColouriseDiffLine(char *lineBuffer, int endLine, Accessor &styler) { } static void ColouriseDiffDoc(unsigned int startPos, int length, int, WordList *[], Accessor &styler) { - char lineBuffer[1024]; + char lineBuffer[DIFF_BUFFER_START_SIZE]; styler.StartAt(startPos); styler.StartSegment(startPos); unsigned int linePos = 0; for (unsigned int i = startPos; i < startPos + length; i++) { - lineBuffer[linePos++] = styler[i]; - if (AtEOL(styler, i) || (linePos >= sizeof(lineBuffer) - 1)) { - // End of line (or of line buffer) met, colourise it - lineBuffer[linePos] = '\0'; + if (AtEOL(styler, i)) { + if (linePos < DIFF_BUFFER_START_SIZE) { + lineBuffer[linePos] = 0; + } ColouriseDiffLine(lineBuffer, i, styler); linePos = 0; + } else if (linePos < DIFF_BUFFER_START_SIZE - 1) { + lineBuffer[linePos++] = styler[i]; + } else if (linePos == DIFF_BUFFER_START_SIZE - 1) { + lineBuffer[linePos++] = 0; } } if (linePos > 0) { // Last line does not have ending characters + if (linePos < DIFF_BUFFER_START_SIZE) { + lineBuffer[linePos] = 0; + } ColouriseDiffLine(lineBuffer, startPos + length - 1, styler); } } |