/* Copy leading retained string. */
cspace(&SS, s, re_off, APPEND);
/* Add in regular expression. */
regsub(&SS, s, cp->u.s->new);
/* Move past this match. */
s += match[0].rm_eo;
/* Copy leading retained string. */
cspace(&SS, s, re_off, APPEND);
/* Add in regular expression. */
regsub(&SS, s, cp->u.s->new);
/* Move past this match. */
s += match[0].rm_eo;
- } while(regexec_e(re, s, REG_NOTBOL, 0));
+ } while(*s && re_eoff && regexec_e(re, s, REG_NOTBOL, 0));
+ if (eos - s > 0 && !re_eoff)
+ err(FATAL, "infinite substitution loop");
/* Copy trailing retained string. */
cspace(&SS, s, strlen(s), APPEND);
break;
/* Copy trailing retained string. */
cspace(&SS, s, strlen(s), APPEND);
break;