git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH v2 2/2] range_set: fix coalescing bug when range is a subset of another

From
Thomas Rast <trast@inf.ethz.ch>
Date
Jul 9, 2013, 09:31 UTC
Message-ID
<8738rogjui.fsf@linux-k42r.v.cablecom.net>
In-Reply-To
<1373349305-63917-3-git-send-email-sunshine@sunshineco.com>
Eric Sunshine <sunshine@sunshineco.com> writes:
Show 25 quoted lines
> When coalescing ranges, sort_and_merge_range_set() unconditionally
> assumes that the end of a range being folded into a preceding range
> should become the end of the coalesced range. This assumption, however,
> is invalid when one range is a subset of another.  For example, given
> ranges 1-5 and 2-3 added via range_set_append_unsafe(),
> sort_and_merge_range_set() incorrectly coalesces them to range 1-3
> rather than the correct union range 1-5. Fix this bug.
>
> Signed-off-by: Eric Sunshine <sunshine@sunshineco.com>
> ---
>  line-log.c          | 3 ++-
>  t/t4211-line-log.sh | 4 ++--
>  2 files changed, 4 insertions(+), 3 deletions(-)
>
> diff --git a/line-log.c b/line-log.c
> index 4bbb09b..8cc29a0 100644
> --- a/line-log.c
> +++ b/line-log.c
> @@ -116,7 +116,8 @@ static void sort_and_merge_range_set(struct range_set *rs)
>  
>  	for (i = 1; i < rs->nr; i++) {
>  		if (rs->ranges[i].start <= rs->ranges[o-1].end) {
> -			rs->ranges[o-1].end = rs->ranges[i].end;
> +			if (rs->ranges[o-1].end < rs->ranges[i].end)
> +				rs->ranges[o-1].end = rs->ranges[i].end;
Ouch.  Thanks for finding and fixing this.
Acked-by: Thomas Rast <trast@inf.ethz.ch>
-- 
Thomas Rast
trast@{inf,student}.ethz.ch
Previous: Eric Sunshine
Message 4 of 4 in “fix broken range_set tests and coalescing”
  1. 0/2 fix broken range_set tests and coalescingEric Sunshine, Jul 9, 2013
  2. 1/2 t4211: fix broken test when one -L range is subset of anotherEric Sunshine, Jul 9, 2013
  3. 2/2 range_set: fix coalescing bug when range is a subset of anotherEric Sunshine, Jul 9, 2013
  4. Thomas RastJul 9, 2013

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.