mirror of
https://github.com/open-simh/simtools.git
synced 2026-01-13 23:36:03 +00:00
Nested delimited strings had an infinite loop.
The code for nested and unnested strings was mixed, thereby being too
simple for the nested case. I separated them, which is simpler than
the fixed combined version.
Detected by the macro call
..EMIT <$FAC=^D<fb$rea>>
This commit is contained in:
parent
749b0a5d73
commit
a8b5272bb8
33
parse.c
33
parse.c
@ -569,10 +569,10 @@ int brackrange(
|
||||
endlen = 1;
|
||||
*start = 1;
|
||||
break;
|
||||
case '/': /* seen on page 6-52 */
|
||||
case '?': /* seen on page 6-52 */
|
||||
case '\\': /* seen on page 6-52 */
|
||||
case '"': /* seen in Kermit-11 source for RT11 */
|
||||
case '/': /* seen on page 6-52 */
|
||||
case '?': /* seen on page 6-52 */
|
||||
case '\\': /* seen on page 6-52 */
|
||||
case '"': /* seen in Kermit-11 source for RT11 */
|
||||
endstr[0] = cp[0];
|
||||
strcpy(endstr + 1, "\n");
|
||||
*start = 1;
|
||||
@ -585,15 +585,28 @@ int brackrange(
|
||||
cp += *start;
|
||||
|
||||
len = 0;
|
||||
nest = 1;
|
||||
while (nest) {
|
||||
if (endstr[1] == '>') { /* <>\n */
|
||||
nest = 1;
|
||||
while (nest) {
|
||||
int sublen;
|
||||
|
||||
sublen = strcspn(cp + len, endstr);
|
||||
if (cp[len + sublen] == '<') {
|
||||
nest++;
|
||||
sublen++; /* avoid infinite loop when sublen == 0 */
|
||||
} else {
|
||||
nest--;
|
||||
if (nest > 0 && cp[len + sublen] == '>')
|
||||
sublen++; /* avoid infinite loop when sublen == 0 */
|
||||
}
|
||||
len += sublen;
|
||||
if (sublen == 0)
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
int sublen;
|
||||
|
||||
sublen = strcspn(cp + len, endstr);
|
||||
if (cp[len + sublen] == '<')
|
||||
nest++;
|
||||
else
|
||||
nest--;
|
||||
len += sublen;
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user