1486 Commits

Author SHA1 Message Date
Paul Eggert
71430dd736 maint: prefer ‘*const’ to ‘* const’
Prefer declarations like ‘char *const *x;’ to ‘char * const *x;’,
for consistency between ‘*const’ and ‘*x’, and to highlight the
fact that the ‘const’ belongs to the preceding ‘*’ not to the
following ‘*’.

Similarly for ‘* volatile’.
2023-05-30 14:49:35 -07:00
Paul Eggert
61c1fffe7b scripts: sync git-hooks from coreutils 2023-05-30 14:49:35 -07:00
Paul Eggert
fc62345ebc maint: calculate log base 2 more efficiently
* bootstrap.conf (gnulib_modules): Add count-leading-zeros.
* src/analyze.c (discard_confusing_lines, diff_2_files):
* src/io.c (read_files):
Prefer floor_log2 to doing it by hand.
* src/cmp.c, src/diff.c, src/diff3.c, src/sdiff.c:
Define SYSTEM_INLINE, for system.h.
* src/system.h: Include count-leading-zeros.h.
(SYSTEM_INLINE): New macro.
(LIN_MAX): Verify that it does not exceed IDX_MAX, so that
floor_log2 is safe to use for lin values too.
(floor_log2): New inline function.
2023-05-30 14:49:35 -07:00
Paul Eggert
f54e901c32 maint: use xpalloc
* bootstrap.conf (gnulib_modules): Add ialloc, to document
the now-direct dependency.
* src/diff.c (add_regexp):
* src/diff3.c (read_diff):
* src/dir.c (dir_read):
* src/io.c (slurp, find_and_hash_each_line, find_identical_ends):
* src/sdiff.c (diffarg):
Prefer xpalloc to doing it by hand.
* src/io.c: Include ialloc.h, for irealloc.
(equivs_alloc): Now idx_t, not lin, for xpalloc.
(sip): Don’t bother subtracting 2 * sizeof (word) from the
buffer_lcm upper bound, as later code works anyway now.
(slurp): Simplify buffer allocation so that xpalloc can be used.
Use irealloc for speculative reallocation, since the code could
work anyway if the irealloc fails.  Use current->eof to check
for EOF, rather than the less-intuitive buffer size checks.
2023-05-30 14:49:35 -07:00
Paul Eggert
82298afa03 maint: prefer signed sizes for allocation
* src/analyze.c (discard_confusing_lines, diff_2_files):
* src/cmp.c (main):
* src/diff.c (main, add_regexp):
* src/diff3.c (read_diff):
* src/dir.c (dir_read):
* src/io.c (slurp, find_and_hash_each_line, find_identical_ends):
* src/sdiff.c (lf_init, diffarg): Prefer ximalloc to xmalloc, etc.
Also prefer letting the xmalloc.c functions multiply (with
overflow checking) than doing it by hand (without).
2023-05-30 14:49:35 -07:00
Paul Eggert
b733c02072 diff: prefer signed types in util.c
* src/util.c (struct msg, message, struct bin_str)
(get_funky_string, c_escape, lines_differ, output_1_line)
(analyze_hunk):
Prefer signed types to size_t.
2023-05-30 14:49:35 -07:00
Paul Eggert
a693d81b03 sdiff: prefer signed types
* src/sdiff.c (ck_fread, ck_fwrite, expand_name, lf_refill)
(lf_snarf, diffarg, edit):
Prefer idx_t to size_t.
2023-05-30 14:49:35 -07:00
Paul Eggert
15fda47d8f diff: prefer signed types in io.c
* src/io.c (struct equivclass, nbuckets)
(find_and_hash_each_line, guess_lines, read_files):
Prefer idx_t to size_t.
2023-05-30 14:49:35 -07:00
Paul Eggert
225f1db8e1 diff: prefer signed types in ifdef.c
* src/ifdef.c (do_printf_spec):
Prefer idx_t to size_t.
2023-05-30 14:49:35 -07:00
Paul Eggert
6f879e4f12 diff: prefer signed types in dir.c
* src/dir.c (struct dirdata, dir_read):
Prefer idx_t to size_t.
2023-05-30 14:49:35 -07:00
Paul Eggert
a7eb06a39d diff: prefer signed types in diff.c
* src/diff.c (struct regexp_list, option_list, main, add_regexp):
Prefer idx_t to size_t.
2023-05-30 14:49:35 -07:00
Paul Eggert
48c1b55813 diff3: prefer signed types
* src/diff3.c (struct diff_block, struct diff3_block)
(copy_stringlist, create_diff3_block, compare_line_list)
(read_diff, scan_diff_line, output_diff3, process_diff):
Prefer idx_t to size_t.
2023-05-30 14:49:35 -07:00
Paul Eggert
3357879cba maint: use safer type for ‘word’
* src/system.h (word): Change it from size_t to void *,
so that uses aren’t tempted to treat it as an integer.
2023-05-30 14:49:35 -07:00
Paul Eggert
e752ad65be diff: prefer signed types in diff.h
* src/diff.h (struct file_data):
Prefer idx_t to size_t.  All uses changed.
2023-05-30 14:49:35 -07:00
Paul Eggert
e9e15097ff diff: prefer signed types in context.c
* src/context.c (find_function):
Prefer idx_t to size_t.
2023-05-30 14:49:35 -07:00
Paul Eggert
7d69341d91 cmp: prefer signed types
* src/cmp.c (buf_size, words_per_buffer, cmp, count_newlines):
Prefer idx_t to size_t.
2023-05-30 14:49:35 -07:00
Paul Eggert
1e20578506 diff: prefer signed types in analyze.c
* src/analyze.c (discard_confusing_lines, diff_2_files):
Prefer signed types to size_t.
2023-05-30 14:49:35 -07:00
Paul Eggert
917e4d34e0 diff: use intmax_t for column widths
Don’t represent column widths and tab stops as size_t, since they
are not object sizes.  Instead, use intmax_t.  This is better than
uintmax_t since gcc -fsanitize=undefined can catch overflows.
* src/diff.c (main):
* src/diff.h (tabsize, sdiff_half_width, sdiff_column2_offset):
* src/io.c (find_and_hash_each_line):
* src/side.c (tab_from_to, print_half_line, print_1sdiff_line):
* src/util.c (lines_differ, output_1_line):
Use intmax_t for column numbers, not size_t.
* src/io.c (find_and_hash_each_line): Count only columns since the
last tab stop, to avoid signed integer overflow.  (The old code
had this possibility on odd but valid platforms where SIZE_MAX <=
INT_MAX.)
* src/util.c (lines_differ, output_1_line): Use a separate counter
for tab stops, so that the column count counts only columns since
the last tab stop.  This avoids integer overflow when tabsize is
large.  (The old code mishandled this situation.)
2023-05-30 14:49:35 -07:00
Paul Eggert
1b9883fe56 maint: update cmpbuf.c comment
Update comment to refer to FreeBSD 13, which is current,
instead of to Tru64 which is not.
2023-05-30 14:49:34 -07:00
Paul Eggert
2a354e0699 maint: check for unlikely st_blksize overflow
Prefer idx_t to size_t in lib/cmpbuf.c and related buffer-size code.
Because POSIX says blksize_t can be wider than idx_t,
check for overflow when copying the former to the latter.
* bootstrap.conf (gnulib_modules): Add idx.
* lib/cmpbuf.c (block_read, buffer_lcm):
Prefer idx_t to size_t.  All uses changed.
* lib/cmpbuf.c (block_read): Return ptrdiff_t instead of size_t.
All uses changed.
(buffer_lcm): Help the compiler by checking for negative args,
even though they are not allowed.
* lib/cmpbuf.h: Include idx.h and stddef.h, for idx_t and ptrdiff_t,
so that this include file is self-contained.
* src/analyze.c (diff_2_files):
* src/cmp.c (main):
* src/diff.c, src/io.c: Do not include stdckdint.h here,
since system.h now does that.
* src/diff3.c (read_diff):
* src/io.c (sip):
Protect against negative STAT_BLOCKSIZE, or STAT_BLOCKSIZE
outside idx_t range.
* src/system.h: Include stdckdint.h, idx.h.
2023-05-30 14:49:34 -07:00
Paul Eggert
9c3bc5255f build: update gnulib submodule to latest 2023-05-24 13:07:34 -07:00
Paul Eggert
6ee3cf3e0b maint: C99 for cmpbuf.c
* lib/cmpbuf.c (buffer_lcm):
Put decls closer to uses.
2023-05-22 11:39:24 -07:00
Paul Eggert
8918d10b0d diff: C99 style for util.c
* src/util.c (get_funky_string, parse_diff_color, begin_output)
(finish_output, lines_differ, print_script, output_1_line)
(analyze_hunk):
Put decls closer to uses.
2023-05-22 11:39:24 -07:00
Paul Eggert
9eae15709a diff: C99 style for side.c
* src/side.c (tab_from_to, print_sdiff_hunk):
Put decls closer to uses.
2023-05-22 11:39:24 -07:00
Paul Eggert
b65d1622e2 diff: C99 style for sdiff.c
* src/sdiff.c (usage, main, trapsigs, untrapsig, flush_line)
(edit, interact):
Put decls closer to uses.
2023-05-22 11:39:24 -07:00
Paul Eggert
5b6b5d9361 diff: C99 style for normal.c
* src/normal.c (print_normal_hunk):
Put decls closer to uses.
2023-05-22 11:39:24 -07:00
Paul Eggert
835063ee2a diff: C99 style for io.c
* src/io.c (sip, slurp, find_and_hash_each_line)
(find_identical_ends, read_files):
Put decls closer to uses.
2023-05-22 11:39:23 -07:00
Paul Eggert
6ae4f12df0 diff: C99 decl style in ifdef.c
* src/ifdef.c (format_ifdef, format_group, print_ifdef_lines)
(do_printf_spec, scan_char_literal):
Put decls closer to uses.
2023-05-22 11:39:23 -07:00
Paul Eggert
7f7054dd5e diff: C99 decl style in ed.c
* src/ed.c (print_ed_hunk, pr_forward_ed_hunk, print_rcs_hunk):
Put decls closer to uses.
2023-05-22 11:39:23 -07:00
Paul Eggert
15f09cb45e diff: C99 decl style in dir.c
* src/dir.c (dir_read, diff_dirs, find_dir_file_pathname):
Put decls closer to uses.
2023-05-22 11:39:23 -07:00
Paul Eggert
e8c2d02643 diff: C99 decl style in diff.c
* src/diff.c (option_list, main, usage, compare_files):
Put decls closer to uses.
2023-05-22 11:39:23 -07:00
Paul Eggert
2bb977b7d9 diff3: C99 decl style
* src/diff3.c (main, usage, make_3way_diff)
(using_to_diff3_block, create_diff3_block, process_diff)
(process_diff_control, read_diff, output_diff3, dotlines)
(output_diff3_edscript, output_diff3_merge)
(reverse_diff3_blocklist):
Put decls closer to uses.
2023-05-22 11:39:23 -07:00
Paul Eggert
da1697dcb6 diff: C99 decl style in context.c
* src/context.c (print_context_script, pr_context_hunk)
(pr_unidiff_hunk, mark_ignorable):
Put decls closer to uses.
2023-05-22 11:39:23 -07:00
Paul Eggert
35b74c5708 cmp: C99 decl style in cmp.c
* src/cmp.c (usage, main, cmp, count_newlines):
Put decls closer to uses.
2023-05-22 11:39:23 -07:00
Paul Eggert
56dd675c35 diff: C99 decl style in analyze.c
* src/analyze.c (discard_confusing_lines, shift_boundaries)
(diff_2_files): Assume C99 decls after statements.
2023-05-22 11:39:23 -07:00
Paul Eggert
d136413d1c sdiff: remove an IF_LINT
* src/sdiff.c (edit): Remove an IF_LINT, which no longer seems
to be needed with current GCC.
2023-05-22 11:39:23 -07:00
Paul Eggert
9df7292724 sdiff: prefer functions to macros
* src/sdiff.c (sighandler): New type.
(signal_handler) [!HAVE_SIGACTION]:
(initial_handler): Now static functions, not macros.
2023-05-22 11:39:23 -07:00
Paul Eggert
efec6cce91 diff: prefer functions in io.c
* src/io.c (HASH_VALUE_WIDTH): New constant.
(rol, hash): New static functions, replacing ...
(ROL, HASH): ... these macros.  All uses changed.
2023-05-22 11:39:23 -07:00
Paul Eggert
844c45fd72 diff: prefer function to DIR_P macro
* src/diff.c (dir_p): New static function, replacing ...
(DIR_P): ... this macro.  All uses changed.
2023-05-22 11:39:23 -07:00
Jim Meyering
f265160c26 maint: prefer ckd_add, ckd_mul to INT_ADD_WRAPV, INT_MULTIPLY_WRAPV
* bootstrap.conf (gnulib_modules): Add stdckdint.
* lib/cmpbuf.c: Use ckd_mul rather than INT_MULTIPLY_WRAPV.
Include stdckdint.h, not "intprops.h".
* src/diff.c: Similar, but for both ckd_add and ckd_mul.
* src/io.c: Likewise for ckd_add.
2023-05-21 12:14:48 -07:00
Jim Meyering
12747f3138 maint: post-release administrivia
* NEWS: Add header line for next release.
* .prev-version: Record previous version.
* cfg.mk (old_NEWS_hash): Auto-update.
2023-05-21 01:53:43 -07:00
Jim Meyering
b1a657b85a version 3.10
* NEWS: Record release date.
v3.10
2023-05-21 01:50:39 -07:00
Jim Meyering
7abd180200 build: skip the sole perl-requiring test when there is no usable perl
* tests/init.cfg (require_perl_): New function, from coreutils.
* tests/large-subopt: Use it.
Reported by Bruno Haible in
https://lists.gnu.org/r/diffutils-devel/2023-05/msg00003.html
2023-05-21 00:56:38 -07:00
Jim Meyering
b079f08cc9 build: fix a new syntax-check failure
* src/diff.h (robust_output_style): Put DIFF_INLINE and
the function name on the same line, so that syntax-check's
naive parsing can spot this function.
* cfg.mk (_gl_TS_extern): Add DIFF_INLINE.
2023-05-20 02:43:07 -07:00
Jim Meyering
55260678d9 build: modernize bootstrap prerequsite tools
Following Pádraig Brady's example from coreutils, ...
* bootstrap.conf: Add an explicit requirement on m4.
Add an explicit requirement on texi2pdf which is often packaged
separately to makeinfo and induces a failure far down the
distribution phase if not present.
Replace the rsync dependency with wget,
which gnulib changed to in 2018.
Also, add an xz requirement and a version for autopoint.
2023-05-20 02:27:03 -07:00
Paul Eggert
11a0695113 build: update gnulib submodule to latest
* src/analyze.c (OFFSET_MAX): New macro, needed for
latest gnulib.
2023-05-19 09:10:12 -07:00
Paul Eggert
11238b27ed diff: avoid a macro in diff.h
* src/diff.h (FILE_BUFFER): Remove.
* src/io.c (file_buffer): New static function.  All uses of
FILE_BUFFER replaced.
2023-05-19 09:10:12 -07:00
Paul Eggert
d3e3696ec7 sdiff: avoid some macros in sdiff.c
* src/sdiff.c (PROGRAM_NAME, SDIFF_BUFSIZE):
Now constants, not macros.
2023-05-19 09:10:12 -07:00
Paul Eggert
9f7c4148b3 diff3: avoid macros in diff3.c
* src/diff3.c (PROGRAM_NAME, FILE0, FILE1, FILE2, FILE3, FO, FC)
(RANGE_START, RANGE_END): Now constants, not macros.
2023-05-19 09:10:12 -07:00
Paul Eggert
36244332b8 cmp: avoid macros in cmp.c
* src/cmp.c (PROGRAM_NAME): Now a constant, not a macro.
(hard_locale_LC_MESSAGES): Now a function, not a macro.
All uses changed.
2023-05-19 09:10:12 -07:00