Module Name: src
Committed By: riz
Date: Wed Nov 2 19:31:21 UTC 2011
Modified Files:
src/bin/sh [netbsd-5]: expand.c
Log Message:
Pull up following revision(s) (requested by christos in ticket #1665):
bin/sh/expand.c: revision 1.85
PR/45269: Andreas Gustafsson: Instead of falling off the edge when eating
trailing newlines
if the block has moved, arrange so that trailing newlines are never placed in
the string
in the first place, by accumulating them and adding them only after we've
encountered a
non-newline character. This allows also for more efficient appending since we
know how much
we need beforehand. From FreeBSD.
To generate a diff of this commit:
cvs rdiff -u -r1.79 -r1.79.2.1 src/bin/sh/expand.c
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
Modified files:
Index: src/bin/sh/expand.c
diff -u src/bin/sh/expand.c:1.79 src/bin/sh/expand.c:1.79.2.1
--- src/bin/sh/expand.c:1.79 Thu Oct 16 17:58:29 2008
+++ src/bin/sh/expand.c Wed Nov 2 19:31:19 2011
@@ -1,4 +1,4 @@
-/* $NetBSD: expand.c,v 1.79 2008/10/16 17:58:29 dholland Exp $ */
+/* $NetBSD: expand.c,v 1.79.2.1 2011/11/02 19:31:19 riz Exp $ */
/*-
* Copyright (c) 1991, 1993
@@ -37,7 +37,7 @@
#if 0
static char sccsid[] = "@(#)expand.c 8.5 (Berkeley) 5/15/95";
#else
-__RCSID("$NetBSD: expand.c,v 1.79 2008/10/16 17:58:29 dholland Exp $");
+__RCSID("$NetBSD: expand.c,v 1.79.2.1 2011/11/02 19:31:19 riz Exp $");
#endif
#endif /* not lint */
@@ -425,6 +425,7 @@ expbackq(union node *cmd, int quoted, in
char const *syntax = quoted? DQSYNTAX : BASESYNTAX;
int saveherefd;
int quotes = flag & (EXP_FULL | EXP_CASE);
+ int nnl;
INTOFF;
saveifs = ifsfirst;
@@ -442,6 +443,7 @@ expbackq(union node *cmd, int quoted, in
p = in.buf;
lastc = '\0';
+ nnl = 0;
for (;;) {
if (--in.nleft < 0) {
if (in.fd < 0)
@@ -455,17 +457,21 @@ expbackq(union node *cmd, int quoted, in
}
lastc = *p++;
if (lastc != '\0') {
- if (quotes && syntax[(int)lastc] == CCTL)
- STPUTC(CTLESC, dest);
- STPUTC(lastc, dest);
+ if (lastc == '\n')
+ nnl++;
+ else {
+ CHECKSTRSPACE(nnl + 2, dest);
+ while (nnl > 0) {
+ nnl--;
+ USTPUTC('\n', dest);
+ }
+ if (quotes && syntax[(int)lastc] == CCTL)
+ USTPUTC(CTLESC, dest);
+ USTPUTC(lastc, dest);
+ }
}
}
- /* Eat all trailing newlines */
- p = stackblock() + startloc;
- while (dest > p && dest[-1] == '\n')
- STUNPUTC(dest);
-
if (in.fd >= 0)
close(in.fd);
if (in.buf)