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 <johannes.schindelin@gmx.de>
This commit is contained in:
Johannes Schindelin
2019-10-24 12:12:50 +02:00
parent a0870ab260
commit c59445a882

View File

@@ -562,8 +562,13 @@ mismatched_output:
static size_t find_next_line(struct strbuf *sb, size_t offset)
{
char *eol = memchr(sb->buf + offset, '\n', sb->len - offset);
char *eol;
if (offset >= sb->len)
BUG("looking for next line beyond buffer (%d >= %d)\n%s",
(int)offset, (int)sb->len, sb->buf);
eol = memchr(sb->buf + offset, '\n', sb->len - offset);
if (!eol)
return sb->len;
return eol - sb->buf + 1;