From faad7a3ed19ad5bc604c48123583634234479c93 Mon Sep 17 00:00:00 2001 From: Conor Byrne <71222289+cbyrneee@users.noreply.github.com> Date: Thu, 30 Dec 2021 16:41:29 +0000 Subject: [PATCH] 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. --- Userland/Libraries/LibDiff/Hunks.cpp | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/Userland/Libraries/LibDiff/Hunks.cpp b/Userland/Libraries/LibDiff/Hunks.cpp index 6870dda028..fe526045aa 100644 --- a/Userland/Libraries/LibDiff/Hunks.cpp +++ b/Userland/Libraries/LibDiff/Hunks.cpp @@ -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++] != '-') { }