=================================================================== RCS file: /cvs/texi2mdoc/main.c,v retrieving revision 1.68 retrieving revision 1.69 diff -u -p -r1.68 -r1.69 --- texi2mdoc/main.c 2015/03/12 10:44:34 1.68 +++ texi2mdoc/main.c 2015/03/13 08:07:33 1.69 @@ -1,4 +1,4 @@ -/* $Id: main.c,v 1.68 2015/03/12 10:44:34 kristaps Exp $ */ +/* $Id: main.c,v 1.69 2015/03/13 08:07:33 kristaps Exp $ */ /* * Copyright (c) 2015 Kristaps Dzonsons * @@ -607,9 +607,17 @@ domacro(struct texi *p, enum texicmd cmd, size_t *pos) m.key[end - start] = '\0'; m.args = argparse(p, pos, &m.argsz, 0); + if (*pos == BUFSZ(p)) { + texiwarn(p, "unexpected EOF"); + return; + } /* Note: we advance to the beginning of the macro. */ advanceeoln(p, pos, 1); + if ((start = *pos) == BUFSZ(p)) { + texiwarn(p, "unexpected EOF"); + return; + } /* * According to the Texinfo manual, the macro ends on the @@ -622,7 +630,6 @@ domacro(struct texi *p, enum texicmd cmd, size_t *pos) * @end macro without the leading newline else we might look * past empty macros. */ - start = *pos; endtok = "@end macro\n"; endtoksz = strlen(endtok); blk = memmem(&BUF(p)[start], BUFSZ(p) - start, endtok, endtoksz); @@ -1526,7 +1533,10 @@ doprintindex(struct texi *p, enum texicmd cmd, size_t } advance(p, pos); - if (0 == (len = end - start)) { + if (*pos == BUFSZ(p)) { + texiwarn(p, "unexpected EOF"); + return; + } else if (0 == (len = end - start)) { texiwarn(p, "zero-length index"); return; } @@ -1672,7 +1682,7 @@ domenu(struct texi *p, enum texicmd cmd, size_t *pos) while (*pos < BUFSZ(p)) { while (*pos < BUFSZ(p) && isws(BUF(p)[*pos])) advance(p, pos); - if ('*' != BUF(p)[*pos]) { + if (*pos < BUFSZ(p) && '*' != BUF(p)[*pos]) { if (TEXICMD_END == peeklinecmd(p, *pos)) break; parseeoln(p, pos); @@ -1695,7 +1705,10 @@ domenu(struct texi *p, enum texicmd cmd, size_t *pos) p->seenws = *pos < BUFSZ(p) && isws(BUF(p)[*pos]); while (*pos < BUFSZ(p) && isws(BUF(p)[*pos])) advance(p, pos); - if ('*' != BUF(p)[*pos]) { + if (*pos == BUFSZ(p)) { + texiwarn(p, "unexpected EOF"); + return; + } else if ('*' != BUF(p)[*pos]) { tcmd = peeklinecmd(p, *pos); if (TEXICMD_END == tcmd) break; @@ -1714,6 +1727,10 @@ domenu(struct texi *p, enum texicmd cmd, size_t *pos) while (*pos < BUFSZ(p) && ':' != BUF(p)[*pos]) advance(p, pos); entrynameend = *pos; + if (*pos == BUFSZ(p)) { + texiwarn(p, "unexpected EOF"); + return; + } advance(p, pos); p->seenvs = 0;