LibDiff: Fix error when parsing a 'new' hunk location

If the location started at 0, and / or the length was 0, it would
originally turn out to be a location of { -1, -1 } when LibDiff was
finished parsing, which was incorrect.

To fix this, we only subtract 1 if `start` or `length` isn't 0.
This commit is contained in:
Conor Byrne 2021-12-30 16:41:29 +00:00 committed by Andreas Kling
parent 507ad1954f
commit faad7a3ed1
Notes: sideshowbarker 2024-07-17 23:00:03 +09:00

View file

@ -83,10 +83,16 @@ HunkLocation parse_hunk_location(const String& location_line)
};
auto parse_start_and_length_pair = [](const String& raw) {
auto index_of_separator = raw.find(',').value();
auto start = raw.substring(0, index_of_separator);
auto length = raw.substring(index_of_separator + 1, raw.length() - index_of_separator - 1);
auto res = StartAndLength { start.to_uint().value() - 1, length.to_uint().value() - 1 };
return res;
auto start = raw.substring(0, index_of_separator).to_uint().value();
auto length = raw.substring(index_of_separator + 1, raw.length() - index_of_separator - 1).to_uint().value();
if (start != 0)
start--;
if (length != 0)
length--;
return StartAndLength { start, length };
};
while (char_index < location_line.length() && location_line[char_index++] != '-') {
}