Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 18 May 2017 21:44:14 +0000 (UTC)
From:      Jilles Tjoelker <jilles@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r318501 - head/bin/sh
Message-ID:  <201705182144.v4ILiEOs046856@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: jilles
Date: Thu May 18 21:44:14 2017
New Revision: 318501
URL: https://svnweb.freebsd.org/changeset/base/318501

Log:
  sh: Ensure memout.bufsize matches allocated buffer, if it exists.

Modified:
  head/bin/sh/eval.c
  head/bin/sh/output.c

Modified: head/bin/sh/eval.c
==============================================================================
--- head/bin/sh/eval.c	Thu May 18 21:23:39 2017	(r318500)
+++ head/bin/sh/eval.c	Thu May 18 21:44:14 2017	(r318501)
@@ -1081,8 +1081,6 @@ evalcommand(union node *cmd, int flags, 
 		mode = (cmdentry.u.index == EXECCMD)? 0 : REDIR_PUSH;
 		if (flags == EV_BACKCMD) {
 			memout.nextc = memout.buf;
-			memout.bufend = memout.buf;
-			memout.bufsize = 64;
 			mode |= REDIR_BACKQ;
 		}
 		savecmdname = commandname;
@@ -1139,6 +1137,7 @@ cmddone:
 			memout.buf = NULL;
 			memout.nextc = NULL;
 			memout.bufend = NULL;
+			memout.bufsize = 64;
 		}
 		if (cmdentry.u.index != EXECCMD)
 			popredir();

Modified: head/bin/sh/output.c
==============================================================================
--- head/bin/sh/output.c	Thu May 18 21:23:39 2017	(r318500)
+++ head/bin/sh/output.c	Thu May 18 21:44:14 2017	(r318501)
@@ -73,7 +73,7 @@ static int doformat_wr(void *, const cha
 
 struct output output = {NULL, NULL, NULL, OUTBUFSIZ, 1, 0};
 struct output errout = {NULL, NULL, NULL, 256, 2, 0};
-struct output memout = {NULL, NULL, NULL, 0, MEM_OUT, 0};
+struct output memout = {NULL, NULL, NULL, 64, MEM_OUT, 0};
 struct output *out1 = &output;
 struct output *out2 = &errout;
 
@@ -208,7 +208,7 @@ outbin(const void *data, size_t len, str
 void
 emptyoutbuf(struct output *dest)
 {
-	int offset;
+	int offset, newsize;
 
 	if (dest->buf == NULL) {
 		INTOFF;
@@ -218,10 +218,11 @@ emptyoutbuf(struct output *dest)
 		INTON;
 	} else if (dest->fd == MEM_OUT) {
 		offset = dest->nextc - dest->buf;
+		newsize = dest->bufsize << 1;
 		INTOFF;
-		dest->bufsize <<= 1;
-		dest->buf = ckrealloc(dest->buf, dest->bufsize);
-		dest->bufend = dest->buf + dest->bufsize;
+		dest->buf = ckrealloc(dest->buf, newsize);
+		dest->bufsize = newsize;
+		dest->bufend = dest->buf + newsize;
 		dest->nextc = dest->buf + offset;
 		INTON;
 	} else {



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201705182144.v4ILiEOs046856>