All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/1] busybox: fix "sed n (flushes pattern space, terminates early)" testcase failure
@ 2016-09-01  9:42 Dengke Du
  2016-09-01  9:42 ` [PATCH 1/1] " Dengke Du
  0 siblings, 1 reply; 2+ messages in thread
From: Dengke Du @ 2016-09-01  9:42 UTC (permalink / raw)
  To: openembedded-core

The following changes since commit 2fedd226c3385f1ac160b3aa0bfadbded85e288c:

  ref-manual: Fixed small wording in PKGR in the glossary (2016-08-25 23:09:29 +0100)

are available in the git repository at:

  git://git.openembedded.org/openembedded-core-contrib dengke/busybox-fix-sed-n-testcase-failure
  http://cgit.openembedded.org/cgit.cgi/openembedded-core-contrib/log/?h=dengke/busybox-fix-sed-n-testcase-failure

Dengke Du (1):
  busybox: fix "sed n (flushes pattern space, terminates early)"
    testcase failure

 ...-n-flushes-pattern-space-terminates-early.patch | 72 ++++++++++++++++++++++
 meta/recipes-core/busybox/busybox_1.24.1.bb        |  1 +
 2 files changed, 73 insertions(+)
 create mode 100644 meta/recipes-core/busybox/busybox/0001-sed-fix-sed-n-flushes-pattern-space-terminates-early.patch

-- 
2.8.1



^ permalink raw reply	[flat|nested] 2+ messages in thread

* [PATCH 1/1] busybox: fix "sed n (flushes pattern space, terminates early)" testcase failure
  2016-09-01  9:42 [PATCH 0/1] busybox: fix "sed n (flushes pattern space, terminates early)" testcase failure Dengke Du
@ 2016-09-01  9:42 ` Dengke Du
  0 siblings, 0 replies; 2+ messages in thread
From: Dengke Du @ 2016-09-01  9:42 UTC (permalink / raw)
  To: openembedded-core

It is a busybox upstream known bug. When the busybox sed sub-command 'n'
hit the files EOF, it print an extra character that have been printed, but
the GNU sed would not print it.

In busybox source code ../editors/sed.c
------------------------------------------------------------------------
    case 'n':
        if (!G.be_quiet)
                sed_puts(pattern_space, last_gets_char);
            if (next_line) {
                    free(pattern_space);
                    pattern_space = next_line;
                    last_gets_char = next_gets_char;
                    next_line = get_next_line(&next_gets_char, &last_puts_char, last_gets_char);
                    substituted = 0;
                    linenum++;
                    break;
            }
            /* fall through */

    /* Quit.  End of script, end of input. */
    case 'q':
        /* Exit the outer while loop */
            free(next_line);
            next_line = NULL;
            goto discard_commands;
------------------------------------------------------------------------
when read at the end of the file, the 'next_line' is null, it would go
"case 'q'" and goto discard_commands, the discard_commands would print
the old pattern space which have been printed.

So in order to comply with GNU sed, in case 'n', when the next_line is null
I add "else" at the end of the second "if": "goto again;" and send it to
the busybox upstream, the busybox maintainer adopt it and make a little
changes to the patch, we can see it at:

His reply:

	http://lists.busybox.net/pipermail/busybox/2016-September/084613.html

The new patch on busybox master branch:

	https://git.busybox.net/busybox/commit/?id=76d72376e0244a5cafd4880cdc623e37d86a75e4

Signed-off-by: Dengke Du <dengke.du@windriver.com>
---
 ...-n-flushes-pattern-space-terminates-early.patch | 72 ++++++++++++++++++++++
 meta/recipes-core/busybox/busybox_1.24.1.bb        |  1 +
 2 files changed, 73 insertions(+)
 create mode 100644 meta/recipes-core/busybox/busybox/0001-sed-fix-sed-n-flushes-pattern-space-terminates-early.patch

