Commit Graph
325 Commits
Author SHA1 Message Date
Assaf Gordon 3939f507a2 tests: test invalid backreferences in gnu/posix modes
's/foo/\1/' is rejected by default (gnu extension),
silently accepted in POSIX.

* testsuite/posix-mode-bad-ref.sh: new test.
* testsuite/Makefile.am: add new test.
2016-06-01 16:59:51 -04:00
Assaf Gordon 8eadf4de43 tests: test N command in gnu/posix modes
'N' with insufficient output prints nothing in POSIX mode, prints the
last read line in GNU Extension mode.

Compare:
  echo a | sed N
  echo a | sed --posix N
  echo a | POSIXLY_CORRECT=y sed N

* testsuite/posix-mode-N.sh: test output of N command under gnu and
posix modes.
* testsuite/Makefile.am: add new test.
2016-06-01 16:59:51 -04:00
Assaf Gordon 49a0f87d9b tests: invalid-mb-seq-UMR: avoid false-failure
* testsuite/Makefile.am (TESTS_ENVIRONMENT): Propagate the
LOCALE_JA envvar setting determined at configure time into
the test environment.  Without this, the test would fail on
some systems: at least CentOS6 and 7, but not Fedora 24.
2016-06-01 08:24:15 -07:00
Jim Meyering b250bd43ef tests: don't let any envvar setting perturb tests
* testsuite/envvar-check: New file. Identical to the one from
grep, but with the addition of sed-specific "COLS".
* testsuite/Makefile.am (EXTRA_DIST): Add it here.
(TESTS_ENVIRONMENT): New prologue, mostly copied from grep.
2016-06-01 08:21:05 -07:00
Assaf Gordon 156e099817 sed: reject recursive escaping after \c
previously, sed 's/./\c\\/' or 's/./\c\d/' would produce incorrect
results. Require two backslashes after \c to denote control sequence
^\ (ASCII 0x34), and reject recursive escaping (e.g. \c\x61).

* sed/compile.c: (RECURSIVE_ESCAPE_C): New error message.
(normalize_text): Check for \c-backslash, reject recursive escaping.
* testsuite/recursive-escape-c.sh: New file. Test new behaviour.
* testsuite/Makefile.am (T): Add new test.
* NEWS (Bug fixes): Mention it.
2016-05-29 18:55:58 -07:00
Jim Meyering 61c0a53ec9 revert v4.2.2-87-gc033bde, to make sed -i treat "-" as a file name
Stephane Chazelas made a fine case for why sed's --in-place (-i)
should treat "-" as a file name, and not as standard input in
http://debbugs.gnu.org/21249

There was no specific test for the prior behavior, so rather than
letting the revert remove the sole test, adapt and retain it:
* testsuite/in-place-hyphen.sh: However, retain and adapt this
file to test for the restored behavior.
* testsuite/Makefile.am: Retain this change, too.
2016-01-02 19:19:46 -08:00
Jim Meyering 57f405ad56 maint: update copyright year, bootstrap, init.sh
Run "make update-copyright" and then...

