From 3aabbb6dc5343d4f8cd61a4f83c8eeba14aaef8b Mon Sep 17 00:00:00 2001 From: Bruce Hill Date: Sun, 7 Nov 2021 12:27:42 -0800 Subject: [PATCH] Fix to ensure proper line numbering --- bp.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/bp.c b/bp.c index e094a7a..2e7591f 100644 --- a/bp.c +++ b/bp.c @@ -287,7 +287,7 @@ static file_t *printing_file = NULL; static int last_line_num = -1; static void _fprint_between(FILE *out, const char *start, const char *end, const char *normal_color) { - while (start < end) { + do { // Cheeky lookbehind to see if line number should be printed if (start == printing_file->start || start[-1] == '\n') { int linenum = (int)get_line_number(printing_file, start); @@ -301,10 +301,10 @@ static void _fprint_between(FILE *out, const char *start, const char *end, const fwrite(start, sizeof(char), (size_t)(line_end - start + 1), out); start = line_end + 1; } else { - fwrite(start, sizeof(char), (size_t)(end - start), out); + if (end > start) fwrite(start, sizeof(char), (size_t)(end - start), out); break; } - } + } while (start < end); } static void fprint_context(FILE *out, file_t *f, const char *prev, const char *next)