aboutsummaryrefslogtreecommitdiff
path: root/refs/iterator.c
diff options
context:
space:
mode:
Diffstat (limited to 'refs/iterator.c')
-rw-r--r--refs/iterator.c18
1 files changed, 17 insertions, 1 deletions
diff --git a/refs/iterator.c b/refs/iterator.c
index bce1f192f..4cf449ef6 100644
--- a/refs/iterator.c
+++ b/refs/iterator.c
@@ -292,7 +292,23 @@ static int prefix_ref_iterator_advance(struct ref_iterator *ref_iterator)
if (!starts_with(iter->iter0->refname, iter->prefix))
continue;
- iter->base.refname = iter->iter0->refname + iter->trim;
+ if (iter->trim) {
+ /*
+ * It is nonsense to trim off characters that
+ * you haven't already checked for via a
+ * prefix check, whether via this
+ * `prefix_ref_iterator` or upstream in
+ * `iter0`). So if there wouldn't be at least
+ * one character left in the refname after
+ * trimming, report it as a bug:
+ */
+ if (strlen(iter->iter0->refname) <= iter->trim)
+ die("BUG: attempt to trim too many characters");
+ iter->base.refname = iter->iter0->refname + iter->trim;
+ } else {
+ iter->base.refname = iter->iter0->refname;
+ }
+
iter->base.oid = iter->iter0->oid;
iter->base.flags = iter->iter0->flags;
return ITER_OK;