git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: Eric Sunshine <sunshine@sunshineco.com>
To: git@vger.kernel.org
Cc: Eric Sunshine <sunshine@sunshineco.com>,
	Thomas Rast <trast@inf.ethz.ch>,
	Bo Yang <struggleyb.nku@gmail.com>
Subject: [PATCH 3/5] range-set: satisfy non-empty ranges invariant
Date: Tue, 23 Jul 2013 10:28:06 -0400	[thread overview]
Message-ID: <1374589688-27751-4-git-send-email-sunshine@sunshineco.com> (raw)
In-Reply-To: <1374589688-27751-1-git-send-email-sunshine@sunshineco.com>

range-set invariants are: ranges must be (1) non-empty, (2) disjoint,
(3) sorted in ascending order.

During processing, various range-set utility functions break the
invariants (for instance, by adding empty ranges), with the
expectation that a finalizing sort_and_merge_range_set() will restore
sanity.

sort_and_merge_range_set(), however, neglects to fold out empty
ranges, thus it fails to satisfy the non-empty constraint. Subsequent
range-set functions crash or throw an assertion failure upon
encountering such an anomaly. Rectify the situation by having
sort_and_merge_range_set() fold out empty ranges.

Signed-off-by: Eric Sunshine <sunshine@sunshineco.com>
---
 line-log.c          | 2 ++
 t/t4211-line-log.sh | 2 +-
 2 files changed, 3 insertions(+), 1 deletion(-)

diff --git a/line-log.c b/line-log.c
index 5234879..6f94d56 100644
--- a/line-log.c
+++ b/line-log.c
@@ -115,6 +115,8 @@ static void sort_and_merge_range_set(struct range_set *rs)
 	qsort(rs->ranges, rs->nr, sizeof(struct range), range_cmp);
 
 	for (i = 0; i < rs->nr; i++) {
+		if (rs->ranges[i].start == rs->ranges[i].end)
+			continue;
 		if (o > 0 && rs->ranges[i].start <= rs->ranges[o-1].end) {
 			if (rs->ranges[o-1].end < rs->ranges[i].end)
 				rs->ranges[o-1].end = rs->ranges[i].end;
diff --git a/t/t4211-line-log.sh b/t/t4211-line-log.sh
index 1db1edd..12814c0 100755
--- a/t/t4211-line-log.sh
+++ b/t/t4211-line-log.sh
@@ -67,7 +67,7 @@ test_bad_opts "-L :foo:b.c" "no match"
 # There is a separate bug when an empty -L range is the first -L encountered,
 # thus to demonstrate this particular bug, the empty -L range must follow a
 # non-empty -L range.
-test_expect_failure '-L {empty-range} (any -L)' '
+test_expect_success '-L {empty-range} (any -L)' '
 	n=$(expr $(cat b.c | wc -l) + 1) &&
 	git log -L1,1:b.c -L$n:b.c
 '
-- 
1.8.3.4.1120.gc240c48

  parent reply	other threads:[~2013-07-23 14:28 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-07-23 14:28 [PATCH 0/5] range-set and line-log bug fixes Eric Sunshine
2013-07-23 14:28 ` [PATCH 1/5] range-set: fix sort_and_merge_range_set() corner case bug Eric Sunshine
2013-07-23 14:28 ` [PATCH 2/5] t4211: demonstrate empty -L range crash Eric Sunshine
2013-07-23 17:59   ` SZEDER Gábor
2013-07-23 19:03     ` Junio C Hamano
2013-07-23 19:59       ` SZEDER Gábor
2013-07-23 23:15       ` Eric Sunshine
2013-07-24 15:10         ` Junio C Hamano
2013-07-24 20:18           ` Eric Sunshine
2013-07-23 14:28 ` Eric Sunshine [this message]
2013-07-23 14:28 ` [PATCH 4/5] t4211: demonstrate crash when first -L encountered is empty range Eric Sunshine
2013-07-23 14:28 ` [PATCH 5/5] line-log: fix "log -LN" crash when N is last line of file Eric Sunshine
2013-07-23 15:16 ` [PATCH 0/5] range-set and line-log bug fixes Thomas Rast
2013-07-25  8:03 ` Eric Sunshine
2013-07-25  8:09   ` Eric Sunshine
2013-07-25  9:12   ` Johannes Sixt
2013-07-25 13:09     ` Eric Sunshine

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: http://vger.kernel.org/majordomo-info.html

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1374589688-27751-4-git-send-email-sunshine@sunshineco.com \
    --to=sunshine@sunshineco.com \
    --cc=git@vger.kernel.org \
    --cc=struggleyb.nku@gmail.com \
    --cc=trast@inf.ethz.ch \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).