From fbe256efa22b8a35f0b12c53050590911486990f Mon Sep 17 00:00:00 2001 From: Jim Meyering Date: Sat, 26 Nov 2016 10:11:43 -0800 Subject: [PATCH 1/8] maint: fix two "make syntax-check" failures * cfg.mk (exclude_file_name_regexp--sc_prohibit_empty_lines_at_EOF): Also exempt zero-anchor.{inp,good}. * sed/regexp.c (match_regex): s/can not/cannot/ --- cfg.mk | 2 +- sed/regexp.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/cfg.mk b/cfg.mk index 8c61cc4..a54498f 100644 --- a/cfg.mk +++ b/cfg.mk @@ -170,7 +170,7 @@ exclude_file_name_regexp--sc_prohibit_tab_based_indentation = \ $(tbi_1)|$(tbi_2) exclude_file_name_regexp--sc_prohibit_empty_lines_at_EOF = \ - ^testsuite/(bkslashes.good|(noeolw?|empty)\.(2?good|inp))$$ + ^testsuite/(bkslashes.good|(noeolw?|empty|zero-anchor)\.(2?good|inp))$$ # Exempt test-related files from our 80-column limitation, for now. exclude_file_name_regexp--sc_long_lines = ^testsuite/ diff --git a/sed/regexp.c b/sed/regexp.c index c21a3a9..bb4a601 100644 --- a/sed/regexp.c +++ b/sed/regexp.c @@ -355,7 +355,7 @@ match_regex(struct regex *regex, char *buf, size_t buflen, } } - /* If the buffer delimiter is not newline character, we can not use + /* If the buffer delimiter is not newline character, we cannot use newline_anchor flag of regex. So do it line-by-line, and add offset value to results. */ if ((regex->flags & REG_NEWLINE) && buffer_delimiter != '\n') -- 2.9.3 From 7869c66841dc2ea013bf4d0d3b46b2f27a89d497 Mon Sep 17 00:00:00 2001 From: Jim Meyering Date: Sat, 26 Nov 2016 17:17:51 -0800 Subject: [PATCH 2/8] maint: remove unused parameters * sed/compile.c (finish_program): This function's sole argument was unused. Remove it and update callers. * sed/sed.h: Update prototype. * sed/utils.c (register_open_file): This functions's third argument, "temp", was unused. Remove it and update callers. * sed/sed.c: Update use. --- sed/compile.c | 2 +- sed/sed.c | 2 +- sed/sed.h | 2 +- sed/utils.c | 8 ++++---- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/sed/compile.c b/sed/compile.c index e97b041..7a28e56 100644 --- a/sed/compile.c +++ b/sed/compile.c @@ -1679,7 +1679,7 @@ rewind_read_files(void) /* Release all resources which were allocated in this module. */ void -finish_program(struct vector *program) +finish_program(void) { /* close all files... */ { diff --git a/sed/sed.c b/sed/sed.c index 565cb1b..7445178 100644 --- a/sed/sed.c +++ b/sed/sed.c @@ -376,7 +376,7 @@ main (int argc, char **argv) return_code = process_files(the_program, argv+optind); - finish_program(the_program); + finish_program(); ck_fclose(NULL); return return_code; diff --git a/sed/sed.h b/sed/sed.h index 6f1591c..0d056e3 100644 --- a/sed/sed.h +++ b/sed/sed.h @@ -191,7 +191,7 @@ struct vector *compile_string (struct vector *, char *str, size_t len); struct vector *compile_file (struct vector *, const char *cmdfile); void check_final_program (struct vector *); void rewind_read_files (void); -void finish_program (struct vector *); +void finish_program (void); struct regex *compile_regex (struct buffer *b, int flags, int needed_sub); int match_regex (struct regex *regex, diff --git a/sed/utils.c b/sed/utils.c index db2b51a..7990863 100644 --- a/sed/utils.c +++ b/sed/utils.c @@ -101,7 +101,7 @@ utils_fp_name(FILE *fp) } static void -register_open_file (FILE *fp, const char *name, int temp) +register_open_file (FILE *fp, const char *name) { struct open_file *p; for (p=open_files; p; p=p->link) @@ -138,7 +138,7 @@ ck_fopen(const char *name, const char *mode, int fail) return NULL; } - register_open_file (fp, name, false); + register_open_file (fp, name); return fp; } @@ -157,7 +157,7 @@ ck_fdopen( int fd, const char *name, const char *mode, int fail) return NULL; } - register_open_file (fp, name, false); + register_open_file (fp, name); return fp; } @@ -179,7 +179,7 @@ ck_mkstemp (char **p_filename, const char *tmpdir, *p_filename = template; FILE *fp = fdopen (fd, mode); - register_open_file (fp, template, true); + register_open_file (fp, template); return fp; } -- 2.9.3 From ed15b8cb1384b89d1a80614f577214c9922f37bf Mon Sep 17 00:00:00 2001 From: Jim Meyering Date: Sat, 26 Nov 2016 18:25:54 -0800 Subject: [PATCH 3/8] maint: fix -Wformat-exposed errors in uses of "panic" * sed/utils.h (panic): Add __printf__ attribute, so that compilers can diagnose format/arg-type errors. This exposed the following: * sed/utils.c (ck_fwrite): Don't try to print size_t via %u. Instead, use %llu and a cast to unsigned long long. * sed/mbcs.c (is_mb_char): Cast an "int" to unsigned int, to avoid mismatch with %x. --- sed/mbcs.c | 3 ++- sed/utils.c | 7 ++++--- sed/utils.h | 2 +- 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/sed/mbcs.c b/sed/mbcs.c index bce39fa..3505ef6 100644 --- a/sed/mbcs.c +++ b/sed/mbcs.c @@ -59,7 +59,8 @@ is_mb_char (int ch, mbstate_t *cur_stat) return 1; default: /* Should never happen, as per mbrtowc(3) documentation */ - panic ("is_mb_char: mbrtowc (0x%x) returned %d",ch,result); + panic ("is_mb_char: mbrtowc (0x%x) returned %d", + (unsigned int) ch, result); } } diff --git a/sed/utils.c b/sed/utils.c index 7990863..8afea8e 100644 --- a/sed/utils.c +++ b/sed/utils.c @@ -189,9 +189,10 @@ ck_fwrite(const void *ptr, size_t size, size_t nmemb, FILE *stream) { clearerr(stream); if (size && fwrite(ptr, size, nmemb, stream) != nmemb) - panic(ngettext("couldn't write %d item to %s: %s", - "couldn't write %d items to %s: %s", nmemb), - nmemb, utils_fp_name(stream), strerror(errno)); + panic(ngettext("couldn't write %llu item to %s: %s", + "couldn't write %llu items to %s: %s", nmemb), + (unsigned long long) nmemb, utils_fp_name(stream), + strerror(errno)); } /* Panic on failing fread */ diff --git a/sed/utils.h b/sed/utils.h index 0b6d211..6b9f8ef 100644 --- a/sed/utils.h +++ b/sed/utils.h @@ -27,7 +27,7 @@ enum exit_codes { }; -_Noreturn void panic (const char *str, ...); +_Noreturn void panic (const char *str, ...) _GL_ATTRIBUTE_FORMAT_PRINTF (1, 2); FILE *ck_fopen (const char *name, const char *mode, int fail); FILE *ck_fdopen (int fd, const char *name, const char *mode, int fail); -- 2.9.3 From ba7cd2126210f05626b771a05c334d76b7c46b79 Mon Sep 17 00:00:00 2001 From: Jim Meyering Date: Sat, 26 Nov 2016 18:35:54 -0800 Subject: [PATCH 4/8] build: avoid "make distcheck" failure due to leftover .Po files The following definitions caused trouble for no gain. They caused some .o file names to have a long additional prefix and even resulted in some .Po files not being removed by "make distclean" when building with recent automake. The only reason to use these definitions was -- long ago -- to require different compiler options for files in lib/ than elsewhere. That is no longer necessary. * lib/local.mk (lib_libsed_a_CPPFLAGS): Remove definition. (lib_libsed_a_CFLAGS, lib_libsed_a_LIBADD): Likewise. (lib_libsed_a_DEPENDENCIES): Likewise. --- lib/local.mk | 7 ------- 1 file changed, 7 deletions(-) diff --git a/lib/local.mk b/lib/local.mk index 9166e63..0d3562f 100644 --- a/lib/local.mk +++ b/lib/local.mk @@ -15,10 +15,3 @@ # include lib/gnulib.mk - -lib_libsed_a_CPPFLAGS = $(AM_CPPFLAGS) -I$(top_srcdir)/lib/ \ - -I$(top_builddir)/lib -lib_libsed_a_CFLAGS = $(AM_CFLAGS) $(GNULIB_WARN_CFLAGS) $(WERROR_CFLAGS) - -lib_libsed_a_LIBADD += $(LIBOBJS) $(ALLOCA) -lib_libsed_a_DEPENDENCIES += $(LIBOBJS) $(ALLOCA) -- 2.9.3 From dc2145f85355f6313f5421127c0f99ef44ee25fe Mon Sep 17 00:00:00 2001 From: Jim Meyering Date: Sat, 26 Nov 2016 18:41:12 -0800 Subject: [PATCH 5/8] build: stop suppressing many -W... warnings This code in configure.ac added many -W options to the list of warnings that we do *not* enable. When I copied most of this code into this file from coreutils, I did not try to remove the options that happened not to be needed for sed. Now, compilers have improved and I have done that triage. Many -W options can be left enabled. * configure.ac (GNULIB_WARN_CFLAGS): There is no longer any need to use a different set of warnings for lib/ files, so remove this variable, along with many -W-related exemptions. --- configure.ac | 53 +---------------------------------------------------- 1 file changed, 1 insertion(+), 52 deletions(-) diff --git a/configure.ac b/configure.ac index ffc0d5e..1b121d9 100644 --- a/configure.ac +++ b/configure.ac @@ -244,37 +244,11 @@ if test "$gl_gcc_warnings" = yes; then nw= # This, $nw, is the list of warnings we disable. nw="$nw -Wdeclaration-after-statement" # too useful to forbid - nw="$nw -Waggregate-return" # anachronistic - nw="$nw -Wlong-long" # C90 is anachronistic (lib/gethrxtime.h) - nw="$nw -Wc++-compat" # We don't care about C++ compilers - nw="$nw -Wundef" # Warns on '#if GNULIB_FOO' etc in gnulib - nw="$nw -Wtraditional" # Warns on #elif which we use often - nw="$nw -Wcast-qual" # Too many warnings for now - nw="$nw -Wconversion" # Too many warnings for now nw="$nw -Wsystem-headers" # Don't let system headers trigger warnings nw="$nw -Wsign-conversion" # Too many warnings for now - nw="$nw -Wtraditional-conversion" # Too many warnings for now - nw="$nw -Wunreachable-code" # Too many warnings for now - nw="$nw -Wpadded" # Our structs are not padded - nw="$nw -Wredundant-decls" # openat.h declares e.g., mkdirat - nw="$nw -Wlogical-op" # Too many warnings until GCC 4.8.0 nw="$nw -Wformat-nonliteral" # who.c and pinky.c strftime uses nw="$nw -Wvla" # warnings in gettext.h - nw="$nw -Wnested-externs" # use of XARGMATCH/verify_function__ - nw="$nw -Wswitch-enum" # Too many warnings for now nw="$nw -Wswitch-default" # Too many warnings for now - nw="$nw -Wstack-protector" # not worth working around - # things I might fix soon: - nw="$nw -Wfloat-equal" # sort.c, seq.c - nw="$nw -Wmissing-format-attribute" # copy.c - nw="$nw -Wunsafe-loop-optimizations" # a few src/*.c - nw="$nw -Winline" # system.h's readdir_ignoring_dot_and_dotdot - nw="$nw -Wsuggest-attribute=format" # warns about copy.c and factor.c - - # Using -Wstrict-overflow is a pain, but the alternative is worse. - # For an example, see the code that provoked this report: - # http://gcc.gnu.org/bugzilla/show_bug.cgi?id=33498 - # Code like that still infloops with gcc-4.6.0 and -O2. Scary indeed. gl_MANYWARN_ALL_GCC([ws]) gl_MANYWARN_COMPLEMENT([ws], [$ws], [$nw]) @@ -282,13 +256,6 @@ if test "$gl_gcc_warnings" = yes; then gl_WARN_ADD([$w]) done gl_WARN_ADD([-Wno-sign-compare]) # Too many warnings for now - gl_WARN_ADD([-Wno-unused-parameter]) # Too many warnings for now - gl_WARN_ADD([-Wno-format-nonliteral]) - - # Enable this warning only with gcc-4.8 and newer. Before that - # bounds checking as done in truncate.c was incorrectly flagged. - # See: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=43772 - gl_GCC_VERSION_IFELSE([4], [8], [gl_WARN_ADD([-Wlogical-op])]) # clang is unduly picky about some things. AC_CACHE_CHECK([whether the compiler is clang], [utils_cv_clang], @@ -320,28 +287,10 @@ if test "$gl_gcc_warnings" = yes; then ]) AC_DEFINE([GNULIB_PORTCHECK], [1], [enable some gnulib portability checks]) - # We use a slightly smaller set of warning options for lib/. - # Remove the following and save the result in GNULIB_WARN_CFLAGS. - nw= - nw="$nw -Wstrict-overflow" - nw="$nw -Wuninitialized" - nw="$nw -Wunused-macros" - nw="$nw -Wmissing-prototypes" - nw="$nw -Wold-style-definition" - # FIXME: it may be easy to remove this, since it affects only one file: - # the snprintf call at ftoastr.c:132. - nw="$nw -Wdouble-promotion" - gl_MANYWARN_COMPLEMENT([GNULIB_WARN_CFLAGS], [$WARN_CFLAGS], [$nw]) - AC_SUBST([GNULIB_WARN_CFLAGS]) - # For gnulib-tests, the set is slightly smaller still. nw= - nw="$nw -Wstrict-prototypes" - # It's not worth being this picky about test programs. - nw="$nw -Wsuggest-attribute=const" - nw="$nw -Wsuggest-attribute=pure" gl_MANYWARN_COMPLEMENT([GNULIB_TEST_WARN_CFLAGS], - [$GNULIB_WARN_CFLAGS], [$nw]) + [$WARN_CFLAGS], [$nw]) AC_SUBST([GNULIB_TEST_WARN_CFLAGS]) fi -- 2.9.3 From 93e9311f29dca6d7a1bf55a6c54731fc1a0a4f91 Mon Sep 17 00:00:00 2001 From: Jim Meyering Date: Sun, 27 Nov 2016 09:21:19 -0800 Subject: [PATCH 6/8] tests: use "returns_ 1" rather than "&& fail=1" * testsuite/colon-with-no-label.sh: Rather than failing only upon success (exit 0), fail upon exit with any value other than 1. --- testsuite/colon-with-no-label.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/testsuite/colon-with-no-label.sh b/testsuite/colon-with-no-label.sh index 1226bb4..42de378 100755 --- a/testsuite/colon-with-no-label.sh +++ b/testsuite/colon-with-no-label.sh @@ -25,7 +25,7 @@ fail=0 # Before sed-4.3, sed would mistakenly accept a ":" with no following # label name. -echo x | sed : > out 2> err && fail=1 +echo x | returns_ 1 sed : > out 2> err || fail=1 compare /dev/null out || fail=1 compare exp-err err || fail=1 -- 2.9.3 From 5af42765d6d2255a04efa4737870f15e11e149a4 Mon Sep 17 00:00:00 2001 From: Jim Meyering Date: Tue, 29 Nov 2016 15:01:41 -0800 Subject: [PATCH 7/8] gnulib: update to latest --- gnulib | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gnulib b/gnulib index e63f5eb..ca3ca77 160000 --- a/gnulib +++ b/gnulib @@ -1 +1 @@ -Subproject commit e63f5eb55570a1ea3e51ce47df33689785e085c1 +Subproject commit ca3ca77fc9e497ff5048a9f1ee0d1acc8e050f51 -- 2.9.3 From 2d426c3711fe3b2325cad8b623575a262ccb3ac6 Mon Sep 17 00:00:00 2001 From: Jim Meyering Date: Tue, 29 Nov 2016 17:14:46 -0800 Subject: [PATCH 8/8] tests: use "returns_ N env VAR=val ..." Use "returns_ N env VAR=val ..." rather than "VAR=val returns_ N ...". Some shells do not propagate envvar settings through our use of the "returns_" function, so set any envvar via use of "env". This was an issue at least on Ubuntu, Debian and *BSD-based systems. * testsuite/mb-bad-delim.sh: As above. * testsuite/mb-y-translate.sh: Likewise. --- testsuite/mb-bad-delim.sh | 4 ++-- testsuite/mb-y-translate.sh | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/testsuite/mb-bad-delim.sh b/testsuite/mb-bad-delim.sh index eb094d3..ac43a49 100755 --- a/testsuite/mb-bad-delim.sh +++ b/testsuite/mb-bad-delim.sh @@ -41,7 +41,7 @@ cat <<\EOF > exp-err1 || framework_failure_ sed: file prog1 line 1: delimiter character is not a single-byte character EOF -LC_ALL=en_US.UTF-8 returns_ 1 sed -f prog1 < /dev/null 2>err1 || fail=1 +returns_ 1 env LC_ALL=en_US.UTF-8 sed -f prog1 < /dev/null 2>err1 || fail=1 compare_ exp-err1 err1 || fail=1 @@ -55,7 +55,7 @@ cat <<\EOF > exp-err2 || framework_failure_ sed: file prog2 line 1: delimiter character is not a single-byte character EOF -LC_ALL=en_US.UTF-8 returns_ 1 sed -f prog2 err2 || fail=1 +returns_ 1 env LC_ALL=en_US.UTF-8 sed -f prog2 err2 || fail=1 compare_ exp-err2 err2 || fail=1 # ... but accept octet \316 as delimiter in C locale diff --git a/testsuite/mb-y-translate.sh b/testsuite/mb-y-translate.sh index df8f37e..a1f59c4 100755 --- a/testsuite/mb-y-translate.sh +++ b/testsuite/mb-y-translate.sh @@ -53,7 +53,7 @@ compare_ exp1 out1 || fail=1 cat <<\EOF > exp-err1 || framework_failure_ sed: file p1 line 1: strings for `y' command are different lengths EOF -LC_ALL=C returns_ 1 sed -f p1 err1 || fail=1 +returns_ 1 env LC_ALL=C sed -f p1 err1 || fail=1 compare_ exp-err1 err1 || fail=1 @@ -71,7 +71,7 @@ compare_ exp2 out2 || fail=1 cat <<\EOF > exp-err2 || framework_failure_ sed: file p2 line 1: strings for `y' command are different lengths EOF -LC_ALL=C returns_ 1 sed -f p2 err2 || fail=1 +returns_ 1 env LC_ALL=C sed -f p2 err2 || fail=1 compare_ exp-err2 err2 || fail=1 @@ -120,7 +120,7 @@ cat <<\EOF > exp-err7 || framework_failure_ sed: file p7 line 1: strings for `y' command are different lengths EOF -LC_ALL=en_US.UTF-8 returns_ 1 sed -f p7 err7 || fail=1 +returns_ 1 env LC_ALL=en_US.UTF-8 sed -f p7 err7 || fail=1 compare_ exp-err7 err7 || fail=1 printf 'y/a/bcd/' > p8 || framework_failure_ @@ -128,7 +128,7 @@ cat <<\EOF > exp-err8 || framework_failure_ sed: file p8 line 1: strings for `y' command are different lengths EOF -LC_ALL=en_US.UTF-8 returns_ 1 sed -f p8 err8 || fail=1 +returns_ 1 env LC_ALL=en_US.UTF-8 sed -f p8 err8 || fail=1 compare_ exp-err8 err8 || fail=1 -- 2.9.3