* gnulib: Update to latest.
* tests/init.sh: Update from gnulib.
* bootstrap: Likewise.
2016-01-01 15:02:20 -08:00
Jim Meyering 9dd563c897 sed: do not elide an invalid byte in a substitution RHS
Now, sed copies such bytes into the output.
* sed/execute.c (str_append_modified): Copy each invalid byte
into the result string, as the comment suggests.
* testsuite/invalid-mb-seq-UMR.sh: Adjust this test to conform.
Perl does the same thing.  Also, remove an unnecessary "-e" option.
* NEWS (Bug fixes): Mention it.
Bug introduced prior to the switch to git in 2004,
between the releases of sed-4.0.9 and sed-4.1.
This addresses http://debbugs.gnu.org/22254.
2015-12-27 22:36:47 -08:00
Jim Meyering 67b3fcc980 sed: fix a heap-clobbering buffer overrun
* sed/execute.c (str_append_modified): Upon encountering an
incomplete multi-byte sequence in a substitution replacement
string, do not treat mbrtowc's return value of -2 as a large,
positive number.
* testsuite/subst-mb-incomplete.sh: New file/test.
* testsuite/Makefile.am (T): Add it.
Reported by Hanno Böck in http://debbugs.gnu.org/22127.
Hanno used the AFL fuzzer to find the segfault-inducing input
from which I derived the test's input.
Introduced by v4.2.2-76-g78e8e58, this bug was never in a release.
2015-12-27 20:19:08 -08:00
Jim Meyering 80c5866cb4 tests: add helper prog, get-mb-cur-max and re_en_utf8_locale_ function 2015-12-12 17:43:25 -08:00
Jim Meyering 31c84cbcfd sed: reject a ":" command without a label
Before, sed would accept it and treat it as a label whose name
had length 0, and that could be referenced via a "b" or "t"
command with no label.
* sed/compile.c (errors): Add the new diagnostic.
(COLON_LACKS_LABEL): Define.
(compile_program): Reject ":" command with no label.
* testsuite/colon-with-no-label.sh: New file.
* testsuite/Makefile.am (T): Add it.
* NEWS (Bug fixes): Mention it.
Reported by Stephane Chazelas in http://bugs.gnu.org/21250
2015-08-23 21:48:34 -07:00
Assaf Gordon 854b64b79b build: comment out definitions of unused macros
* sed/compile.c (OPEN_BRACE): Comment out definition, to prevent gcc-5.2
from failing with -Werror -Wunused-macros.
(END_ERRORS): Likewise.
2015-08-01 09:15:47 -07:00
Jim Meyering 51dc57ab9c tests: avoid false-failure on system with no ja_JP.eucJP locale
* testsuite/invalid-mb-seq-UMR.sh: Use the configure-detected
locale name, $LOCALE_JA, rather than hard-coding ja_JP.eucJP.
If the required type of locale was not detected, then skip
this test. Reported by Assaf Gordon in http://bugs.gnu.org/21124
2015-07-30 09:55:11 -07:00
Jim Meyering c38910d9e7 maint: remove dead code
* sed/utils.c (ck_mkstemp): Remove $TMP/$TMPDIR-envvar-using code
that would have been run only if this function's second parameter
were to be NULL, but that could never happen, given the current
and sole caller.
Also, use mode_t as the type for the saved umask value, not "int".
Also, move each declaration down to point of definition.
* sed/utils.h (ck_mkstemp): Mark each of the four parameters as nonnull.
2015-07-24 21:48:03 -07:00
Stanislav Brabec e387009c78 sed: fix --follow-symlinks to work when reading stdin
When reading from stdin, use of --follow-symlinks would cause failure:

  $ echo abc | sed --follow-symlinks s/a/d/
  sed: cannot stat -: No such file or directory

* sed/execute.c (open_next_file): Set input->in_file_name earlier,
so we can rearrange logic to avoid calling follow_symlink("-").
* testsuite/follow-symlinks-stdin.sh: New file.
* testsuite/Makefile.am (T): Add it.
* NEWS (Bug fixes): Mention it.
Bug introduced by commit v4.2.1-13-g84066bf.
http://bugs.gnu.org/20795
2015-07-15 21:40:31 -07:00
Jim Meyering fe9c9b6cfa typo fix: s/singlebyte/single-byte/
* sed/compile.c (compile_program, normalize_text): Fix typo.
* sed/mbcs.c (brlen): Likewise.
2015-06-23 15:32:35 -07:00
Jim Meyering c033bdee41 sed -i: do not treat "-" as a file name
Most GNU utilities treat "-" as standard input, sed itself does that --
in most contexts.  However, since the addition of support for
--in-place (-i) in sed-4.0, sed -i has treated a "-" argument as a
file name, i.e., like ./-.  Now, that usage evokes a diagnostic:

  $ sed -i s/a/b/ -
  sed: couldn't edit -: is a terminal

If you require the old behavior, specify the file name as "./-".
Prompted by the report/patch from Stanislav Brabec in
http://bugs.gnu.org/20796 to document the strangely
inconsistent legacy behavior.

