Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

input.c and here documents bugfixes



A while ago I reported that here documents with lines longer that 255
characters cause SEGV on Linux.  Then I suspected that the bug is in input.c
(i.e. beta10 doesn't have this bug).  I was right, the patch can be seen
below.  However this doesn't fix all problems with here documents.  Zsh think
that the here-doc. is over when it sees the end mark after a
backslash/newline:

cat << EOF
foo\
EOF
EOF

should print fooEOF.  An other problem (after the input.c bug is fixed or if
vanilla beta10 is used), that if there is an end mark at the 256th position of
a line, zsh will think that the here document is over.  And an evem more
serious problem is that it discards TABs at the 256th position if <<- was
used.

All of these are fixed below.

Bye,
  Zoltan

*** 1.9	1995/09/21 10:30:39
--- Src/exec.c	1995/09/21 10:46:34
***************
*** 1703,1723 ****
  	if (!ingets(pbuf, sizeof(pbuf)))
  	    break;
  	bptr = pbuf;
! 	if (strip)
! 	    while (*bptr == '\t')
! 		bptr++;
! 	for (u = bptr, v = str; *u != '\n' && *v; u++, v++)
! 	    if (*u != *v)
  		break;
! 	if (!(*u == '\n' && !*v)) {
! 	    l = strlen(bptr);
! 	    if (!qt && l > 1 && bptr[l - 1] == '\n' && bptr[l - 2] == '\\')
! 		bptr[l -= 2] = '\0';
! 	    t = realloc(t, siz + l + 1);
! 	    strncpy(t + siz, bptr, l);
! 	    siz += l;
! 	} else
! 	    break;
      }
      t[siz] = '\0';
      if (siz && t[siz - 1] == '\n')
--- 1703,1724 ----
  	if (!ingets(pbuf, sizeof(pbuf)))
  	    break;
  	bptr = pbuf;
! 	if (!siz || t[siz-1] == '\n') {
! 	    if (strip)
! 		while (*bptr == '\t')
! 		    bptr++;
! 	    for (u = bptr, v = str; *u != '\n' && *v; u++, v++)
! 		if (*u != *v)
! 		    break;
! 	    if (*u == '\n' && !*v)
  		break;
! 	}
! 	l = strlen(bptr);
! 	if (!qt && l > 1 && bptr[l - 1] == '\n' && bptr[l - 2] == '\\')
! 	    bptr[l -= 2] = '\0';
! 	t = realloc(t, siz + l + 1);
! 	strncpy(t + siz, bptr, l);
! 	siz += l;
      }
      t[siz] = '\0';
      if (siz && t[siz - 1] == '\n')
*** 1.2	1995/09/19 17:57:52
--- Src/input.c	1995/09/20 11:04:22
***************
*** 274,283 ****
  {
      int l;
  
!     for (l = 0; l < n - 1; l++)
! 	if ((buf[l] = ingetc()) == '\n' || lexstop)
! 	    break;
!     buf[l + (lexstop ? 0 : 1)] = 0;
  
      return (!lexstop || l) ? buf : NULL;
  }
--- 274,283 ----
  {
      int l;
  
!     for (l = 0; l < n - 1 && (buf[l++] = ingetc()) != '\n' && !lexstop;)
!     if (lexstop)
! 	l--;
!     buf[l] = '\0';
  
      return (!lexstop || l) ? buf : NULL;
  }



Messages sorted by: Reverse Date, Date, Thread, Author