Skip to content

Commit 098aa77

Browse files
committed
fixup! built-in add -p: implement the hunk splitting feature
A recently-reported bug had its root cause in the `splittable_into` variable overcounting the number of potential hunks (the symptom was misleading, it said that there was an unhandled diff marker). Let's make sure to catch these things earlier, with a less misleading error message. Signed-off-by: Johannes Schindelin <[email protected]>
1 parent c59445a commit 098aa77

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

add-patch.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -853,6 +853,10 @@ static int split_hunk(struct add_p_state *s, struct file_diff *file_diff,
853853

854854
while (splittable_into > 1) {
855855
ch = s->plain.buf[current];
856+
857+
if (!ch)
858+
BUG("buffer overrun while splitting hunks");
859+
856860
if ((marker == '-' || marker == '+') && ch == ' ') {
857861
first = 0;
858862
hunk[1].start = current;

0 commit comments

Comments
 (0)