* sed/execute.c (open_next_file): Call panic before
even attempting to operate on the file descriptor.
* testsuite/in-place-hyphen.sh: New file.  Test for this.
* testsuite/Makefile.am (T): Add it.
* NEWS (Feature removal): Mention it. Admittedly, the old behavior
feels more like a misfeature.
2015-06-20 19:58:08 -07:00
Jim Meyering 2714d42345 tests: initialize $fail to 0
* testsuite/range-overlap.sh: Otherwise, with $fail set to
nonzero in the environment, this test would report failure,
even when it should pass.
2015-06-20 19:58:08 -07:00
Jim Meyering 68e47c0c62 build: avoid warning about implicit declaration of unlink
* sed/sed.c: Include <unistd.h>, for declaration of unlink.
Without this change, commit makes sed v4.2.2-84-g7689015 fail
to compile when configured with --enable-gcc-warnings.
2015-05-10 09:33:27 -07:00
Jim Meyering 768901548e sed -i: don't leave behind a temporary sedXXXXXX file
For example, running a command like "sed -i s//b/ F" would fail
to remove a temporary file named sedXXXXXX (for random XXXXXX)
in the directory alongside F.
* sed/sed.c (G_file_to_unlink): New global.
(register_cleanup_file, cancel_cleanup, cleanup): New functions.
(main): Call atexit.
* sed/execute.c (open_next_file): Register for unlink.
(closedown): Call cancel_cleanup right after the rename.
* sed/sed.h: Declare two of the new functions.
* NEWS (Bug fixes): Mention it.
* testsuite/temp-file-cleanup.sh: New file.  Test for this.
* testsuite/Makefile.am (T): Add it.
Reported by David Jones in http://bugs.gnu.org/20002.
2015-05-10 09:29:04 -07:00
Jim Meyering 3201f1dcbe maint: remove stray blank line in the middle of a comment
* sed/utils.c (ck_mkstemp): As above.
2015-05-07 08:07:03 -07:00
Jim Meyering af342f7233 tests: skip the new test in presence of buggy valgrind
* testsuite/invalid-mb-seq-UMR.sh: Upon failure due to a
valgrind-internal assertion, skip this test.
Reported by Norihiro Tanaka in http://debbugs.gnu.org/20490
2015-05-07 08:04:48 -07:00
Norihiro Tanaka 4c75f64068 sed: fix mishandling of overlapping address ranges
When the line number ranges of two or more editing commands overlap,
sed applies all commands but the first to a line that is just beyond
the union of all ranges.  E.g., with this command,
seq 9|sed '2,7d;3,6d', sed would mistakenly delete line 8.

