aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authornyamatongwe <devnull@localhost>2012-03-21 23:29:03 +1100
committernyamatongwe <devnull@localhost>2012-03-21 23:29:03 +1100
commit47bf829182a41587ec200ece1dfdfa0bad93a55d (patch)
treebfc80e353c915e02b93600d2050287e2a0b0b1ab
parentf9ae1745b534a9fe0a07e69deed4679bcb469ca9 (diff)
downloadscintilla-mirror-47bf829182a41587ec200ece1dfdfa0bad93a55d.tar.gz
Bug #3508602. Avoid hang with diff files. From zenico.
-rw-r--r--doc/ScintillaHistory.html2
-rw-r--r--lexers/LexOthers.cxx21
2 files changed, 18 insertions, 5 deletions
diff --git a/doc/ScintillaHistory.html b/doc/ScintillaHistory.html
index eb5822512..0e316cb44 100644
--- a/doc/ScintillaHistory.html
+++ b/doc/ScintillaHistory.html
@@ -395,6 +395,8 @@
<td>Gordon Smith</td>
<td>dimitar</td>
<td>Sébastien Granjoux</td>
+ </tr><tr>
+ <td>zenico</td>
</tr>
</table>
<p>
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);
}
}