diff options
author | Denys Vlasenko <vda.linux@googlemail.com> | 2016-09-01 01:59:11 +0200 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2016-09-01 01:59:11 +0200 |
commit | 76d72376e0244a5cafd4880cdc623e37d86a75e4 (patch) | |
tree | 30335e94c8585150c89e5bab1d02986422fea4de /editors | |
parent | 9ff910de6be59eec120158de0b4721701877a9b1 (diff) |
sed: fix "sed n (flushes pattern space, terminates early)" testcase failure
Patch based on work by Dengke Du <dengke.du@windriver.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'editors')
-rw-r--r-- | editors/sed.c | 19 |
1 files changed, 10 insertions, 9 deletions
diff --git a/editors/sed.c b/editors/sed.c index c0d79cc7b..b7add1fb1 100644 --- a/editors/sed.c +++ b/editors/sed.c @@ -1300,16 +1300,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); - 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); + substituted = 0; + linenum++; + break; /* Quit. End of script, end of input. */ case 'q': |