From a5aa18b93b99b49ca1a46bdb36bd0ab83d305052 Mon Sep 17 00:00:00 2001 From: Sultan Alsawaf Date: Wed, 17 Sep 2025 09:35:26 -0700 Subject: [PATCH 1/4] Remove extra code block from trim_context() --- src/interdiff.c | 26 ++++++++++++-------------- 1 file changed, 12 insertions(+), 14 deletions(-) diff --git a/src/interdiff.c b/src/interdiff.c index f3f474b0..7906047c 100644 --- a/src/interdiff.c +++ b/src/interdiff.c @@ -1099,20 +1099,18 @@ trim_context (FILE *f /* positioned at start of @@ line */, printf ("Trim: %lu,%lu\n", strip_pre, strip_post); fsetpos (f, &pos); - { - if (new_orig_count != 1 && new_new_count != 1) { - print_color (out, LINE_HUNK, "@@ -%lu,%lu +%lu,%lu @@\n", - orig_offset, new_orig_count, new_offset, new_new_count); - } else if (new_orig_count != 1) { - print_color (out, LINE_HUNK, "@@ -%lu,%lu +%lu @@\n", - orig_offset, new_orig_count, new_offset); - } else if (new_new_count != 1) { - print_color (out, LINE_HUNK, "@@ -%lu +%lu,%lu @@\n", - orig_offset, new_offset, new_new_count); - } else { - print_color (out, LINE_HUNK, "@@ -%lu +%lu @@\n", - orig_offset, new_offset); - } + if (new_orig_count != 1 && new_new_count != 1) { + print_color (out, LINE_HUNK, "@@ -%lu,%lu +%lu,%lu @@\n", + orig_offset, new_orig_count, new_offset, new_new_count); + } else if (new_orig_count != 1) { + print_color (out, LINE_HUNK, "@@ -%lu,%lu +%lu @@\n", + orig_offset, new_orig_count, new_offset); + } else if (new_new_count != 1) { + print_color (out, LINE_HUNK, "@@ -%lu +%lu,%lu @@\n", + orig_offset, new_offset, new_new_count); + } else { + print_color (out, LINE_HUNK, "@@ -%lu +%lu @@\n", + orig_offset, new_offset); } while (total_count--) { From 047f5522a9e94a5aa41dfb9c5340fe783aa4055b Mon Sep 17 00:00:00 2001 From: Sultan Alsawaf Date: Wed, 17 Sep 2025 09:35:51 -0700 Subject: [PATCH 2/4] Remove unneeded curly braces from if-statement chain in trim_context() --- src/interdiff.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/interdiff.c b/src/interdiff.c index 7906047c..79781071 100644 --- a/src/interdiff.c +++ b/src/interdiff.c @@ -1099,19 +1099,18 @@ trim_context (FILE *f /* positioned at start of @@ line */, printf ("Trim: %lu,%lu\n", strip_pre, strip_post); fsetpos (f, &pos); - if (new_orig_count != 1 && new_new_count != 1) { + if (new_orig_count != 1 && new_new_count != 1) print_color (out, LINE_HUNK, "@@ -%lu,%lu +%lu,%lu @@\n", orig_offset, new_orig_count, new_offset, new_new_count); - } else if (new_orig_count != 1) { + else if (new_orig_count != 1) print_color (out, LINE_HUNK, "@@ -%lu,%lu +%lu @@\n", orig_offset, new_orig_count, new_offset); - } else if (new_new_count != 1) { + else if (new_new_count != 1) print_color (out, LINE_HUNK, "@@ -%lu +%lu,%lu @@\n", orig_offset, new_offset, new_new_count); - } else { + else print_color (out, LINE_HUNK, "@@ -%lu +%lu @@\n", orig_offset, new_offset); - } while (total_count--) { enum line_type type; From ef722ee48124bcec0e51d8cbe5835a397df4b1ce Mon Sep 17 00:00:00 2001 From: Sultan Alsawaf Date: Wed, 17 Sep 2025 09:37:28 -0700 Subject: [PATCH 3/4] Remove stray leading spaces in print_color() definition --- src/interdiff.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/interdiff.c b/src/interdiff.c index 79781071..8ebe2c64 100644 --- a/src/interdiff.c +++ b/src/interdiff.c @@ -132,9 +132,9 @@ static struct file_list *files_in_patch1 = NULL; /* * Print colored output using a variadic format string. */ - static void - print_color (FILE *output_file, enum line_type type, const char *format, ...) - { +static void +print_color (FILE *output_file, enum line_type type, const char *format, ...) +{ const char *color_start = NULL; va_list args; @@ -154,7 +154,7 @@ static struct file_list *files_in_patch1 = NULL; /* Print color end code */ if (color_start) fputs ("\033[0m", output_file); - } +} /* checks whether file needs processing and sets context */ static int From 5c3dd467cc559fe11711137961dd9471f66b14ca Mon Sep 17 00:00:00 2001 From: Sultan Alsawaf Date: Wed, 17 Sep 2025 09:50:33 -0700 Subject: [PATCH 4/4] Add printf format attribute to print_color() So that the compiler can check the format specifier types and emit -Wformat warnings for print_color(). --- src/interdiff.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/interdiff.c b/src/interdiff.c index 8ebe2c64..d1cc9e25 100644 --- a/src/interdiff.c +++ b/src/interdiff.c @@ -132,7 +132,7 @@ static struct file_list *files_in_patch1 = NULL; /* * Print colored output using a variadic format string. */ -static void +static void __attribute__((__format__(printf, 3, 4))) print_color (FILE *output_file, enum line_type type, const char *format, ...) { const char *color_start = NULL;