Skip to content

Commit bc36540

Browse files
committed
Merge branch 'bc/xdiffnl'
* bc/xdiffnl: xdiff-interface.c: strip newline (and cr) from line before pattern matching
2 parents ed187bd + a5a5a04 commit bc36540

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

xdiff-interface.c

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,12 +191,22 @@ struct ff_regs {
191191
static long ff_regexp(const char *line, long len,
192192
char *buffer, long buffer_size, void *priv)
193193
{
194-
char *line_buffer = xstrndup(line, len); /* make NUL terminated */
194+
char *line_buffer;
195195
struct ff_regs *regs = priv;
196196
regmatch_t pmatch[2];
197197
int i;
198198
int result = -1;
199199

200+
/* Exclude terminating newline (and cr) from matching */
201+
if (len > 0 && line[len-1] == '\n') {
202+
if (len > 1 && line[len-2] == '\r')
203+
len -= 2;
204+
else
205+
len--;
206+
}
207+
208+
line_buffer = xstrndup(line, len); /* make NUL terminated */
209+
200210
for (i = 0; i < regs->nr; i++) {
201211
struct ff_reg *reg = regs->array + i;
202212
if (!regexec(&reg->re, line_buffer, 2, pmatch, 0)) {

0 commit comments

Comments
 (0)