Subject: bug#61193: closed (Re: [bug-diffutils] bug#61193: '-D' option of diff 3.9 - #ifdef directives missing)

From: [email-masked] (GNU bug Tracking System)
Date: Fri, 10 Feb 2023 23:49:02 +0000

Your bug report

#61193: '-D' option of diff 3.9 - #ifdef directives missing

which was filed against the diffutils package, has been closed.

The explanation is attached below, along with your original report.
If you require more details, please reply to [email-masked].

-- 
61193: https://debbugs.gnu.org/cgi/bugreport.cgi?bug=61193
GNU Bug Tracking System
Contact [email-masked] with problems

Subject: Re: [bug-diffutils] bug#61193: '-D' option of diff 3.9 - #ifdef directives missing
From: Paul Eggert <[email-masked]>
To: Robert Webb <[email-masked]>
Cc: [email-masked]
Date: Fri, 10 Feb 2023 15:47:53 -0800
List-Id: <debbugs-submit.debbugs.gnu.org>

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 <[email-masked]>
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

Subject: '-D' option of diff 3.9 - #ifdef directives missing
From: Robert Webb <[email-masked]>
To: [email-masked]
Date: Mon, 30 Jan 2023 19:02:43 -0800
List-Id: <debbugs-submit.debbugs.gnu.org>

Hi,
The merged output from 'diff -D' (v3.9) is missing the '#ifdef'
directives.  A test script and logs from runs with two versions of diff,
one not working, and the second older one working, follows.

-------------------------------------------------------------------------
#!/bin/sh
# diff_ifdef_example.sh   2023-01-30   rw
#
# The -D option (--ifdef) of 'diff' version 3.9 does not work correctly.
# The '#ifdef' directives are not included in the merged output.

diff -v |grep diff
seq 5 > c
for OPT in '' '-D ZZZ' '-u'  ;do
  printf '\n=== diff %s\n' "$OPT"
  sed 2,3d c  |diff $OPT c -
  done

-------------------------------------------------------------------------
openSUSE Tumbleweed 20230129
diff (GNU diffutils) 3.9

=== diff
2,3d1
< 2
< 3

=== diff -D ZZZ
1
2
3
4
5

=== diff -u
--- c 2023-01-30 16:29:06.165608569 -0800
+++ - 2023-01-30 16:29:06.188398585 -0800
@@ -1,5 +1,3 @@
 1
-2
-3
 4
 5

-------------------------------------------------------------------------
openSUSE Tumbleweed 20220312
diff (GNU diffutils) 3.8

=== diff
2,3d1
< 2
< 3

=== diff -D ZZZ
1
#ifndef ZZZ
2
3
#endif /* ! ZZZ */
4
5

=== diff -u
--- c 2023-01-30 16:32:59.516569839 -0800
+++ - 2023-01-30 16:32:59.529462800 -0800
@@ -1,5 +1,3 @@
 1
-2
-3
 4
 5

-- 
Robert Webb