mirror of
https://github.com/zsh-users/zsh
synced 2024-09-29 04:35:22 +00:00
23308: sanity for tindent in text output
This commit is contained in:
parent
738c305a26
commit
24477a7ff4
|
@ -1,6 +1,10 @@
|
||||||
2007-04-23 Peter Stephenson <pws@csr.com>
|
2007-04-23 Peter Stephenson <pws@csr.com>
|
||||||
|
|
||||||
* Christoph Bauer: 23309ish: define _INCLUDE__STDC_A1_SOURCE
|
* 23308: Src/text.c: stop tindent becoming negative, which
|
||||||
|
causes infinite use of memory; add debug test to see where
|
||||||
|
it would become negative.
|
||||||
|
|
||||||
|
* Christoph Bauer: 23310ish: define _INCLUDE__STDC_A1_SOURCE
|
||||||
for HP/UX.
|
for HP/UX.
|
||||||
|
|
||||||
2007-04-21 Clint Adams <clint@zsh.org>
|
2007-04-21 Clint Adams <clint@zsh.org>
|
||||||
|
|
42
Src/text.c
42
Src/text.c
|
@ -33,6 +33,14 @@
|
||||||
static char *tptr, *tbuf, *tlim;
|
static char *tptr, *tbuf, *tlim;
|
||||||
static int tsiz, tindent, tnewlins, tjob;
|
static int tsiz, tindent, tnewlins, tjob;
|
||||||
|
|
||||||
|
static void
|
||||||
|
dec_tindent(void)
|
||||||
|
{
|
||||||
|
DPUTS(tindent == 0, "attempting to decrement tindent below zero");
|
||||||
|
if (tindent > 0)
|
||||||
|
tindent--;
|
||||||
|
}
|
||||||
|
|
||||||
/* add a character to the text buffer */
|
/* add a character to the text buffer */
|
||||||
|
|
||||||
/**/
|
/**/
|
||||||
|
@ -354,7 +362,7 @@ gettext2(Estate state)
|
||||||
state->pc++;
|
state->pc++;
|
||||||
} else {
|
} else {
|
||||||
state->pc = s->u._subsh.end;
|
state->pc = s->u._subsh.end;
|
||||||
tindent--;
|
dec_tindent();
|
||||||
taddnl();
|
taddnl();
|
||||||
taddstr(")");
|
taddstr(")");
|
||||||
stack = 1;
|
stack = 1;
|
||||||
|
@ -371,7 +379,7 @@ gettext2(Estate state)
|
||||||
state->pc++;
|
state->pc++;
|
||||||
} else {
|
} else {
|
||||||
state->pc = s->u._subsh.end;
|
state->pc = s->u._subsh.end;
|
||||||
tindent--;
|
dec_tindent();
|
||||||
taddnl();
|
taddnl();
|
||||||
taddstr("}");
|
taddstr("}");
|
||||||
stack = 1;
|
stack = 1;
|
||||||
|
@ -387,7 +395,7 @@ gettext2(Estate state)
|
||||||
} else
|
} else
|
||||||
stack = 1;
|
stack = 1;
|
||||||
} else {
|
} else {
|
||||||
tindent--;
|
dec_tindent();
|
||||||
stack = 1;
|
stack = 1;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
@ -414,7 +422,7 @@ gettext2(Estate state)
|
||||||
} else {
|
} else {
|
||||||
state->strs = s->u._funcdef.strs;
|
state->strs = s->u._funcdef.strs;
|
||||||
state->pc = s->u._funcdef.end;
|
state->pc = s->u._funcdef.end;
|
||||||
tindent--;
|
dec_tindent();
|
||||||
taddnl();
|
taddnl();
|
||||||
taddstr("}");
|
taddstr("}");
|
||||||
stack = 1;
|
stack = 1;
|
||||||
|
@ -444,7 +452,7 @@ gettext2(Estate state)
|
||||||
taddnl();
|
taddnl();
|
||||||
tpush(code, 1);
|
tpush(code, 1);
|
||||||
} else {
|
} else {
|
||||||
tindent--;
|
dec_tindent();
|
||||||
taddnl();
|
taddnl();
|
||||||
taddstr("done");
|
taddstr("done");
|
||||||
stack = 1;
|
stack = 1;
|
||||||
|
@ -462,7 +470,7 @@ gettext2(Estate state)
|
||||||
taddnl();
|
taddnl();
|
||||||
tpush(code, 1);
|
tpush(code, 1);
|
||||||
} else {
|
} else {
|
||||||
tindent--;
|
dec_tindent();
|
||||||
taddnl();
|
taddnl();
|
||||||
taddstr("done");
|
taddstr("done");
|
||||||
stack = 1;
|
stack = 1;
|
||||||
|
@ -475,14 +483,14 @@ gettext2(Estate state)
|
||||||
tindent++;
|
tindent++;
|
||||||
tpush(code, 0);
|
tpush(code, 0);
|
||||||
} else if (!s->pop) {
|
} else if (!s->pop) {
|
||||||
tindent--;
|
dec_tindent();
|
||||||
taddnl();
|
taddnl();
|
||||||
taddstr("do");
|
taddstr("do");
|
||||||
tindent++;
|
tindent++;
|
||||||
taddnl();
|
taddnl();
|
||||||
s->pop = 1;
|
s->pop = 1;
|
||||||
} else {
|
} else {
|
||||||
tindent--;
|
dec_tindent();
|
||||||
taddnl();
|
taddnl();
|
||||||
taddstr("done");
|
taddstr("done");
|
||||||
stack = 1;
|
stack = 1;
|
||||||
|
@ -498,7 +506,7 @@ gettext2(Estate state)
|
||||||
taddnl();
|
taddnl();
|
||||||
tpush(code, 1);
|
tpush(code, 1);
|
||||||
} else {
|
} else {
|
||||||
tindent--;
|
dec_tindent();
|
||||||
taddnl();
|
taddnl();
|
||||||
taddstr("done");
|
taddstr("done");
|
||||||
stack = 1;
|
stack = 1;
|
||||||
|
@ -536,7 +544,7 @@ gettext2(Estate state)
|
||||||
n->pop = (state->pc - 2 + WC_CASE_SKIP(code) >= end);
|
n->pop = (state->pc - 2 + WC_CASE_SKIP(code) >= end);
|
||||||
}
|
}
|
||||||
} else if (state->pc < s->u._case.end) {
|
} else if (state->pc < s->u._case.end) {
|
||||||
tindent--;
|
dec_tindent();
|
||||||
switch (WC_CASE_TYPE(code)) {
|
switch (WC_CASE_TYPE(code)) {
|
||||||
case WC_CASE_OR:
|
case WC_CASE_OR:
|
||||||
taddstr(" ;;");
|
taddstr(" ;;");
|
||||||
|
@ -564,7 +572,7 @@ gettext2(Estate state)
|
||||||
s->pop = ((state->pc - 2 + WC_CASE_SKIP(code)) >=
|
s->pop = ((state->pc - 2 + WC_CASE_SKIP(code)) >=
|
||||||
s->u._case.end);
|
s->u._case.end);
|
||||||
} else {
|
} else {
|
||||||
tindent--;
|
dec_tindent();
|
||||||
switch (WC_CASE_TYPE(code)) {
|
switch (WC_CASE_TYPE(code)) {
|
||||||
case WC_CASE_OR:
|
case WC_CASE_OR:
|
||||||
taddstr(" ;;");
|
taddstr(" ;;");
|
||||||
|
@ -578,7 +586,7 @@ gettext2(Estate state)
|
||||||
taddstr(";|");
|
taddstr(";|");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
tindent--;
|
dec_tindent();
|
||||||
if (tnewlins)
|
if (tnewlins)
|
||||||
taddnl();
|
taddnl();
|
||||||
else
|
else
|
||||||
|
@ -601,14 +609,14 @@ gettext2(Estate state)
|
||||||
} else if (s->pop) {
|
} else if (s->pop) {
|
||||||
stack = 1;
|
stack = 1;
|
||||||
} else if (s->u._if.cond) {
|
} else if (s->u._if.cond) {
|
||||||
tindent--;
|
dec_tindent();
|
||||||
taddnl();
|
taddnl();
|
||||||
taddstr("then");
|
taddstr("then");
|
||||||
tindent++;
|
tindent++;
|
||||||
taddnl();
|
taddnl();
|
||||||
s->u._if.cond = 0;
|
s->u._if.cond = 0;
|
||||||
} else if (state->pc < s->u._if.end) {
|
} else if (state->pc < s->u._if.end) {
|
||||||
tindent--;
|
dec_tindent();
|
||||||
taddnl();
|
taddnl();
|
||||||
code = *state->pc++;
|
code = *state->pc++;
|
||||||
if (WC_IF_TYPE(code) == WC_IF_ELIF) {
|
if (WC_IF_TYPE(code) == WC_IF_ELIF) {
|
||||||
|
@ -622,7 +630,7 @@ gettext2(Estate state)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
s->pop = 1;
|
s->pop = 1;
|
||||||
tindent--;
|
dec_tindent();
|
||||||
taddnl();
|
taddnl();
|
||||||
taddstr("fi");
|
taddstr("fi");
|
||||||
stack = 1;
|
stack = 1;
|
||||||
|
@ -760,14 +768,14 @@ gettext2(Estate state)
|
||||||
n->u._subsh.end = state->pc + WC_CURSH_SKIP(state->pc[-1]);
|
n->u._subsh.end = state->pc + WC_CURSH_SKIP(state->pc[-1]);
|
||||||
} else if (!s->pop) {
|
} else if (!s->pop) {
|
||||||
state->pc = s->u._subsh.end;
|
state->pc = s->u._subsh.end;
|
||||||
tindent--;
|
dec_tindent();
|
||||||
taddnl();
|
taddnl();
|
||||||
taddstr("} always {");
|
taddstr("} always {");
|
||||||
tindent++;
|
tindent++;
|
||||||
taddnl();
|
taddnl();
|
||||||
s->pop = 1;
|
s->pop = 1;
|
||||||
} else {
|
} else {
|
||||||
tindent--;
|
dec_tindent();
|
||||||
taddnl();
|
taddnl();
|
||||||
taddstr("}");
|
taddstr("}");
|
||||||
stack = 1;
|
stack = 1;
|
||||||
|
|
Loading…
Reference in a new issue