diff --git a/meta/recipes-core/busybox/busybox/0001-sed-fix-sed-n-flushes-pattern-space-terminates-early.patch b/meta/recipes-core/busybox/busybox/0001-sed-fix-sed-n-flushes-pattern-space-terminates-early.patch
new file mode 100644
index 0000000..4f53984
--- /dev/null
+++ b/meta/recipes-core/busybox/busybox/0001-sed-fix-sed-n-flushes-pattern-space-terminates-early.patch
@@ -0,0 +1,72 @@
+From 903542f7331c58007a3ef938d41e1c55fc329648 Mon Sep 17 00:00:00 2001
+From: Dengke Du <dengke.du@windriver.com>
+Date: Wed, 31 Aug 2016 23:40:43 -0400
+Subject: [PATCH] sed: fix "sed n (flushes pattern space, terminates early)"
+ testcase failure
+
+This patch fix "sed n (flushes pattern space, terminates early)"
+testcase failure. We can see it at:
+
+	https://git.busybox.net/busybox/commit/?id=76d72376e0244a5cafd4880cdc623e37d86a75e4
+
+Upstream-Status: Backport
+
+Signed-off-by: Dengke Du <dengke.du@windriver.com>
+---
+ editors/sed.c       | 19 ++++++++++---------
+ testsuite/sed.tests |  6 +-----
+ 2 files changed, 11 insertions(+), 14 deletions(-)
+
+diff --git a/editors/sed.c b/editors/sed.c
+index 7bbf820..259c39c 100644
+--- a/editors/sed.c
++++ b/editors/sed.c
+@@ -1274,16 +1274,17 @@ static void process_files(void)
+ 		case 'n':
+ 			if (!G.be_quiet)
+ 				sed_puts(pattern_space, last_gets_char);
+-			if (next_line) {
+-				free(pattern_space);
+-				pattern_space = next_line;
+-				last_gets_char = next_gets_char;
+-				next_line = get_next_line(&next_gets_char, &last_puts_char, last_gets_char);
+-				substituted = 0;
+-				linenum++;
+-				break;
++			if (next_line == NULL) {
++				/* If no next line, jump to end of script and exit. */
++				goto discard_line;
+ 			}
+-			/* fall through */
++			free(pattern_space);
++			pattern_space = next_line;
++			last_gets_char = next_gets_char;
++			next_line = get_next_line(&next_gets_char, &last_puts_char, last_gets_char);
++			substituted = 0;
++			linenum++;
++			break;
+ 
+ 		/* Quit.  End of script, end of input. */
+ 		case 'q':
+diff --git a/testsuite/sed.tests b/testsuite/sed.tests
+index 34479e5..96ff7a5 100755
+--- a/testsuite/sed.tests
++++ b/testsuite/sed.tests
+@@ -73,13 +73,9 @@ testing "sed t (test/branch clears test bit)" "sed -e 's/a/b/;:loop;t loop'" \
+ testing "sed T (!test/branch)" "sed -e 's/a/1/;T notone;p;: notone;p'" \
+ 	"1\n1\n1\nb\nb\nc\nc\n" "" "a\nb\nc\n"
+ 
+-test x"$SKIP_KNOWN_BUGS" = x"" && {
+-# Normal sed end-of-script doesn't print "c" because n flushed the pattern
+-# space.  If n hits EOF, pattern space is empty when script ends.
+-# Query: how does this interact with no newline at EOF?
+ testing "sed n (flushes pattern space, terminates early)" "sed -e 'n;p'" \
+ 	"a\nb\nb\nc\n" "" "a\nb\nc\n"
+-}
++
+ # non-GNU sed: N does _not_ flush pattern space, therefore c is eaten @ script end
+ # GNU sed: N flushes pattern space, therefore c is printed too @ script end
+ testing "sed N (flushes pattern space (GNU behavior))" "sed -e 'N;p'" \
+-- 
+2.8.1
+
diff --git a/meta/recipes-core/busybox/busybox_1.24.1.bb b/meta/recipes-core/busybox/busybox_1.24.1.bb
index e8265cd..f370451 100644
--- a/meta/recipes-core/busybox/busybox_1.24.1.bb
+++ b/meta/recipes-core/busybox/busybox_1.24.1.bb
@@ -50,6 +50,7 @@ SRC_URI = "http://www.busybox.net/downloads/busybox-${PV}.tar.bz2;name=tarball \
            file://ip_fix_problem_on_mips64_n64_big_endian_musl_systems.patch \
            file://makefile-fix-backport.patch \
            file://parallel-make-fix.patch \
+           file://0001-sed-fix-sed-n-flushes-pattern-space-terminates-early.patch \
 "
 SRC_URI_append_libc-musl = " file://musl.cfg "
 
-- 
2.8.1



^ permalink raw reply related	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2016-09-01  9:42 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-09-01  9:42 [PATCH 0/1] busybox: fix "sed n (flushes pattern space, terminates early)" testcase failure Dengke Du
2016-09-01  9:42 ` [PATCH 1/1] " Dengke Du

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.