Skip to content

Commit c59445a

Browse files
committed
fixup! built-in add -p: implement the hunk splitting feature
Let's be a bit more defensive in the code that finds the next line: if we are already at the end of the buffer, we definitely do _not_ want to return an offset that is outside the buffer! Signed-off-by: Johannes Schindelin <[email protected]>
1 parent a0870ab commit c59445a

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

add-patch.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -562,8 +562,13 @@ static int parse_diff(struct add_p_state *s, const struct pathspec *ps)
562562

563563
static size_t find_next_line(struct strbuf *sb, size_t offset)
564564
{
565-
char *eol = memchr(sb->buf + offset, '\n', sb->len - offset);
565+
char *eol;
566566

567+
if (offset >= sb->len)
568+
BUG("looking for next line beyond buffer (%d >= %d)\n%s",
569+
(int)offset, (int)sb->len, sb->buf);
570+
571+
eol = memchr(sb->buf + offset, '\n', sb->len - offset);
567572
if (!eol)
568573
return sb->len;
569574
return eol - sb->buf + 1;

0 commit comments

Comments
 (0)