Thanks for the bug report and test case. This is due to a "sizeof sizeof" typo I introduced in diff 3.9; sorry about that. I installed the attached to fix things and add a regression test.
From ba08fbbb0ca5da455bf695236c57bc50e7faed50 Mon Sep 17 00:00:00 2001
From: Paul Eggert <egg...@cs.ucla.edu>
Date: Fri, 10 Feb 2023 15:33:40 -0800
Subject: [PATCH] diff: fix bug where -D does not work
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Problem reported by Robert Webb (bug#61193).
* NEWS: Mention this.
* src/diff.c (main): Omit stray ‘sizeof’.
* tests/ifdef: New test.
* tests/Makefile.am (TESTS): Add it.
---
 NEWS              |  5 +++++
 src/diff.c        |  2 +-
 tests/Makefile.am |  1 +
 tests/ifdef       | 37 +++++++++++++++++++++++++++++++++++++
 4 files changed, 44 insertions(+), 1 deletion(-)
 create mode 100755 tests/ifdef

diff --git a/NEWS b/NEWS
index ad9c6cc..f146730 100644
--- a/NEWS
+++ b/NEWS
@@ -2,6 +2,11 @@ GNU diffutils NEWS                                    -*- outline -*-
 
 * Noteworthy changes in release ?.? (????-??-??) [?]
 
+** Bug fixes
+
+  diff -D no longer fails to output #ifndef lines.
+  [bug#61193 introduced in 3.9]
+
 
 * Noteworthy changes in release 3.9 (2023-01-15) [stable]
 
diff --git a/src/diff.c b/src/diff.c
index dd6f63b..2b4834f 100644
--- a/src/diff.c
+++ b/src/diff.c
@@ -416,7 +416,7 @@ main (int argc, char **argv)
 	    char *base = b;
 	    int changes = 0;
 
-	    for (i = 0; i < sizeof sizeof C_ifdef_group_formats; i++)
+	    for (i = 0; i < sizeof C_ifdef_group_formats; i++)
 	      {
 		char ch = C_ifdef_group_formats[i];
 		switch (ch)
diff --git a/tests/Makefile.am b/tests/Makefile.am
index d98df82..624192d 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -10,6 +10,7 @@ TESTS = \
   diff3 \
   excess-slash \
   help-version	\
+  ifdef \
   invalid-re	\
   function-line-vs-leading-space \
   ignore-matching-lines \
diff --git a/tests/ifdef b/tests/ifdef
new file mode 100755
index 0000000..d3b05dd
--- /dev/null
+++ b/tests/ifdef
@@ -0,0 +1,37 @@
+#!/bin/sh
+# --ifdef
+
+# Bug reported by Robert Webb in <http://bugs.gnu.org/61193>.
+
+. "${srcdir=.}/init.sh"; path_prepend_ ../src
+
+fail=0
+
+cat <<'EOF' >a
+1
+2
+3
+4
+5
+EOF
+
+cat <<'EOF' >b
+1
+4
+5
+EOF
+
+cat <<'EOF' >exp
+1
+#ifndef ZZZ
+2
+3
+#endif /* ! ZZZ */
+4
+5
+EOF
+
+returns_ 1 diff -D ZZZ a b >out 2>err || fail=1
+compare exp out || fail=1
+
+Exit $fail
-- 
2.39.1

Reply via email to