* sed/execute.c (match_an_address_p) [ADDR_IS_NUM]: Make this
function work also in this case.
(match_address_p): Move the ADDR_IS_NUM +
...->line_number == ...->addr_number comparison "up" into
match_an_address_p, so we can hoist two similar if/return
blocks out of "if" and "else" branches.
Change so that this function returns false when the current
line number is outside the specified range.
* testsuite/range-overlap.sh: New file, to test for this.
* testsuite/Makefile.am (T): Add it to the list.
* NEWS (Bug fixes): Mention it.
Reported as http://bugs.gnu.org/19899
2015-05-06 19:18:54 -07:00
Jim Meyering b1517867eb build: do not require autoconf.git
* configure.ac: Use AC_CONFIG_MACRO_DIR, not
the new (as yet unreleased) AC_CONFIG_MACRO_DIRS.
Reported by Hongyi Zhao in http://debbugs.gnu.org/20424
2015-05-04 07:29:31 -07:00
Jim Meyering 62ae3e9016 maint: housekeeping: sync a few rules from coreutils
* cfg.mk (sc_preprocessor_indentation): New rule, from coreutils.
(local-checks-to-skip): Exempt it, for now.
(sc_THANKS_in_sorted): Another rule from coreutils.  Enabled.
(announcement_Cc_): Define, so the auto-generated announcement
message template includes sed-devel@ as a recipient.
(update-copyright-env) [UPDATE_COPYRIGHT_USE_INTERVALS]: Update
to use =2, rather than=1, so that the next time we update
copyright dates, it will collapse a few more ranges.
2015-05-03 11:11:28 -07:00
Jim Meyering 7c826cb41f maint: tweak comments and rearrange code slightly
* sed/execute.c (str_append): Trivial NSC code transformation.
(str_append_modified): Tweak another comment.
2015-05-03 10:56:16 -07:00
Jim Meyering af7a509eaa tests: test for just-fixed UMR bug
* testsuite/invalid-mb-seq-UMR.sh: New file. Test for just-fixed bug.
* testsuite/Makefile.am (T): New variable.
Add the two init.sh-using test names here, rather than in
two separate lists.
(SEDTESTS, EXTRA_DIST): Use $(T).
(EXTRA_DIST): Add init.cfg.
* testsuite/init.cfg: New file, to add functions from coreutils.
(require_valgrind_, print_ver_): New functions.
2015-05-03 10:03:44 -07:00
Norihiro Tanaka 78e8e58ab0 sed: avoid a UMR bug when processing an invalid multibyte sequence
* sed/execute.c (str_append_modified): When attempting to append an
invalid multibyte sequence, e.g., from the RHS of a substitution
expression, we would read uninitialized memory.
Don't capitalize first word of diagnostic; remove exclamation point.
Wrap new translatable strings in _(...).
* NEWS (Bug fixes): Mention it.
This addresses http://debbugs.gnu.org/20490
2015-05-03 10:01:15 -07:00
Jim Meyering 3277f269a2 maint: remove SED_FEATURE_VERSION; use PACKAGE_VERSION instead
* configure.ac (SED_FEATURE_VERSION): Remove definition et al.
* sed/compile.c (compile_program): Remove sole use.
Use PACKAGE_VERSION instead.
2015-05-02 19:28:38 -07:00
Jim Meyering 29baca551b maint: add "/*~" to build-aux/ and m4/.gitignore files
Otherwise, bootstrap would add entries for individual file names.
* build-aux/.gitignore: Add /*~
* m4/.gitignore: Likewise.
2015-05-02 10:13:25 -07:00
Jim Meyering 857ed5c3b9 maint: enable sc_file_system
* cfg.mk (local-checks-to-skip): Remove its exemption.
* BUGS (characters): s/filesystem/file system/
* ChangeLog-2014 (setup_jump): Likewise.
* doc/sed-in.texi: Likewise.
* doc/sed.texi: Likewise.
2015-05-01 18:09:51 -07:00
Jim Meyering 312c75163a build: require gettext 0.19.2, perl-5.5
* configure.ac: Require gettext-0.19.2.
* bootstrap.conf: List perl and gettext version requirements.
2015-05-01 18:09:39 -07:00
Jim Meyering 885402bc29 tests: set sed's expected failure status to 4
* testsuite/help-version.sh (expected_failure_status_sed): As above.
2015-04-27 07:26:01 -07:00
Jim Meyering 44a0755f64 maint: invoke make via $(MAKE), not via "make"
* Makefile.am (html): Invoke make via $(MAKE).
(full-distcheck): Likewise.
2015-04-26 22:57:27 -07:00
Jim Meyering 2636740851 use generated version.[ch] and add init.sh and help-version.sh
* Makefile.am (DISTCLEANFILES): Initialize.
(EXTRA_DIST): Add .version.
(BUILT_SOURCES): Set to .version.
(.version): New rule.
(THANKS): Depend on .version.
* sed/Makefile.am: Add rules to build version.[ch].
* sed/sed.c: Include version.h, and use the new variable, Version.
* testsuite/Makefile.am: Arrange to distribute and run the new
help-version.sh test. Also distribute the new init.sh.
* testsuite/help-version.sh: New file.
* testsuite/init.sh: Likewise.
* .gitignore: Ignore the generated files, .version and src/version.[ch].
2015-04-26 12:30:33 -07:00
Jim Meyering 2f5dbefd8b maint: COPYRIGHT_YEAR: remove, along with tests that use it
This is covered by other tests, and the general --help/--version
checks provided by help-version.sh (about to be added) are more
thorough.
* configure.ac (COPYRIGHT_YEAR): Remove definition and AC_SUBST.
* Makefile.am (dist-hook): Remove test.
* testsuite/Makefile.am (SEDTESTS): Remove "version".
* testsuite/version.gin: Remove file.
* .gitignore: Remove mention of generated file, version.good.
2015-03-01 20:21:17 -08:00
Jim Meyering 5b16974db6 maint: initialize an mbstate_t with "= { 0, };", rather than with memset
I.e., use this:
  mbstate_t mbstate = { 0, };
rather than this:
  mbstate_t mbstate;
  memset (&cur_stat, 0, sizeof (mbstate_t));
Also, prefer "sizeof VAR" over sizeof(TYPE).
* sed/execute.c (execute_program, translate_mb): As above.
* sed/compile.c (match_slash, compile_program, normalize_text):
Likewise.
2015-01-01 19:21:26 -08:00
Jim Meyering 96fe108e64 maint: enable sc_prohibit_long_lines
* cfg.mk (local-checks-to-skip): Remove the overall exemption,
but continue to exempt some files in testsuite/.
* configure.ac: Split a long line.
* doc/sed-in.texi: Split long lines.
* doc/sed.texi: Likewise.
* sed/compile.c: Likewise.
* sed/execute.c: Split long lines.
(execute_program): Reorder "#ifdef HAVE_POPEN" and
"if (pipe_fp != NULL)" if/else blocks to make the code
clearer and (incidentally) the lines shorter, due to a
decrease in nesting level.
* sed/sed.c: Split long lines.
* sed/utils.c: Likewise.
* sed/utils.h: Likewise.
2015-01-01 19:21:26 -08:00
Jim Meyering 5445ae1fc3 maint: translate_mb: new function factored out of 'y'-handling case
* sed/execute.c (translate_mb): New function, factored out of
the "case 'y':" part of...
(execute_program): ...here.
2015-01-01 19:21:26 -08:00
Jim Meyering 63f190e574 maint: remove more unnecessary declarations
* sed/execute.c: Remove now-duplicate forward declarations.
2015-01-01 19:21:26 -08:00
Jim Meyering 082b25cc3e maint: update copyright year ranges to include 2015; update gnulib 2015-01-01 19:18:17 -08:00
Jim Meyering 311d11269e maint: enable sc_prohibit_strncpy check
* cfg.mk (exclude_file_name_regexp--sc_prohibit_strncpy): Remove
its exemption.
* sed/compile.c (compile_program): Remove two misuses of strncpy;
use memcpy instead.
* sed/execute.c (do_list): Likewise, for one instance.
2014-12-20 18:51:52 -08:00
Jim Meyering 9eb391523b maint: begin to use "size_t" more, where appropriate
* sed/execute.c (do_list): Update some "int" locals to "size_t",
and combine a few declarations with needlessly separate initializations.
2014-12-20 18:51:45 -08:00
Jim Meyering bea07ed28f maint: update .gitignore
* .gitignore: Ignore build artifacts.
2014-12-20 16:39:53 -08:00
Jim Meyering 0a6fe4a625 maint: remove po/sed.pot from version control
* po/sed.pot: Remove file.  It is unnecessary and undesirable to
version-control a file like this (mechanically-derived).
2014-12-20 16:11:49 -08:00
Jim Meyering 33493b14bb build: update build tool version requirements
* bootstrap.conf (buildreq): Blindly update tool-version number
requirements from those required by coreutils.
2014-12-20 16:03:50 -08:00
Jim Meyering a5d187ada0 maint: fix "make distcheck" failure
* Makefile.am (EXTRA_DIST): List THANKS.in, not THANKS.
Add .mailmap, too.
2014-12-20 16:03:50 -08:00
Jim Meyering 6783c9f367 build: build-aux/texi2dvi: remove file
* build-aux/texi2dvi: Remove file. It was out of date and could
no longer parse our .texi files.
* Makefile.am (EXTRA_DIST): Don't list it here.
* cfg.mk: Remove an exemption for that file.
* doc/Makefile.am (TEXI2DVI): Remove definition.
2014-12-20 16:03:40 -08:00
Jim Meyering be2d5c0d33 remove support for the 'L' (fmt/flow-paragraph) command
* sed/Makefile.am (sed_SOURCES): Remove fmt.c.
* sed/execute.c (execute_program):
* sed/fmt.c: Remove file.
* sed/sed.h (fmt): Remove declaration.
* doc/sed.texi: Remove documentation for 'L' command.
* doc/sed-in.texi: Likewise.
* NEWS (Feature removal): Document it.
Prompted by the report from Jodie Cunningham that using this
command with a large number could cause sed to segfault:
https://bugs.launchpad.net/ubuntu/+source/sed/+bug/1400575
2014-12-16 15:40:57 -08:00
Jim Meyering 38800587a9 doc: NEWS: mention the gzip->xz release tarball switch
* NEWS (Build-related): Mention that we are now distributing
only .tar.xz archives; no more gzip-compressed tarballs.
2014-12-01 21:59:02 -08:00