Configuration Information [Automatically generated, do not change]:
Machine: x86_64
OS: darwin20.6.0
Compiler: gcc
Compilation CFLAGS: -g -O2
uname output: Darwin macspear 20.6.0 Darwin Kernel Version 20.6.0: Tue Apr 19 2$
Machine Type: x86_64-apple-darwin20.6.0

Bash Version: 5.2
Patch Level: 0
Release Status: rc3

Description:
    examples/loadables/cut.c uses zgetline, which includes the newline
    delimiter in the line it reads, but the rest of the code expects the
    line to not contain the newline.

Repeat-By:
    $ ./bash -c 'enable -f examples/loadables/cut cut ; cut -c4-' <<< 
$'abcdef\nghijkl'
    def
    
    jkl
    
    $

Fix:
    Strip off the newline right after reading the line.  Attached patch
    fixes the problem.
diff --git a/examples/loadables/cut.c b/examples/loadables/cut.c
index ed4972d2..280c5231 100644
--- a/examples/loadables/cut.c
+++ b/examples/loadables/cut.c
@@ -417,6 +417,8 @@ cutfile (v, list, ops)
       while ((n = zgetline (fd, &line, &llen, '\n', unbuffered_read)) != -1)
        {
          QUIT;
+         if (line[n] == '\n')
+           line[n] = '\0';
          cutline (v, line, ops);               /* can modify line */
        }
       if (fd > 0)

Reply via email to