Subject: Re: [bug-diffutils] bug#77840: Testing diffutils 3.12 on PPC Mac OS X 10.4.11, Tiger, produces so many failures

From: Peter Dyballa <[email-masked]>
Date: Mon, 16 Jun 2025 13:30:01 +0200

> Am 13.06.2025 um 00:14 schrieb Paul Eggert <[email-masked]>:
> 
> On 2025-06-12 03:29, Peter Dyballa wrote:
>> 	(gdb) p base
>> 	$2 = 0x0
> 
> That's obviously wrong; 'base' should not be a null pointer. Can you track down why it is a null pointer?

Hello Paul!

The case becomes mysterious.

Here is a comparison between PPC Mac OS X and x86_64 macOS, using (quite) the same .gdbinit file with diff arguments and breakpoints (the only difference is that of the files to diff is differently named, *-312 vs. *-P312, to be able to simply differentiate between saved logs):

PPC Mac OS X 10.4.11, Tiger, GNU gdb 6.3.50-20050815 (Apple version gdb-696), 2007| x86_64 macOS High Sierra, Version 10.13.6, GNU gdb (GDB) 14.2
––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––
--- Portfile-graphite2-312	2025-06-09 15:48:08.000000000 +0200		  | --- Portfile-graphite2-P312	2025-06-11 09:54:04.000000000 +0200
+++ Portfile-graphite2	2025-06-09 15:48:08.000000000 +0200			  | +++ Portfile-graphite2	2025-06-13 10:27:53.000000000 +0200
@@ -27,14 +18,23 @@								  | @@ -31,7 +31,7 @@
										  | 
Breakpoint 1, pr_unidiff_hunk (hunk=0x4014d0) at context.c:369			  | Thread 3 hit Breakpoint 1, pr_unidiff_hunk (hunk=0x1003001a0) at context.c:369
(gdb) p last0									  | (gdb) p last0
$1 = 9										  | $1 = 6
(gdb) p last1									  | (gdb) p last1
$2 = 9										  | $2 = 6
(gdb) p i									  | (gdb) p i
$3 = -4										  | $3 = 0
(gdb) p j									  | (gdb) p j
$4 = -13									  | $4 = 0
(gdb) n										  | (gdb) n
(gdb) p next->line0								  | (gdb) p next->line0
$5 = -1										  | $5 = 3
(gdb) n										  | (gdb) n
(gdb) n										  | (gdb) n
(gdb) n										  | (gdb) n
(gdb) n										  | (gdb) n
										  | 
Breakpoint 4, pr_unidiff_hunk (hunk=0x4014d0) at context.c:379			  | Thread 3 hit Breakpoint 4, pr_unidiff_hunk (hunk=0x1003001a0) at context.c:379
(gdb) step									  | (gdb) step
print_1_line (line_flag=0x0, line=0x40137c) at util.c:989			  | print_1_line (line_flag=0x0, line=0x100300418) at util.c:989
(gdb) step									  | (gdb) step
print_1_line_nl (line_flag=0x0, line=0x40137c, skip_nl=false) at util.c:1001	  | print_1_line_nl (line_flag=0x0, line=0x100300418, skip_nl=false) at util.c:1001
(gdb) n										  | (gdb) n
(gdb) n										  | (gdb) n
(gdb) n										  | (gdb) n
(gdb) p base									  | (gdb) p base
$6 = 0x0									  | $6 = 0x101001630 "compiler.cxx_standard \\\n", ' ' <repeats 20 times>, "2011\n\nset py_ver          3.12\nset py_ver_nodot    [string map {. {}} ${py_ver}]\n\ntest.run", ' ' <repeats 12 times>, "yes\n#test.env", ' ' <repeats 12 times>, "ARGS=-V\n# Use the same python"...
										  | (gdb) p limit
										  | $7 = 0x101001648 ' ' <repeats 20 times>, "2011\n\nset py_ver          3.12\nset py_ver_nodot    [string map {. {}} ${py_ver}]\n\ntest.run", ' ' <repeats 12 times>, "yes\n#test.env", ' ' <repeats 12 times>, "ARGS=-V\n# Use the same python as fonttools.\nconfigure"...
										  | (gdb) n
										  | (gdb) step
										  | output_1_line (
										  |     base=0x101001630 "compiler.cxx_standard \\\n", ' ' <repeats 20 times>, "2011\n\nset py_ver          3.12\nset py_ver_nodot    [string map {. {}} ${py_ver}]\n\ntest.run", ' ' <repeats 12 times>, "yes\n#test.env", ' ' <repeats 12 times>, "ARGS=-V\n# Use the same python"..., 
										  |     limit=0x101001648 ' ' <repeats 20 times>, "2011\n\nset py_ver          3.12\nset py_ver_nodot    [string map {. {}} ${py_ver}]\n\ntest.run", ' ' <repeats 12 times>, "yes\n#test.env", ' ' <repeats 12 times>, "ARGS=-V\n# Use the same python as fonttools.\nconfigure"..., flag_format=0x0, line_flag=0x0) at util.c:1047

