diff options
author | Alan Somers <asomers@FreeBSD.org> | 2018-02-19 22:09:49 +0000 |
---|---|---|
committer | Alan Somers <asomers@FreeBSD.org> | 2018-02-19 22:09:49 +0000 |
commit | d23662ec2e738098f5af6e978dbd3ea5484fc155 (patch) | |
tree | af62b5dcbfd09852b81155647e2268f5a583803b /usr.bin/tail | |
parent | 88126356cf1a673a94b931fad404398bcf156f85 (diff) | |
download | src-d23662ec2e738098f5af6e978dbd3ea5484fc155.tar.gz src-d23662ec2e738098f5af6e978dbd3ea5484fc155.zip |
Notes
Diffstat (limited to 'usr.bin/tail')
-rw-r--r-- | usr.bin/tail/reverse.c | 7 | ||||
-rwxr-xr-x | usr.bin/tail/tests/tail_test.sh | 44 |
2 files changed, 49 insertions, 2 deletions
diff --git a/usr.bin/tail/reverse.c b/usr.bin/tail/reverse.c index 435623b594ae..422724c0ebab 100644 --- a/usr.bin/tail/reverse.c +++ b/usr.bin/tail/reverse.c @@ -257,10 +257,13 @@ r_buf(FILE *fp, const char *fn) if ((*p == '\n') || start) { struct bfelem *tr; - if (start && llen) + if (llen && start && *p != '\n') WR(p, llen + 1); - else if (llen) + else if (llen) { WR(p + 1, llen); + if (start && *p == '\n') + WR(p, 1); + } tr = TAILQ_NEXT(tl, entries); llen = 0; if (tr != NULL) { diff --git a/usr.bin/tail/tests/tail_test.sh b/usr.bin/tail/tests/tail_test.sh index fddc4ccd998b..d136a0be605e 100755 --- a/usr.bin/tail/tests/tail_test.sh +++ b/usr.bin/tail/tests/tail_test.sh @@ -83,6 +83,49 @@ HERE atf_check cmp expectfile outpipe } +# Regression test for PR 222671 +# https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=222671 +atf_test_case pipe_leading_newline_r +pipe_leading_newline_r_head() +{ + atf_set "descr" "Reverse a pipe whose first character is a newline" +} +pipe_leading_newline_r_body() +{ + cat > expectfile << HERE +3 +2 +1 + +HERE + printf '\n1\n2\n3\n' | tail -r > outfile + printf '\n1\n2\n3\n' | tail -r > outpipe + atf_check cmp expectfile outfile + atf_check cmp expectfile outpipe +} + +atf_test_case file_rc28 +file_rc28_head() +{ + atf_set "descr" "Reverse a file and display the last 28 characters" +} +file_rc28_body() +{ + cat > infile <<HERE +This is the first line +This is the second line +This is the third line +HERE + cat > expectfile << HERE +This is the third line +line +HERE + tail -rc28 infile > outfile + tail -rc28 < infile > outpipe + atf_check cmp expectfile outfile + atf_check cmp expectfile outpipe +} + atf_test_case file_rc28 file_rc28_head() { @@ -235,6 +278,7 @@ atf_init_test_cases() atf_add_test_case file_r atf_add_test_case file_rc28 atf_add_test_case file_rn2 + atf_add_test_case pipe_leading_newline_r # The longfile tests are designed to exercise behavior in r_buf(), # which operates on 128KB blocks atf_add_test_case longfile_r |