Permalink
Browse files

Ah, check last_printed_match in the second if-statement as well. The …

…first if can increment last_printed_match. Sneaky.
  • Loading branch information...
1 parent e07b1a6 commit 7453e9c169be82c9b6090028627180ad21db69be @ggreer committed Nov 29, 2012
Showing with 10 additions and 12 deletions.
  1. +10 −12 src/print.c
View
@@ -142,20 +142,18 @@ void print_file_matches(const char* path, const char* buf, const int buf_len, co
fprintf(out_fd, "%s", opts.color_match);
}
for (j = prev_line_offset; j <= i; j++) {
- if (last_printed_match < matches_len) {
- if (j == matches[last_printed_match].end) {
- if (opts.color) {
- fprintf(out_fd, "%s", color_reset);
- }
- printing_a_match = FALSE;
- last_printed_match++;
+ if (j == matches[last_printed_match].end && last_printed_match < matches_len) {
+ if (opts.color) {
+ fprintf(out_fd, "%s", color_reset);
}
- if (j == matches[last_printed_match].start) {
- if (opts.color) {
- fprintf(out_fd, "%s", opts.color_match);
- }
- printing_a_match = TRUE;
+ printing_a_match = FALSE;
+ last_printed_match++;
+ }
+ if (j == matches[last_printed_match].start && last_printed_match < matches_len) {
+ if (opts.color) {
+ fprintf(out_fd, "%s", opts.color_match);
}
+ printing_a_match = TRUE;
}
fputc(buf[j], out_fd);
}

0 comments on commit 7453e9c

Please sign in to comment.