From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from krisdoz.my.domain (schwarze@localhost [127.0.0.1]) by krisdoz.my.domain (8.14.5/8.14.5) with ESMTP id s66Ikt0P014432 for ; Sun, 6 Jul 2014 14:46:55 -0400 (EDT) Received: (from schwarze@localhost) by krisdoz.my.domain (8.14.5/8.14.3/Submit) id s66IktdN013008; Sun, 6 Jul 2014 14:46:55 -0400 (EDT) Date: Sun, 6 Jul 2014 14:46:55 -0400 (EDT) Message-Id: <201407061846.s66IktdN013008@krisdoz.my.domain> X-Mailinglist: mdocml-source Reply-To: source@mdocml.bsd.lv MIME-Version: 1.0 From: schwarze@mdocml.bsd.lv To: source@mdocml.bsd.lv Subject: mdocml: Fix expansion of escape sequences with incomplete arguments. X-Mailer: activitymail 1.26, http://search.cpan.org/dist/activitymail/ Content-Type: text/plain; charset=utf-8 Log Message: ----------- Fix expansion of escape sequences with incomplete arguments. * For \* and \n, discard the incomplete arg, expand to empty string. * For \B, discard the incomplete arg, expand to the digit 0. * For \w, use the incomplete arg (behaviour unchanged). Modified Files: -------------- mdocml: roff.c Revision Data ------------- Index: roff.c =================================================================== RCS file: /usr/vhosts/mdocml.bsd.lv/cvs/mdocml/roff.c,v retrieving revision 1.217 retrieving revision 1.218 diff -Lroff.c -Lroff.c -u -p -r1.217 -r1.218 --- roff.c +++ roff.c @@ -500,7 +500,7 @@ roff_res(struct roff *r, char **bufp, si size_t naml; /* actual length of the escape name */ int expand_count; /* to avoid infinite loops */ int npos; /* position in numeric expression */ - int irc; /* return code from roff_evalnum() */ + int arg_complete; /* argument not interrupted by eol */ char term; /* character terminating the escape */ expand_count = 0; @@ -585,10 +585,12 @@ roff_res(struct roff *r, char **bufp, si /* Advance to the end of the name. */ + arg_complete = 1; for (naml = 0; 0 == maxl || naml < maxl; naml++, cp++) { if ('\0' == *cp) { mandoc_msg(MANDOCERR_BADESCAPE, r->parse, ln, (int)(stesc - *bufp), NULL); + arg_complete = 0; break; } if (0 == maxl && *cp == term) { @@ -604,20 +606,25 @@ roff_res(struct roff *r, char **bufp, si switch (stesc[1]) { case '*': - res = roff_getstrn(r, stnam, naml); + if (arg_complete) + res = roff_getstrn(r, stnam, naml); break; case 'B': npos = 0; - irc = roff_evalnum(stnam, &npos, NULL, 0); - ubuf[0] = irc && stnam + npos + 1 == cp - ? '1' : '0'; + ubuf[0] = arg_complete && + roff_evalnum(stnam, &npos, NULL, 0) && + stnam + npos + 1 == cp ? '1' : '0'; ubuf[1] = '\0'; break; case 'n': - (void)snprintf(ubuf, sizeof(ubuf), "%d", - roff_getregn(r, stnam, naml)); + if (arg_complete) + (void)snprintf(ubuf, sizeof(ubuf), "%d", + roff_getregn(r, stnam, naml)); + else + ubuf[0] = '\0'; break; case 'w': + /* use even incomplete args */ (void)snprintf(ubuf, sizeof(ubuf), "%d", 24 * (int)naml); break; -- To unsubscribe send an email to source+unsubscribe@mdocml.bsd.lv