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;
|
mode = (cmdentry.u.index == EXECCMD)? 0 : REDIR_PUSH;
|
||||||
if (flags == EV_BACKCMD) {
|
if (flags == EV_BACKCMD) {
|
||||||
memout.nextc = memout.buf;
|
memout.nextc = memout.buf;
|
||||||
memout.bufend = memout.buf;
|
|
||||||
memout.bufsize = 64;
|
|
||||||
mode |= REDIR_BACKQ;
|
mode |= REDIR_BACKQ;
|
||||||
}
|
}
|
||||||
savecmdname = commandname;
|
savecmdname = commandname;
|
||||||
@ -1139,6 +1137,7 @@ evalcommand(union node *cmd, int flags, struct backcmd *backcmd)
|
|||||||
memout.buf = NULL;
|
memout.buf = NULL;
|
||||||
memout.nextc = NULL;
|
memout.nextc = NULL;
|
||||||
memout.bufend = NULL;
|
memout.bufend = NULL;
|
||||||
|
memout.bufsize = 64;
|
||||||
}
|
}
|
||||||
if (cmdentry.u.index != EXECCMD)
|
if (cmdentry.u.index != EXECCMD)
|
||||||
popredir();
|
popredir();
|
||||||
|
@ -73,7 +73,7 @@ static int doformat_wr(void *, const char *, int);
|
|||||||
|
|
||||||
struct output output = {NULL, NULL, NULL, OUTBUFSIZ, 1, 0};
|
struct output output = {NULL, NULL, NULL, OUTBUFSIZ, 1, 0};
|
||||||
struct output errout = {NULL, NULL, NULL, 256, 2, 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 *out1 = &output;
|
||||||
struct output *out2 = &errout;
|
struct output *out2 = &errout;
|
||||||
|
|
||||||
@ -208,7 +208,7 @@ outbin(const void *data, size_t len, struct output *file)
|
|||||||
void
|
void
|
||||||
emptyoutbuf(struct output *dest)
|
emptyoutbuf(struct output *dest)
|
||||||
{
|
{
|
||||||
int offset;
|
int offset, newsize;
|
||||||
|
|
||||||
if (dest->buf == NULL) {
|
if (dest->buf == NULL) {
|
||||||
INTOFF;
|
INTOFF;
|
||||||
@ -218,10 +218,11 @@ emptyoutbuf(struct output *dest)
|
|||||||
INTON;
|
INTON;
|
||||||
} else if (dest->fd == MEM_OUT) {
|
} else if (dest->fd == MEM_OUT) {
|
||||||
offset = dest->nextc - dest->buf;
|
offset = dest->nextc - dest->buf;
|
||||||
|
newsize = dest->bufsize << 1;
|
||||||
INTOFF;
|
INTOFF;
|
||||||
dest->bufsize <<= 1;
|
dest->buf = ckrealloc(dest->buf, newsize);
|
||||||
dest->buf = ckrealloc(dest->buf, dest->bufsize);
|
dest->bufsize = newsize;
|
||||||
dest->bufend = dest->buf + dest->bufsize;
|
dest->bufend = dest->buf + newsize;
|
||||||
dest->nextc = dest->buf + offset;
|
dest->nextc = dest->buf + offset;
|
||||||
INTON;
|
INTON;
|
||||||
} else {
|
} else {
|
||||||
|
Loading…
Reference in New Issue
Block a user