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:
parent
507ad1954f
commit
faad7a3ed1
Notes:
sideshowbarker
2024-07-17 23:00:03 +09:00
Author: https://github.com/caoimhebyrne Commit: https://github.com/SerenityOS/serenity/commit/faad7a3ed19 Pull-request: https://github.com/SerenityOS/serenity/pull/11509 Issue: https://github.com/SerenityOS/serenity/issues/8979 Reviewed-by: https://github.com/itamar8910 ✅
1 changed files with 10 additions and 4 deletions
|
@ -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++] != '-') {
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue