summaryrefslogtreecommitdiff
path: root/src
Commit message (Collapse)AuthorAgeFilesLines
* diff: fix bug where -D does not workPaul Eggert2023-02-101-1/+1
| | | | | | | | 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.
* diff: use C23 boolPaul Eggert2023-02-052-3/+0
| | | | | * bootstrap.conf (gnulib_modules): Add stdbool. * src/die.h, src/system.h: Do not include <stdbool.h>.
* diff: prefer nullptr to NULLPaul Eggert2023-02-058-50/+51
| | | | | | | | | | | | | | | | | * bootstrap.conf (gnulib_modules): Add c-nullptr. * src/cmp.c (main): * src/context.c (pr_context_hunk, pr_unidiff_hunk) (mark_ignorable, find_function): * src/diff.c (longopts, main, specify_value, specify_style) (specify_colors_style, compare_files): * src/diff3.c (main, process_diff): * src/dir.c (find_dir_file_pathname): * src/ifdef.c (scan_char_literal): * src/sdiff.c (main): * src/util.c (process_signals, install_signal_handlers) (color_ext_list, color_indicator, indicator_name) (parse_diff_color): Prefer C23-style nullptr to NULL, as nullptr is a bit better.
* build: add librariesPaul Eggert2023-02-051-2/+7
| | | | | | | * src/Makefile.am (LDADD, sdiff_LDADD): Add Gnulib libraries that in theory would be needed on unusual platforms. In practice, these are typicall empty or are duplicates of other library arguments and so are redundant.
* maint: update copyright datesJim Meyering2023-01-0117-17/+17
|
* build: simplify GCC 12 false alarm workaroundPaul Eggert2022-12-311-16/+7
| | | | | * src/util.c (print_message_queue): Pacify GCC in a more-straightforward way.
* maint: fix assumption typoPaul Eggert2022-12-311-1/+1
| | | | | | Fix a typo I introduced in my August 2021 signal handling fixes. Problem reported by Sam James (Bug#60457). * src/util.c (xsigismember): Don’t assume sigismember cannot return 0.
* build: temp?-disable -Wanalyzer-use-of-uninitialized-valueJim Meyering2022-12-301-1/+9
| | | | | | | | * src/util.c (print_message_queue): This function triggers false positive warnings from GCC12, so add pragmas to ignore that new warning in this one function. Required when using either of these: - gcc version 12.2.1 20221121 - gcc version 13.0.0 20221229 (experimental)
* maint: make update-copyrightJim Meyering2022-01-0317-17/+17
|
* diff: fix timezone bug on SolarisPaul Eggert2021-10-153-1/+11
| | | | | | | | | | | | Problem reported by Vladimir Marek (bug#51228). * NEWS: Mention this. * src/context.c (print_context_label): Pass localtz to nstrftime, instead of always passing 0. * src/diff.c (main) [!HAVE_TM_GMTOFF]: Initialize localtz if time_format uses %z. * src/diff.h (localtz): New decl. * tests/Makefile.am (TESTS): Add timezone. * tests/timezone: New test.
* diff3: port better to MS-WindowsPaul Eggert2021-08-311-23/+23
| | | | | * src/diff3.c (enum diff_type): Prefix constants like ADD with "DIFF_" to avoid collisions with unwise system headers.
* maint: port better to non-POSIXPaul Eggert2021-08-301-4/+24
| | | | | | | Problem privately reported by Gisle Vanem for MS-Windows. * src/util.c (sig, install_signal_handlers): Don’t assume SIGTSTP, SIGALRM, SIGQUIT. (is_tstp_index): New function, for use in SIGTSTP avoidance.
* maint: prefer attribute.h attributesPaul Eggert2021-08-309-42/+28
| | | | | | | | | | Prefer the macros used in attribute.h, and _Noreturn, to the by-hand use of __attribute__, as this is more portable. * bootstrap.conf (gnulib_modules): Add attribute. * src/system.h: Include attribute.h. All uses of attributes changed to use the attribute.h macros. Plus, use _Noreturn. (FALLTHROUGH): Remove; attribute.h now defines this.
* diff: avoid double translationPaul Eggert2021-08-301-2/+2
| | | | | * src/analyze.c (briefly_report): Do not translate here, as ‘message’ translates its format.
* diff: use variable arg list for messagesPaul Eggert2021-08-303-55/+73
| | | | | | | | | | | | | | | | | This simplifies the code by using varargs. * bootstrap.conf (gnulib_modules): Add flexmember. (XGETTEXT_OPTIONS): Do not flag message5. * src/util.c: Include flexmember.h, stdarg.h. (struct msg): New members msgid, argbytes. args is now FLEXIBLE_ARRAY_MEMBER, and does not contain msgid. All uses changed. (message): Now varargs. Detect number of args by counting '%'s. Use FLEXSIZEOF, to avoid problems on systems with buggy allocators. Avoid redundant ‘*p = 0’ when *p is already zero after stpcpy. (message5): Remove; all callers changed to use ‘message’. (print_message_queue): Abort if too many args were passed; this cannot happen with current diffutils.
* diff: port better to MS-WindowsPaul Eggert2021-08-291-21/+15
| | | | | | | | | Problem reported by Gisle Vanem (Bug#36488#30). * src/util.c (xsigaction) [SA_NOCLDSTOP]: Remove; no longer needed. (install_signal_handlers): If the first call to sigaction or signal fails, do not exit; just skip the signal and continue, in case the runtime does not support the signal even though the corresponding SIG* macro is defined.
* diff: cleanup signal handling just before exitPaul Eggert2021-08-283-65/+125
| | | | | | | | | | | | | | | | | | | | | | | | | This should fix an unlikely signal handling bug with colored output, and should also fix a Debian FTBFS (Fails To Build From Source) on powerpc64le-linux. See Bug#34519 and Frédéric Bonnard’s report in: https://bugs.debian.org/922552#19 * bootstrap.conf (gnulib_modules): Add raise, sigprocmask. * src/diff.c (main): Call cleanup_signal_handlers before exiting. Don’t bother calling ‘exit’; no longer needed nowadays. * src/util.c (sigprocmask, siginterrupt) [!SA_NOCLDSTOP]: Define to 0 instead of empty, since the results are now used. (sigset_t) [!SA_NOCLDSTOP]: Remove; we now rely on Gnulib. (xsigaction) [SA_NOCLDSTOP]: New function. (xsigaddset, xsigismember, xsignal, xsigprocmask): New functions. (some_signals_caught): New static var. (process_signals): Omit a conditional branch. Don’t bother loading interrupt_signal if stop_signal_count is nonzero. (process_signals, install_signal_handlers): Check for failures from sigprocmask etc. (sig, nsig): Now at top level, since multiple functions need them. (install_signal_handlers): No need for caught_sig array; just use caught_signals. However, set some_signals_caught. (cleanup_signal_handlers): New function.
* diff: add integer overflow checkingPaul Eggert2021-08-221-3/+12
| | | | | * src/diff.c (option_list, main): Check for integer overflow in some unlikely and hard-to-test cases.
* maint: refactor integer overflow checkingPaul Eggert2021-08-223-27/+13
| | | | | | | | | | | | | | Rely on more-modern Gnulib capabilities instead of doing integer overflow checking by hand, in some cases. * lib/cmpbuf.c (buffer_lcm): * src/io.c (slurp, find_identical_ends): Use INT_ADD_WRAPV and INT_MULTIPLY_WRAPV rather than checking overflow by hand. * src/diff3.c (process_diff): * src/dir.c (dir_read): * src/io.c (find_identical_ends, read_files): Use xnmalloc rather than checking overflow by hand. (read_files): Rely on xcalloc to do overflow checking.
* diff: avoid sprintf %sPaul Eggert2021-08-223-32/+63
| | | | | | | | | | | | sprintf fails if the result contains more than INT_MAX bytes, so rework the code to avoid usage of sprintf %s where the string might be longer than that. * bootstrap.conf (gnulib_modules): Remove xvasprintf. * src/diff.c (specify_style): * src/util.c (begin_output): Rewrite to avoid sprintf %s. * src/util.c: Do not include xvasprintf.h. (concat): Remove, as it uses sprintf %s. All uses rewritten.
* diff: use mempcpyPaul Eggert2021-08-223-23/+20
| | | | | | | | | * bootstrap.conf (gnulib_modules): Add mempcpy, stpcpy. * src/ifdef.c (do_printf_spec): * src/sdiff.c (expand_name, lf_snarf, temporary_file): * src/util.c (message5): Prefer mempcpy to memcpy plus manual size-updating. Prefer stpcpy to mempcpy plus manual size-spec.
* sdiff: fix unlikely memory leakPaul Eggert2021-08-221-5/+8
| | | | | * src/sdiff.c (temporary_file): Fix memory leak when mkstemp fails. Don’t assume temporary file name length fits in ‘int’.
* diff3: simplify process_diffPaul Eggert2021-08-221-10/+7
| | | | | | * src/diff3.c (process_diff): Remove LAST_BLOCK arg, since callers no longer needed it. All callers changed. This removes an unnecessary initialization of bptr to NULL.
* maint: modernize IF_LINT for GCC 11.2.1Paul Eggert2021-08-225-9/+6
| | | | | | | | | | | | | * src/cmp.c (cmp): * src/dir.c (find_dir_file_pathname): * src/sdiff.c (edit): Mention which GCC bug this IF_LINT works around. * src/diff3.c (process_diff): Always initialize to NULL, to avoid problems on mostly-theoretical hosts where accessing uninitialized variables traps. The next patch will have a better fix for this. * src/ifdef.c (do_printf_spec): No need for IF_LINT in GCC 11.2.1.
* maint: lint → GCC_LINTPaul Eggert2021-08-222-4/+4
| | | | | | | | ‘lint’ is for traditional lint and perhaps some other tools; ‘GCC_LINT’ is targeted more for what we do. Gnulib accepts either, but we might as well be more accurate. * configure.ac (GCC_LINT): Define this instead of ‘lint’. All uses changed.
* diff: remove printintPaul Eggert2021-08-229-78/+37
| | | | | * src/system.h (printint): Remove. All uses removed. This type was only for porting to pre-C89 hosts, and is no longer needed.
* diff: remove INT_MAX limit on -F/-p searchesPaul Eggert2021-08-221-2/+3
| | | | | * src/context.c (find_function): Don’t limit function-line searches to INT_MAX bytes, removing a FIXME.
* maint: omit unused function if not debuggingPaul Eggert2021-08-221-0/+2
| | | | * src/util.c (debug_script): Compile only if DEBUG.
* maint: remove prepargsPaul Eggert2021-08-221-1/+0
| | | | | | | | * lib/Makefile.am (noinst_HEADERS): Remove prepargs.h. (libdiffutils_a_SOURCES): Remove prepargs.c. * lib/prepargs.c, lib/prepargs.h: Remove. Hasn’t been needed for many years. * src/diff.c: Do not include prepargs.h.
* maint: zalloc → xzallocPaul Eggert2021-08-224-18/+5
| | | | | * src/util.c (zalloc): Remove. All uses replaced by xzalloc, which means the same thing.
* diff3: suppress -fanalyzer alarmsPaul Eggert2021-08-222-3/+17
| | | | | | | | * src/diff3.c: Add pragma to suppress -Wanalyzer-null-dereference alarms. * src/diff.h (find_dir_file_pathname): Add malloc-related attributes, to pacify gcc -Wsuggest-attribute=malloc.
* cmp: avoid reading uninitialized memoryJim Meyering2021-07-311-0/+5
| | | | | | | | | | | [This *is* useful, so reapply. ] When comparing buffers a word at a time, cmp could read up to sizeof (word) - 1 uninitialized bytes. * src/cmp.c (cmp): Set not just a single guaranteed-differing sentinel byte just beyond any final read byte, but also ensure that any following bytes are defined, if those may be read via block_compare's word-at-a-time comparison. Reported by Bruno Haible in https://lists.gnu.org/r/diffutils-devel/2021-07/msg00003.html
* cmp: avoid reading uninitialized memoryBruno Haible2021-07-281-0/+4
| | | | | | One or both of the sentinel bytes were copies of uninitialized values. * src/cmp.c (cmp): Use arbitrary initialized values for the sentinel bytes.
* cmp: revert preceding changeJim Meyering2021-07-281-2/+0
| | | | It did not solve the problem. The next patch does.
* cmp: avoid reading uninitialized memoryJim Meyering2021-07-271-0/+2
| | | | | | | | | | When comparing buffers a word at a time, cmp could read up to sizeof (word) - 1 uninitialized bytes. * src/cmp.c (cmp): Set not just a single guaranteed-differing sentinel byte just beyond any final read byte, but also ensure that any following bytes are defined, if those may be read via block_compare's word-at-a-time comparison. Reported by Bruno Haible in https://lists.gnu.org/r/diffutils-devel/2021-07/msg00003.html
* diff: better --color helpPaul Eggert2021-05-211-2/+2
| | | | | | * src/diff.c (option_help_msgid): Reword --color help without using the confusing word “default”. Problem reported by Peter Oliver (Bug#48532).
* diff: pacify compiler re stylePaul Eggert2021-03-241-1/+1
| | | | | | * src/diff.c (usage): Prefer &"string"[N] to "string" + N. Some compilers complain about the latter, as they worry C++ refugees will think it’s string concatnation.
* diff3: avoid signed int overflowPaul Eggert2021-03-241-10/+13
| | | | | | | * src/diff3.c (main): Avoid signed integer overflow in the very unlikely case of more than INT_MAX incompatible options. Instead, use one bit to record the presence of each type of incompatible option, and report an error if more than one bit is set.
* diff: plug memory leak in ifdef.cPaul Eggert2021-03-241-9/+3
| | | | | | | | | | | Problem reported by Than (Bug#47362). Fix the bug by using xmalloca instead of vararrays. * bootstrap.conf (gnulib_modules): Add xmalloca; remove vararrays. * configure.ac: Remove AC_C_VARARRAYS. * src/ifdef.c: Include xmalloca.h instead of xalloc.h. (do_printf_spec): Use xmalloca instead of an xmalloc that lacks a corresponding ‘free’ if HAVE_C_VARARRAYS due to a typo in 2017-05-18T05:51:31Z!meyering@fb.com.
* maint: update all copyright year number rangesJim Meyering2021-01-0117-17/+17
| | | | | | | Run "make update-copyright" and then... * gnulib: Update to latest with copyright year adjusted. * tests/init.sh: Sync with gnulib to pick up copyright year. * bootstrap: Likewise.
* maint: update all copyright year number rangesJim Meyering2020-01-0117-17/+17
| | | | | | | Run "make update-copyright" and then... * gnulib: Update to latest with copyright year adjusted. * tests/init.sh: Sync with gnulib to pick up copyright year. * bootstrap: Likewise.
* cmp: fix -l width bugPaul Eggert2019-10-011-1/+2
| | | | | | Problem reported by Dave Odell (Bug#37558). * src/cmp.c (cmp): Treat negative ‘bytes’ as infinite, fixing a bug introduced in the 2019-08-27 patch that fixed Bug#35256.
* diff: don’t mistreat -N in arg as a large numberPaul Eggert2019-08-274-28/+29
| | | | | | | | | | | | | | Problem reported by alec (Bug#35256). * NEWS: Mention the fix. * bootstrap.conf (gnulib_modules): Use strtoimax and xstrtoimax, not strtoumax and strtoumax. * src/cmp.c (bytes): Now signed, with -1 representing no limit. All uses changed. * src/cmp.c (specify_ignore_initial, main): * src/diff.c (main): * src/ifdef.c (format_group): * src/sdiff.c (interact): Use strtoimax, not strtoumax.
* diff: use xstdopen, not stdopenPaul Eggert2019-01-064-16/+8
| | | | | | * bootstrap.conf (gnulib_modules): * src/cmp.c, src/diff.c, src/diff3.c, src/sdiff.c (main): Use xstdopen, not stdopen.
* maint: convert all TABs to equivalent spaces in indentationJim Meyering2019-01-0512-3318/+3318
| | | | | | | | | | | | | | | | | | | | | | | Using this file, cat > leading-blank.exempt <<\EOF (\.gitmodules|help2man|pre-commit)$ (?:^|\/)ChangeLog[^/]*$ (?:^|\/)(?:GNU)?[Mm]akefile[^/]*$ \.(?:am|mk)$ EOF run the following command to convert all non-conforming leading white space to be all spaces: git ls-files \ | pcregrep -vf leading-blank.exempt \ | xargs pcregrep -l '^ *\t' \ | xargs perl -MText::Tabs -ni -le \ '$m=/^( *\t[ \t]*)(.*)/; print $m ? expand($1) . $2 : $_' Since that changed old NEWS, I also ran "make update-NEWS-hash" to update the old_NEWS_hash value in cfg.mk.
* diff: fix cmp, diff3, sdiff with stdin closedPaul Eggert2019-01-054-15/+23
| | | | | | | | | * NEWS: Mention this. * src/cmp.c, src/diff3.c, src/sdiff.c: Include stdopen.h. (main): Call stdopen early. * src/cmp.c (main): Simplify now that we need not worry about stdin being closed. * src/diff.c (main): Translate stdopen diagnostic.
* diff: remove unportable ‘diff -N - f <&-’ featurePaul Eggert2019-01-051-7/+4
| | | | | | | | | | | | * NEWS: Mention this. * bootstrap.conf (gnulib_modules): Add stdopen. * doc/diffutils.texi (Comparing Directories): Do not document behavior if stdin is closed. * src/diff.c: Include stdopen.h. (main): Call stdopen early. (compare_files) [__hpux]: Remove recently-introduced special case for HP-UX exec with stdin closed. * tests/new-file: Remove tests of the removed feature.
* diff: recognize file descriptors closed by the parent process on HP-UXBruno Haible2019-01-031-0/+7
| | | | | | * src/diff.c (compare_files): Use fcntl to distinguish a file descriptor closed by the parent process from a file descriptor that references /dev/null.
* maint: update all copyright dates via "make update-copyright"Jim Meyering2019-01-0117-17/+17
| | | | * gnulib: Also update submodule for its copyright updates.
* diff: adjust ANSI escapes for compatibility with less -RDennis Lambe Jr2018-12-302-30/+19
| | | | | | | | | | | | | | | | | | | | GNU less can display ANSI-colored text with the -R flag, but this support has some limitations. One of them is that if an escape sequence starts on one line and ends on a different line, only the first line will be colored in less. As a result, when diff creates colored output with multi-line deletes or adds, less will only color the first line. This change resets ANSI color to the default at the end of each line and restarts it at the beginning of the next. It patches normal and context mode. Side-by-side already worked in my testing. * src/context.c (print_context_label, pr_context_hunk): As above. (pr_unidiff_hunk, print_context_header): Likewise. * src/normal.c (print_normal_hunk): Likewise. * tests/colors: Adjust existing tests to accommodate this. * NEWS (Improvements): Mention it. Proposed in http://bugs.gnu.org/31105