1486 Commits

Author SHA1 Message Date
Paul Eggert
bdc8608705 diff: tweak mbrtoc32 use
* src/side.c (print_half_line): Use more-intuitive
way to test whether mbrtoc32 found a non-null character.
2023-06-28 15:25:21 -07:00
Paul Eggert
d4a63b11fc diff: fix xpalloc typo
Problem reported by Gisle Vanem (Bug#64316).
* src/dir.c (dir_read): Also set local var cache.
2023-06-27 09:37:04 -07:00
Paul Eggert
9eece02408 maint: pacify "make syntax-check" 2023-06-26 18:58:50 -07:00
Paul Eggert
ef5e8e03a8 cmp: make -bl locale-independent again
* src/cmp.c (sprintc): Use c_isprint, not isprint, fixing a bug I
introduced in 2004.
* tests/cmp: Test for the bug.
2023-06-26 18:51:54 -07:00
Paul Eggert
8ee5d34415 diff: omit c-ctype.h double-include
* src/context.c: Don’t include c-ctype.h,
as system.h does that for us.
2023-06-26 18:51:54 -07:00
Paul Eggert
c780b2f4c6 maint: omit unneeded 0 args to ‘open’
* src/cmp.c (main):
* src/diff.c (compare_files): Omit third arg 0 to ‘open’.
This was never necessary, and I suspect was put in only to pacify
no-longer-relevant compilers.
2023-06-26 11:59:19 -07:00
Paul Eggert
c563537bad diff: avoid ‘if (... = ...)’
* src/diff.c (compare_files):
* src/ifdef.c (format_group, print_ifdef_lines):
* src/io.c (find_and_hash_each_line):
Don’t put assignments into ‘if (...)’, of ‘switch (...)’,
as per GNU coding standards.
2023-06-26 11:59:19 -07:00
Paul Eggert
47cd159b0f cmp: tune 'cmp A B >/dev/null'
* src/cmp.c (main): Also optimize 'cmp A B >/dev/null'
when A and B are regular files with different nonzero sizes.
* tests/cmp: Test this.
2023-06-26 11:59:19 -07:00
Paul Eggert
9c5fcbdc29 cmp: support -n N with huge N
* src/cmp.c (bytes): Use INTMAX_MAX, not -1, for “infinity”.
This simplifies the code and is not a value that can be exhausted
these days.
(main, cmp): Treat very large -n values as “infinity”.
* tests/cmp: Test this.
2023-06-26 11:59:19 -07:00
Paul Eggert
b7d8245828 cmp: avoid syscall when !S_ISCHR (stdout)
* src/cmp.c (main): Avoid a 'stat' call in the common case when
standard output is not a character special device.  This is valid
because /dev/null is a character special device.
2023-06-26 11:59:19 -07:00
Paul Eggert
fbc7fc8074 cmp: improve offset width calculation
* src/cmp.c (cmp): When calculating the offset width,
Don’t attempt to squeeze a file position into an int
as that might trap or yield the wrong answer.
Also, treat “negative” file sizes as zero; this can
happen if the initial file offset is past EOF.
2023-06-25 17:19:46 -07:00
Paul Eggert
b72079f2f9 cmp: work around lseek bugs
* src/cmp.c (ignore_initial): Now an array of intmax_t not off_t.
This allows cmp -i N to work better on platforms where intmax_t
is wider than off_t, N fits in the former and not the latter,
and the input is not a regular file.  All uses changed.
(cmp): Instead of seeking to file end when -i N is huge,
simply pretend that we read zero bytes.  This avoids some
kernel lseek bugs.
2023-06-25 17:19:46 -07:00
Paul Eggert
84d4d49c6b cmp: do not try to read 2**64 - 1 bytes
* src/cmp.c (cmp): Do not store a negative value into
bytes_to_read, as that causes block_read to be passed
SIZE_MAX as the buffer size.
2023-06-25 15:23:17 -07:00
Jim Meyering
2f053f15c0 cmp: avoid new tests/cmp failure
* src/cmp.c (file_position): Set position to EOF by calling lseek
with an offset of 0 and SEEK_END, rather than a SEEK_CURR-relative
offset of the maximum off_t value. The latter would evoke failure on
fedora 38/glibc-2.37/linux 6.2.15-300.fc38.x86_64:
  lseek(3, 9223372036854775807, SEEK_CUR) = -1 EINVAL
The failing test was this (which must now exit 0, but did not):
  echo a>a;echo b>b; src/cmp -i 99999999999999999999 a b
2023-06-25 12:14:51 -07:00
Jim Meyering
ae55e99195 maint: avoid syntax-check failure
* NEWS (Bug fixes): Move the two new items from the section
for already-relesed 3.10 into the section for the next release.
2023-06-24 18:01:29 -07:00
Bruno Haible
93c20ba3c0 build: Ensure that makeinfo ≥ 6.8 checks the @menu structure
See <https://lists.gnu.org/r/bug-texinfo/2023-06/msg00015.html>.

* doc/Makefile.am (MAKEINFO): New variable.
* cfg.mk (_makefile_at_at_check_exceptions): New variable.
2023-06-24 17:52:51 -07:00
Paul Eggert
4ee8300b46 cmp: handle huge -i N with regular files
* NEWS: Document this.
* src/cmp.c (specify_ignore_initial):
If the value exceeds TYPE_MAXIMUM (off_t), set the correspnding
ignore_initial value to -1 instead of reporting an error.
(main, cmp, file_position): All uses changed.  Hence a huge value
will always do the right thing with regular files, which cannot
contain more than TYPE_MAXIMUM (off_t) bytes.  There still may be
EOVERFLOW failures reported for non-regular files, though, as
these can be larger.
* tests/cmp: Test cmp -i N when N cannot fit into 64 bits.
2023-06-24 17:42:01 -07:00
Paul Eggert
584986ad18 cmp: work around Linux tmpfs bug
* lib/cmpbuf.c: Include inttypes.h, for TYPE_MAXIMUM.
(block_read): Work around Linux 6.3.8 tmpfs bug.
2023-06-24 17:42:01 -07:00
Paul Eggert
69ea279bbb cmp: be more robust if lseek fails
* src/cmp.c (main, cmp): If lseek fails,
don’t assume the file position is -1.
2023-06-24 17:42:01 -07:00
Paul Eggert
ff1096a0c2 cmp: fix -s bug when comparing /proc files
* NEWS: Mention this.
* src/cmp.c (main, cmp): Do not trust st_size == 0, as it may
be a /proc file.
* tests/brief-vs-stat-zero-kernel-lies: Also test cmp -s.
2023-06-24 17:42:01 -07:00
Paul Eggert
77722b5c59 doc: mention new SI prefixes
* doc/diffutils.texi (cmp Options): Update for new SI prefixes R and Q.
Simplify the intro to be more like coreutils.
2023-06-20 15:50:20 -07:00
Paul Eggert
d45cee5d38 maint: prefer c_isdigit to ISDIGIT
c_isdigit is a function supplied by Gnulib, which should
be a bit better than our own macro.
* bootstrap.conf (gnulib_modules): Add c-ctype.
* src/system.h (ISDIGIT): Remove.  All calls replaced by c_isdigit.
Include <c-ctype.h>, for c_isdigit.
2023-06-20 15:50:20 -07:00
Paul Eggert
5ce9ac138c maint: omit -Wstack-pointer
* configure.ac (WERROR_CFLAGS): Do not use -Wstack-protector.
It is not a correctness warning, and it causes a false
positive on Ubuntu 23.04 x86-64.
2023-06-20 15:27:35 -07:00
Jim Meyering
0d2ea921b3 build: update gnulib to latest (for maint.mk syntax-check fix) 2023-06-06 22:33:02 -07:00
Jim Meyering
608a613abd maint: avoid new tight-scope syntax-check failure
* src/system.h (floor_log2): Declare with "SYSTEM_INLINE int"
on the same line as the function name, to accommodate the
tight-scope syntax-check rule.
* cfg.mk (_gl_TS_extern): Add SYSTEM_INLINE to the regexp.
2023-06-06 21:49:24 -07:00
Paul Eggert
29f1874aea build: update gnulib submodule to latest 2023-06-06 18:47:12 -07:00
Paul Eggert
ec4a3c07ba maint: update .gitignore
* .gitignore: Add *.rej (for 'patch'), lib/error.c.
2023-06-06 14:35:21 -07:00
Paul Eggert
f7432876c5 maint: sync bootstrap from Gnulib
* bootstrap, tests/init.sh: Copy from Gnulib.
2023-06-06 14:35:21 -07:00
Paul Eggert
a2e301b52c diff: switch from wchar_t to char32_t
Prefer C11-style char32_t to wchar_t, as char32_t works better on
platforms where wchar_t is only 16 bits.
* .gitignore: Add lib/uchar.h.
* bootstrap.conf (gnulib_modules): Add c32width, mbrtoc32.
Remove mbrtowc.  Sort.
* src/side.c: Include uchar.h instead of wchar.h.
(print_half_line): Use c32width and mbrtowc instead of
wcwidth and mbrtowc.
2023-06-06 14:35:21 -07:00
Paul Eggert
c89fd071d5 maint: tell Gnulib diffutils is single-threaded
* configure.ac (GNULIB_EXCLUDE_SINGLE_THREAD)
(GNULIB_MBRTOWC_SINGLE_THREAD, GNULIB_REGEX_SINGLE_THREAD)
(GNULIB_WCHAR_SINGLE_LOCALE):
Define, to improve performance a bit in Gnulib.
Diffutils is single-threaded and sets locales first.
2023-06-06 11:50:34 -07:00
Paul Eggert
418240fccc maint: use similar style for parsing options
This refactors and reindents option-parsing so that the code looks
similar in all three main programs.
* src/cmp.c, src/diff3.c, src/sdiff.c (shortopts): New constant.
(main): Use it.
* src/diff.c (main): Put local inside loop.
2023-06-03 15:50:33 -07:00
Paul Eggert
4c8554b702 maint: go back from ‘die’ to ‘error’
* src/Makefile.am (noinst_HEADERS): Remove die.h.
* src/die.h: Remove.  All uses of ‘die’ replaced with ‘error’,
and all includes of die.h removed.
This reverts commit 2016-10-16T15:43:14Z!meyering@fb.com,
which is no longer needed now that the Gnulib ‘error’
module arranges for static checking to work with ‘error’.
2023-06-03 15:50:33 -07:00
Paul Eggert
9fdc4083f8 diff: bool, not char, for changed vector
* src/diff.h (struct file_data.changed): Now bool instead of char.
This shrinks the size of the code generated on GCC x86-64 by 1.6%.
Formerly this was char because bool’s size is greater than 1
on some platforms, but those platforms are no longer of so
much importance that it’s worth pessimizing on common platforms.
All uses changed.
2023-06-03 15:50:33 -07:00
Paul Eggert
fddb3dbab1 maint: be more specific about 0 and 1
* src/analyze.c (NOTE_DELETE, NOTE_INSERT)
(discard_confusing_lines, shift_boundaries)
(build_reverse_script, build_script, diff_2_files):
* src/cmp.c (specify_comparison_type, option_help_msgid, main):
* src/diff.c (main, option_help_msgid):
* src/diff3.c (main, option_help_msgid, make_3way_diff)
(using_to_diff3_block, create_diff3_block, process_diff):
* src/dir.c (dir_read):
* src/ifdef.c (format_ifdef, format_group, print_ifdef_lines)
(do_printf_spec, scan_char_literal):
* src/io.c (binary_file_p):
* src/sdiff.c (option_help_msgid, lf_snarf, main, trapsigs)
(untrapsig):
* src/util.c (message, setup_output, begin_output)
(finish_output, lines_differ, print_script, print_1_line_nl)
(change_letter, analyze_hunk):
Prefer more-specific constants like true, false and nullptr
to the less-specific 1 and 0.
2023-06-03 15:50:33 -07:00
Paul Eggert
ced621dd21 maint: switch from propername to propername-lite
* bootstrap.conf (gnulib_modules): Replace propername with
propername-lite.
* src/Makefile.am (LDADD): Remove $(LIBICONV).  Sort.
* src/cmp.c, src/diff.c, src/diff3.c, src/sdiff.c (AUTHORS):
Use proper_name_lite and gettext instead of proper_name_utf8 and
proper_name.
2023-06-03 15:50:33 -07:00
Paul Eggert
73b5c504f6 maint: modernize GCC warnings, AC_INIT
* configure.ac: Pass new args to AC_INIT.
(gl_GCC_VERSION_IFELSE): New macro, taken from coreutils.
Modernize GCC warnings to agree more with coreutils.
2023-06-03 15:50:33 -07:00
Paul Eggert
e5e4200fce maint: remove AM_PROG_CC_C_O cruft
* bootstrap.conf (buildreq): Require Automake 1.14 instead of 1.12.2,
since AM_PROG_CC_C_O is obsolete as of 1.14.
* configure.ac: Don’t use obsolescent AM_PROG_CC_C_O.
2023-06-03 15:50:33 -07:00
Paul Eggert
a1a4c58d3d diff: remove CLOSEDIR_VOID cruft
* configure.ac: Don’t use AC_FUNC_CLOSEDIR_VOID; it’s obsolescent.
* src/dir.c (dir_read): Simplify by assuming !CLOSEDIR_VOID.
2023-06-03 15:50:33 -07:00
Paul Eggert
6341b346cd diff: don’t limit contexts arbitrarily
* src/context.c (find_hunk):
Check for overflow when computing non-ignorable threshold.
* src/diff.c (main): Limit ‘context’ to LIN_MAX since it is a lin.
* src/system.h (CONTEXT_MAX): Remove.
2023-06-03 15:50:33 -07:00
Paul Eggert
e8a7dab95c diff: calculate log2 faster in io.c
* src/io.c (find_identical_ends): Use floor_log2 instead
of computing log base 2 by hand.
2023-06-03 15:50:33 -07:00
Paul Eggert
c41d3d921e maint: improve floor_log2 comment
* src/system.h: Document floor_log2 (0).
2023-06-03 15:50:33 -07:00
Paul Eggert
c457027a98 maint: use same-inode
* bootstrap.conf (gnulib_modules): Add same-inode.
* src/system.h: Include <same-inode.h>.
(same_file): Use SAME_INODE instead of reinventing it.
2023-06-03 15:50:33 -07:00
Paul Eggert
8c13859cce maint: test that cmpbuf.h is self-contained
* lib/cmpbuf.c: Include cmpbuf.h before all files but config.h.
2023-06-03 15:50:33 -07:00
Paul Eggert
74bc02c996 maint: rely on Gnulib SSIZE_MAX
* lib/cmpbuf.c (SSIZE_MAX): Remove, as Gnulib now supplies it.
2023-06-03 15:50:33 -07:00
Paul Eggert
741a5659a0 maint: coalesce duplicate MIN, MAX
* bootstrap.conf (gnulib_modules): Add minmax.
* lib/cmpbuf.c, src/system.h: Include minmax.h.
(MIN, MAX): Remove.
2023-06-03 15:50:33 -07:00
Paul Eggert
fa802347c7 maint: depend directly on intprops
* bootstrap.conf (gnulib_modules): Add intprops, since
we are including intprops.h.
2023-06-03 15:50:33 -07:00
Paul Eggert
b56727716d build: update gnulib submodule to latest 2023-06-03 15:50:33 -07:00
Paul Eggert
c2e38d4b22 maint: even safer word type
* src/system.h (word): Change from ‘void *’ to ‘struct incomplete *’
since that’s even less likely to be misused.
2023-05-30 14:59:27 -07:00
Paul Eggert
cb018ecff2 maint: omit ‘register’
The ‘register’ keyword is no longer needed for optimization.
With GCC 13.1 x86-64 compiled with -O2, omitting ‘register’ did not
change the generated code.
2023-05-30 14:49:35 -07:00
Paul Eggert
8587626636 diff: fix unlikely integer overflow
* src/analyze.c (discard_confusing_lines):
Avoid theoretical possibility of integer overflow.
2023-05-30 14:49:35 -07:00