sh: Ensure memout.bufsize matches allocated buffer, if it exists.
This commit is contained in:
parent
980e53a299
commit
de29cd0869
@ -1081,8 +1081,6 @@ evalcommand(union node *cmd, int flags, struct backcmd *backcmd)
|
||||
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 @@ evalcommand(union node *cmd, int flags, struct backcmd *backcmd)
|
||||
memout.buf = NULL;
|
||||
memout.nextc = NULL;
|
||||
memout.bufend = NULL;
|
||||
memout.bufsize = 64;
|
||||
}
|
||||
if (cmdentry.u.index != EXECCMD)
|
||||
popredir();
|
||||
|
@ -73,7 +73,7 @@ static int doformat_wr(void *, const char *, int);
|
||||
|
||||
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, struct output *file)
|
||||
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 {
|
||||
|
Loading…
Reference in New Issue
Block a user