First difference: diff 3.12 finds different line numbers on both systems.

Second and important difference: On Mac OS X "base" is the null pointer, because in print_1_line_nl() the statement

	  char const *base = line[0], *limit = line[1]; /* Help the compiler.  */

assigns the null pointer to "base". And that's the actual cause for fwrite'ing into the wrong STREAM…

The struct line does exist, and line[1] contains a text to diff/compare, but line[0] is empty, is the null pointer, but should contain a chunk of annotated text from the first file:

	(gdb) p line
	$7 = (const char * const *) 0x40137c
	(gdb) p *line
	$8 = 0x0
	(gdb) p line[0]
	$9 = 0x0
	(gdb) p line[1]
	$10 = 0x18015ef "distname", ' ' <repeats 12 times>, "${name}-${version}\nextract.suffix      .tgz\n\ncompiler.cxx_standard \\\n", ' ' <repeats 20 times>, "2011\n\nset py_ver          3.12\nset py_ver_nodot    [string map {. {}} ${py_ver}]\n\ntest.run "...
	(gdb) p limit
	$11 = 0x18015ef "distname", ' ' <repeats 12 times>, "${name}-${version}\nextract.suffix      .tgz\n\ncompiler.cxx_standard \\\n", ' ' <repeats 20 times>, "2011\n\nset py_ver          3.12\nset py_ver_nodot    [string map {. {}} ${py_ver}]\n\ntest.run "...
	(gdb) p line[2]
	$12 = 0x1801616 "extract.suffix      .tgz\n\ncompiler.cxx_standard \\\n", ' ' <repeats 20 times>, "2011\n\nset py_ver          3.12\nset py_ver_nodot    [string map {. {}} ${py_ver}]\n\ntest.run", ' ' <repeats 12 times>, "yes\n#test.env", ' ' <repeats 12 times>, "ARG"...

The text string "3.12" indicates that the text chunks come from the first file, Portfile-graphite2-312 or Portfile-graphite2-P312 (Portfile-graphite2 contains "3.13" instead). So the failure on Tiger seems to happen when some prepared (?) text chunk is saved into the line array of annotated text chunks. Then the index to save at is wrong by the value of 1… From incrementing or decrementing line?

BTW, checking the files to diff the two file sets on the macOS system gives:

	pete 142 /\  l Portfile-graphite2*
	-rw-r--r--  1 pete  admin  1412 13 Jun 10:27 Portfile-graphite2
	-rw-r--r--  1 pete  admin  1412 16 Jun 12:22 Portfile-graphite2-312@Tiger
	-rw-r--r--  1 pete  admin  1412 11 Jun 09:54 Portfile-graphite2-P312
	-rw-r--r--  1 pete  admin  1412 16 Jun 12:22 Portfile-graphite2@Tiger
	pete 143 /\  which diff
	/usr/bin/diff
	pete 144 /\  diff --version
	diff (GNU diffutils) 2.8.1
	Copyright (C) 2002 Free Software Foundation, Inc.
	
	This program comes with NO WARRANTY, to the extent permitted by law.
	You may redistribute copies of this program
	under the terms of the GNU General Public License.
	For more information about these matters, see the file named COPYING.
	
	Written by Paul Eggert, Mike Haertel, David Hayes,
	Richard Stallman, and Len Tower.
	pete 145 /\  ./diff --version
	diff (GNU diffutils) 3.12
	Copyright (C) 2025 Free Software Foundation, Inc.
	License GPLv3+: GNU GPL version 3 or later <https://gnu.org/licenses/gpl.html>.
	This is free software: you are free to change and redistribute it.
	There is NO WARRANTY, to the extent permitted by law.
	
	Written by Paul Eggert, Mike Haertel, David Hayes,
	Richard Stallman, and Len Tower.
	pete 147 /\  ./diff Portfile-graphite2 Portfile-graphite2@Tiger
	pete 148 /\  diff Portfile-graphite2 Portfile-graphite2@Tiger
	pete 149 /\  diff -u Portfile-graphite2 Portfile-graphite2@Tiger
	pete 150 /\  ./diff -u Portfile-graphite2 Portfile-graphite2@Tiger
	pete 151 /\  ./diff -u Portfile-graphite2-P312  Portfile-graphite2-312@Tiger
	pete 152 /\  diff -u Portfile-graphite2-P312 Portfile-graphite2-312@Tiger
	pete 153 /\  diff Portfile-graphite2-P312 Portfile-graphite2-312@Tiger
	pete 154 /\  ./diff Portfile-graphite2-P312 Portfile-graphite2-312@Tiger

So they are equal, with the same contents, on both Macs.

--
Greetings

  Pete

A morning without coffee is like something without something else.