Emit warning for bad working file index instead of crashing.

This commit is contained in:
Jacob Dufault 2017-05-06 22:34:43 -07:00
parent 1b4f377682
commit e1e45b6dc5

View File

@ -74,9 +74,11 @@ optional<int> WorkingFile::GetBufferLineFromIndexLine(int index_line) const {
// Note: |index_line| and |buffer_line| are 1-based.
// TODO: reenable this assert once we are using the real indexed file.
assert(index_line >= 1 && index_line <= index_lines.size());
//if (index_line < 1 || index_line > index_lines.size())
// return nullopt;
//assert(index_line >= 1 && index_line <= index_lines.size());
if (index_line < 1 || index_line > index_lines.size()) {
std::cerr << "!! Bad index_line (got " << index_line << ", expected [1, " << index_lines.size() << "])" << std::endl;
return nullopt;
}
// Find the line in the cached index file. We'll try to find the most similar line
// in the buffer and return the index for that.
@ -108,9 +110,11 @@ optional<int> WorkingFile::GetIndexLineFromBufferLine(int buffer_line) const {
// See GetBufferLineFromIndexLine for additional comments.
// Note: |index_line| and |buffer_line| are 1-based.
assert(buffer_line >= 1 && buffer_line < all_buffer_lines.size());
//if (buffer_line < 1 || buffer_line > all_buffer_lines.size())
// return nullopt;
//assert(buffer_line >= 1 && buffer_line < all_buffer_lines.size());
if (buffer_line < 1 || buffer_line > all_buffer_lines.size()) {
std::cerr << "!! Bad buffer_line (got " << buffer_line << ", expected [1, " << all_buffer_lines.size() << "])" << std::endl;
return nullopt;
}
// Find the line in the index file. We'll try to find the most similar line
// in the index file and return the index for that.