summaryrefslogtreecommitdiffstats
path: root/src
AgeCommit message (Collapse)AuthorLines
2022-01-31factor: remove IF_LINTPaul Eggert-1/+1
* src/factor.c (factor_using_squfof) [USE_SQUFOF]: Use plain assert (...), not IF_LINT (assert (...)). This code is currently never compiled or executed, so this is merely a symbolic cleanup.
2022-01-31expand: remove IF_LINTPaul Eggert-1/+1
* src/expand.c (expand): Remove no-longer-needed IF_LINT.
2022-01-31env: simplify -fsanitize=leak pacificationPaul Eggert-6/+1
* src/env.c (unset_envvars): Remove IF_LINT code. (main): Use main_exit, not return.
2022-01-31md5sum: remove IF_LINTsPaul Eggert-2/+2
* src/digest.c (digest_check): Remove IF_LINTs that are no longer needed, as GCC has gotten smarter since 2008.
2022-01-31df: simplify -fsanitize=leak pacificationPaul Eggert-12/+3
* src/df.c (print_table, main) [lint]: Omit unnecessary cleanup. (main): Use main_exit, not return.
2022-01-31date: simplify -fsanitize=leak pacificationPaul Eggert-4/+1
* src/date.c (main) [lint]: Omit unnecessary cleanup. Use main_exit, not return.
2022-01-31cut: simplify and remove an IF_LINTPaul Eggert-55/+28
* src/cut.c (enum operating_mode, operating_mode) (output_delimiter_specified, cut_stream): Remove; no longer needed. (output_delimiter_default): New static var. Code can now use ‘output_delimiter_string != output_delimiter_default’ instead of ‘output_delimiter_specified’. (cut_file): New arg CUT_STREAM. Caller changed. (main): Simplify. Coalesce duplicate code. Redo to avoid need for IF_LINT, or for the static var. No need to xstrdup optarg.
2022-01-31cut: simplify -fsanitize=leak pacificationPaul Eggert-14/+0
* src/set-fields.c (reset_fields): Remove, as it’s not needed for -fsanitize=leak even when ‘lint’ is defined. All uses removed.
2022-01-31cp: simplify GCC pacificationPaul Eggert-1/+1
* src/cp.c (make_dir_parents_private): Remove IF_LINT code that is no longer needed, as GCC has apparently gotten smarter since 2008.
2022-01-31chown: simplify -fsanitize=leak pacificationPaul Eggert-6/+2
* src/chgrp.c, src/chown.c (main) [lint]: Omit unnecessary cleanup. Use main_exit, not return.
2022-01-31basenc: simplify -fsanitize=leak pacificationPaul Eggert-21/+20
* src/basenc.c (finish_and_exit): New function. (do_encode, do_decode): Use it. Accept new INFILE arg. Remove no-longer-needed IF_LINT code. Exit when done. Caller changed.
2022-01-31test: simplify gcc pacificationPaul Eggert-4/+0
* src/test.c (get_mtime) [lint]: Omit ifdef lint code that is no longer needed, as GCC has gotten smarter since 2005.
2022-01-31tail: simplify -fsanitize=leak pacificationPaul Eggert-52/+16
Also, close a no-longer-needed file descriptor when falling back from inotify. * src/tail.c (tail_forever_inotify): Return void, not bool. Exit on fatal error, or on successful completion. Accept an extra argument pointing to a hash table that the caller should free on non-fatal error; this simplifies cleanup. Don’t bother setting errno when returning. Caller changed. (main): Omit no-longer-needed IF_LINT code. Close inotify descriptor if inotify fails; this fixes a file descriptor leak and means we needn’t call inotify_rm_watch. Use main_exit, not return.
2022-01-31tac: simplify -fsanitize=leak pacificationPaul Eggert-6/+1
* src/tac.c (main) [lint]: Omit unnecessary cleanup. Use main_exit, not return.
2022-01-31shuf: simplify -fsanitize=leak pacificationPaul Eggert-18/+1
* src/shuf.c (main) [lint]: Omit unnecessary cleanup. Use main_exit, not return.
2022-01-31numfmt: simplify -fsanitize=leak pacificationPaul Eggert-10/+1
* src/numfmt.c (main) [lint]: Omit unnecessary cleanup. Use main_exit, not return.
2022-01-31mktemp: simplify -fsanitize=leak pacificationPaul Eggert-6/+1
* src/mktemp.c (main) [lint]: Omit unnecessary cleanup. Use main_exit, not return.
2022-01-31dd: simplify -fsanitize=leak pacificationPaul Eggert-7/+1
* src/dd.c (cleanup) [lint]: Omit unnecessary cleanup. (main): Use main_exit, not return.
2022-01-31cp: simplify cp/install/ln/mv pacificationPaul Eggert-60/+6
* src/copy.c (dest_info_free, src_info_free) [lint]: Remove. All uses removed. (copy_internal): Pacify only Clang and Coverity; GCC doesn’t need it. * src/cp-hash.c (forget_all) [lint]: Remove. All uses removed. * src/cp.c, src/install.c, src/ln.c, src/mv.c (main): Use main_exit, not return.
2022-01-31chmod: pacify -fsanitizer=leakPaul Eggert-3/+1
* src/chmod.c (main): Use main_exit, not return.
2022-01-31yes: pacify -fsanitizer=leakPaul Eggert-1/+1
* src/yes.c (main): Use main_exit, not return.
2022-01-31tsort: pacify -fsanitizer=leakPaul Eggert-2/+4
* src/tsort.c (detect_loop): Free removed successor.
2022-01-31sort: pacify -fsanitizer=leakPaul Eggert-17/+6
* src/sort.c (pipe_fork, keycompare, sort, main): Remove lint code that no longer seems to be needed. (sort): Unconditionally compile ifdef lint code that is needed to free storage even when not linting. (main): Use main_exit, not return.
2022-01-31split: pacify -fsanitizer=leakPaul Eggert-7/+9
* src/split.c (lines_rr): New arg FILESP. All uses changed. (main): Use main_exit, not return. Omit unnecessary alignfree.
2022-01-31ptx: pacify -fsanitizer=leakPaul Eggert-14/+10
* src/ptx.c (unescape_string): Rename from copy_unescaped_string, and unescape the string in place. Callers changed. This way, we needn’t allocate storage and thus needn’t worry about -fsanitizer=leak.
2022-01-31seq: pacify -fsanitizer=leakPaul Eggert-15/+10
* src/seq.c (seq_fast): If successful, exit rather than returning true. Callers changed. (main): Use main_exit, not return.
2022-01-31tsort: pacify -fsanitizer=leakPaul Eggert-28/+11
* src/tsort.c (struct item.balance): Now signed char to save space. (struct item.printed): New member. (new_item): Initialize k->printed to false. Simplify via xzalloc. (scan_zeros): Use k->printed rather than nulling out string. (tsort): Move exiting code here ... (main): ... from here. (tsort) [lint]: Omit no-longer-needed code. Instead, set head->printed.
2022-01-31tr: pacify -fsanitizer=leakPaul Eggert-1/+1
* src/tr.c (main): Use main_exit, not return.
2022-01-31stat: pacify -fsanitizer=leakPaul Eggert-1/+1
* src/stat.c (main): Use main_exit, not return.
2022-01-31comm: pacify -fsanitizer=leakPaul Eggert-6/+8
* src/comm.c (compare_files): Move exiting code here ... (main): ... from here, to pacify gcc -fsanitize=leak.
2022-01-31expr: lint cleanup, and introducing main_exitPaul Eggert-3/+15
This introduces a new macro main_exit, which is useful for pacifying gcc -fsanitizer=lint and in some cases means we can remove some ‘IF_LINT’ and ‘ifdef lint’ code. * src/expr.c (main): Use main_exit, not return. (docolon): Omit an IF_LINT that GCC no longer needs. * src/system.h (main_exit): New macro.
2022-01-30cksum: use more exact selection of digest algorithmsPádraig Brady-3/+3
Use more constrained argument matching to improve forward compatibility and robustness. For example it's better that `cksum -a sha3` is _not_ equivalent to `cksum -a sha386`, so that a user specifying `-a sha3` on an older cksum would not be surprised. Also argmatch() is used when parsing tags from lines like: SHA3 (filename) = abcedf.... so it's more robust that older cksum instances to fail earlier in the parsing process, when parsing output from possible future cksum implementations that might support SHA3. * src/digest.c (algorithm_from_tag): Use argmatch_exact() to ensure we don't match abbreviated algorithms. (main): Likewise. * tests/misc/cksum-a.sh: Add a test case.
2022-01-29mv: when installing to dir use dir-relative namesPaul Eggert-209/+198
When the destination for mv is a directory, use functions like openat to access the destination files, when such functions are available. This should be more efficient and should avoid some race conditions. Likewise for 'install'. * src/cp.c (must_be_working_directory, target_directory_operand) (target_dirfd_valid): Move from here ... * src/system.h: ... to here, so that install and mv can use them. Make them inline so GCC doesn’t complain. * src/install.c (lchown) [HAVE_LCHOWN]: Remove; no longer needed. (need_copy, copy_file, change_attributes, change_timestamps) (install_file_in_file, install_file_in_dir): New args for directory-relative names. All uses changed. Continue to pass full names as needed, for diagnostics and for lower-level functions that do not support directory-relative names. (install_file_in_dir): Update *TARGET_DIRFD as needed. (main): Handle target-directory in the new, cp-like way. * src/mv.c (remove_trailing_slashes): Remove static var; now local. (do_move): New args for directory-relative names. All uses changed. Continue to pass full names as needed, for diagnostics and for lower-level functions that do not support directory-relative names. (movefile): Remove; no longer needed. (main): Handle target-directory in the new, cp-like way. * tests/install/basic-1.sh: * tests/mv/diag.sh: Adjust to match new diagnostic wording.
2022-01-29cp: fix comment typoPaul Eggert-1/+1
2022-01-28dd: synchronize output after write errorsPaul Eggert-21/+55
Problem reported by Sworddragon (Bug#51345). * src/dd.c (cleanup): Synchronize output unless dd has been interrupted. (synchronize_output): New function, split out from dd_copy. Update conversions_mask so synchronization is done at most once. (main): Do not die with the output file open, since we want to be able to synchronize it before exiting. Synchronize output before exiting.
2022-01-27dd: output final progress before syncingPaul Eggert-0/+12
Problem reported by Sworddragon (Bug#51482). * src/dd.c (reported_w_bytes): New var. (print_xfer_stats): Set it. (dd_copy): Print a final progress report if useful before synchronizing output data.
2022-01-27cat: prefer copy_file_range to read+writePaul Eggert-5/+51
* src/cat.c (copy_cat): New function. (main): Use it.
2022-01-27csplit: improve integer overflow checkingPaul Eggert-144/+113
* src/csplit.c: Prefer signed integers to unsigned for sizes when either will do. Check for some unlikely overflows. (INCR_SIZE): Remove; no longer used. (free_buffer): Also free the arg, simplifying callers. (get_new_buffer): Use xpalloc instead of computing new size by hand. Add ATTRIBUTE_DEALLOC. (delete_all_files, close_output_file): If unlink fails with ENOENT, treat it as success. (close_output_file): If unlink fails, decrement count anyway. (parse_repeat_count, parse_patterns): Check for int overflow. (check_format_conv_type): Use signed format.
2022-01-27maint: simplify memory alignmentPaul Eggert-75/+55
Use the new Gnulib modules alignalloc and xalignalloc to simplify some memory allocation. Also, fix some unlikely integer overflow problems. * bootstrap.conf (gnulib_modules): Add alignalloc, xalignalloc. * src/cat.c, src/copy.c, src/dd.c, src/shred.c, src/split.c: Include alignalloc.h. * src/cat.c (main): * src/copy.c (copy_reg): * src/dd.c (alloc_ibuf, alloc_obuf): * src/shred.c (dopass): * src/split.c (main): Use alignalloc/xalignalloc/alignfree instead of doing page alignment by hand. * src/cat.c (main): Check for integer overflow in page size calculations. * src/dd.c (INPUT_BLOCK_SLOP, OUTPUT_BLOCK_SLOP, MAX_BLOCKSIZE): (real_ibuf, real_obuf) [lint]: Remove; no longer needed. (cleanup) [lint]: (scanargs): Simplify. * src/ioblksize.h (io_blksize): Do not allow blocksizes largest than the largest power of two that fits in idx_t and size_t. * src/shred.c (PAGE_ALIGN_SLOP, PATTERNBUF_SIZE): Remove.
2022-01-27copy: remove unnecessary ‘free’Paul Eggert-2/+0
* src/copy.c (copy_reg): Remove a ‘free’ call that does nothing because its argument is always a null pointer, starting with 2007-11-1608:31:15Z!jim@meyering.net.
2022-01-27dd: simplify conv=swab codePaul Eggert-54/+33
Simplify byte-swapping, so that the code no longer needs to allocate a page before the input buffer. * src/dd.c (SWAB_ALIGN_OFFSET, char_is_saved, saved_char): Remove. All uses removed. (INPUT_BLOCK_SLOP): Simplify to just page_size. (alloc_ibuf, dd_copy): Adjust to new swab_buffer API. (swab_buffer): New arg SAVED_BYTE, taking the place of the old global variables. Do not access BUF[-1].
2022-01-27dd: improve integer overflow checkingPaul Eggert-135/+163
* src/dd.c: Prefer signed to unsigned types where either will do, as this helps improve checking with gcc -fsanitize=undefined. Limit the signed types to their intended ranges. (MAX_BLOCKSIZE): Don’t exceed IDX_MAX - slop either. (input_offset_overflow): Remove; overflow now denoted by negative. (parse_integer): Return INTMAX_MAX on overflow, instead of unspecified. Do not falsely report overflow for ‘00x99999999999999999999999999999’. * tests/dd/misc.sh: New test for 00xBIG. * tests/dd/skip-seek-past-file.sh: Adjust to new diagnostic wording. New test for BIGxBIG.
2022-01-27cat: prefer signed to unsignedPaul Eggert-11/+12
* src/cat.c: Prefer signed to unsigned types where either will do, as they allow for better overflow checking at runtime.
2022-01-27cat: improve stylePaul Eggert-97/+49
* cat.c: Improve style a bit, mostly by assuming C99-style declarations after statements
2022-01-27doc: csplit: clarify [OFFSET] syntaxPádraig Brady-1/+1
* src/csplit.c (usage): Clarify that '+' prefix is optional on OFFSET. * doc/coreutils.texi (csplit invocation): Likewise. Fixes https://bugs.gnu.org/53574
2022-01-14cp: rely on Gnulib for copy_file_range workaroundPaul Eggert-44/+1
Gnulib now replaces copy_file_range on buggy hosts so there is no need for Coreutils to worry about the bug. * src/copy.c: Do not include sys/utsname.h, xstrtol.h. (functional_copy_file_range): Remove. All uses now simply call copy_file_range.
2022-01-14cp: fix two typos in previous changePaul Eggert-3/+4
Somehow ‘make check’ didn’t catch these the first few times. * src/copy.c (copy_dir): Don’t pass null pointer to copy_internal where it now expects non-null if move mode. * src/cp.c (make_dir_parents_private): Initialize *attr_list before recentely-added quick return.
2022-01-14cp: omit unnecessary stat of destinationPaul Eggert-21/+36
'cp A B' attempts to open B as a directory, to see whether to write to B/A instead of to B. In the common case where the open fails with ENOENT, do not bother to stat B afterwards since the stat should also fail with ENOENT. * src/copy.c (copy_internal, copy): Change bool arg about nonexistent destination to a 3-way int argument. All callers changed. (copy_internal): Do not bother to stat a destination already known to not exist when following symlinks.
2022-01-13cp: when copying to dir use dir-relative namesPaul Eggert-246/+344
When copying to a directory, use functions like openat to access the destination files, when such functions are available. This should be more efficient and should avoid some race conditions. * bootstrap.conf (gnulib_modules): Add areadlinkat-with-size, fchmodat, fchownat, mkdirat, mkfifoat, utimensat. * src/copy.c (lchown) [!HAVE_LCHOWN]: * src/copy.c, src/system.h (rpl_mkfifo, mkfifo) [!HAVE_MKFIFO]: Remove. All uses removed. (utimens_symlink): Remove; we shouldn’t have to worry about those obsolete systems any more. All uses replaced by utimensat. * src/copy.c (copy_dir, set_owner, fchmod_or_lchmod, copy_reg) (same_file_ok, writable_destination, overwrite_ok, abandon_move) (create_hard_link, src_is_dst_backup, copy_internal, copy): * src/cp.c (make_dir_parents_private, re_protect): New args for directory-relative names. All uses changed. Continue to pass full names as needed, for diagnostics and for lower-level functions like qset_acl that do not support directory-relative names. * src/copy.c (copy_reg): Prefer readlinkat to lstatat for merely checking whether a file is a symlink, to avoid EOVERFLOW issues. (subst_suffix): New function. (create_hard_link): Accept a null SRC_NAME as meaning that if it is needed it needs to be constructed from SRC_RELNAME, DST_NAME, and DST_RELNAME. (source_is_dst_backup): Use subst_suffix instead of doing it by hand. (copy_internal): Remember and use directory-relative names instead of full names. * src/cp.c (lchown) [!HAVE_LCHOWN]: Remove. All uses removed. (must_be_working_directory): New function. (target_directory_operand): Simply take file name as arg, and return a file descriptor or negative number on failure; open with O_DIRECTORY to obtain any file descriptor. All uses changed. (target_dirfd_valid): New function. (do_copy): Use these new functions to obtain a file descriptor for any target directory, and use directory-relative names for that directory. (main): Omit no-longer-needed stat when --target-directory, as do_copy now does this. * src/ln.c (O_PATHSEARCH): Move from here ... * src/system.h: ... to here. * tests/cp/fail-perm.sh: Adjust to change in diagnostic wording, and add a test for --no-target-directory.
2022-01-13cp: tweak internal namePaul Eggert-7/+2
* src/cp.c (do_copy): Omit confusingly-named local new_dest, since there’s another var new_dst that means something quite different.