From 9944617df66bb15643a5f9049a5b249411b4cbdb Mon Sep 17 00:00:00 2001 From: Fangrui Song Date: Wed, 31 Jan 2018 16:48:26 -0800 Subject: [PATCH] Fix #385 --- src/working_files.cc | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/working_files.cc b/src/working_files.cc index c3d634ad..2b2afea4 100644 --- a/src/working_files.cc +++ b/src/working_files.cc @@ -44,7 +44,7 @@ lsPosition GetPositionForOffset(const std::string& content, int offset) { // If the distance is larger than threshold, returns threshould + 1. int MyersDiff(const char* a, int la, const char* b, int lb, int threshold) { assert(threshold <= kMaxDiff); - static int v_static[kMaxDiff + 2]; + static int v_static[2 * kMaxColumnAlignSize + 2]; const char *ea = a + la, *eb = b + lb; // Strip prefix for (; a < ea && b < eb && *a == *b; a++, b++) { @@ -54,6 +54,9 @@ int MyersDiff(const char* a, int la, const char* b, int lb, int threshold) { } la = int(ea - a); lb = int(eb - b); + // If the sum of lengths exceeds what we can handle, return a lower bound. + if (la + lb > 2 * kMaxColumnAlignSize) + return std::min(abs(la - lb), threshold + 1); int* v = v_static + lb; v[1] = 0;