From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp1.rz.uni-karlsruhe.de (Debian-exim@smtp1.rz.uni-karlsruhe.de [129.13.185.217]) by krisdoz.my.domain (8.14.3/8.14.3) with ESMTP id p0MMxYj3030743 for ; Sat, 22 Jan 2011 17:59:35 -0500 (EST) Received: from hekate.usta.de (asta-nat.asta.uni-karlsruhe.de [172.22.63.82]) by smtp1.rz.uni-karlsruhe.de with esmtp (Exim 4.63 #1) id 1PgmQf-0006gg-Mv; Sat, 22 Jan 2011 23:59:33 +0100 Received: from donnerwolke.usta.de ([172.24.96.3]) by hekate.usta.de with esmtp (Exim 4.72) (envelope-from ) id 1PgmQf-0001ZX-LN for tech@mdocml.bsd.lv; Sat, 22 Jan 2011 23:59:33 +0100 Received: from iris.usta.de ([172.24.96.5] helo=usta.de) by donnerwolke.usta.de with esmtp (Exim 4.69) (envelope-from ) id 1PgmQf-0005ob-KO for tech@mdocml.bsd.lv; Sat, 22 Jan 2011 23:59:33 +0100 Received: from schwarze by usta.de with local (Exim 4.72) (envelope-from ) id 1PgmQf-0005wf-Jg for tech@mdocml.bsd.lv; Sat, 22 Jan 2011 23:59:33 +0100 Date: Sat, 22 Jan 2011 23:59:33 +0100 From: Ingo Schwarze To: tech@mdocml.bsd.lv Subject: Re: line termination in manuals Message-ID: <20110122225933.GL12520@iris.usta.de> References: <20110122195656.GE12520@iris.usta.de> <20110122200516.GA26592@britannica.bec.de> <20110122212814.GH12520@iris.usta.de> <20110122213510.GA29547@britannica.bec.de> <20110122221836.GJ12520@iris.usta.de> <20110122222938.GA30488@britannica.bec.de> X-Mailinglist: mdocml-tech Reply-To: tech@mdocml.bsd.lv MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20110122222938.GA30488@britannica.bec.de> User-Agent: Mutt/1.5.21 (2010-09-15) Hi, Kristaps Dzonsons wrote on Sat, Jan 22, 2011 at 11:28:11PM +0100: > Has somebody checked whether groff accepts these in the same way? It does. Joerg Sonnenberger wrote on Sat, Jan 22, 2011 at 11:29:38PM +0100: > On Sat, Jan 22, 2011 at 11:18:36PM +0100, Ingo Schwarze wrote: >> When the last character in blk.buf is '\r' (without a newline >> at the end of the file), my first attempt would have overrun >> the buffer by one byte. > Right. What about the same condition for the first if? Has anybody mentioned that handling of null-terminated strings is less error-prone than of buffers with a length, because there is the null at the end and you don't that easily overrun? Joerg, you are right, and not only that, the bounds check was off by one as well. Checking i+1 < sz and then accessing buf[i+2] is not smart. Maybe i should write poems instead, or something. Sigh, Ingo Index: main.c =================================================================== RCS file: /cvs/src/usr.bin/mandoc/main.c,v retrieving revision 1.69 diff -u -r1.69 main.c --- main.c 20 Jan 2011 21:33:11 -0000 1.69 +++ main.c 22 Jan 2011 22:49:00 -0000 @@ -669,6 +669,16 @@ } while (i < (int)blk.sz && (start || '\0' != blk.buf[i])) { + + /* + * When finding an unescaped newline character, + * leave the character loop to process the line. + * Skip a preceding carriage return, if any. + */ + + if ('\r' == blk.buf[i] && i + 1 < (int)blk.sz && + '\n' == blk.buf[i + 1]) + ++i; if ('\n' == blk.buf[i]) { ++i; ++lnn; @@ -703,11 +713,18 @@ continue; } - /* Found escape & at least one other char. */ + /* + * Found escape and at least one other character. + * When it's a newline character, skip it. + * When there is a carriage return in between, + * skip that one as well. + */ + if ('\r' == blk.buf[i + 1] && i + 2 < (int)blk.sz && + '\n' == blk.buf[i + 2]) + ++i; if ('\n' == blk.buf[i + 1]) { i += 2; - /* Escaped newlines are skipped over */ ++lnn; continue; } -- To unsubscribe send an email to tech+unsubscribe@mdocml.bsd.lv