]> git.cameronkatri.com Git - mandoc.git/log
mandoc.git
9 years agoBring .Pp/.Lp handling inside .Nm blocks closer to groff;
Ingo Schwarze [Tue, 3 Feb 2015 00:48:47 +0000 (00:48 +0000)]
Bring .Pp/.Lp handling inside .Nm blocks closer to groff;
as a bonus, get rid of another call to rew_sub().

9 years agoSimplify and reindent make_pending(). No functional change
Ingo Schwarze [Mon, 2 Feb 2015 19:23:23 +0000 (19:23 +0000)]
Simplify and reindent make_pending().  No functional change
except that some error messages become less confusing.
Now the function is almost readable (but still requires
nineteen lines of comments for fourteen lines of code).

9 years agoSimplify: Do not call rew_dohalt() from make_pending(),
Ingo Schwarze [Mon, 2 Feb 2015 18:26:32 +0000 (18:26 +0000)]
Simplify: Do not call rew_dohalt() from make_pending(),
the calling macro handler already found the breaking block.
No functional change except tiny variations in error messages.

9 years agoGet rid of all remaining calls to rew_sub() where the target block
Ingo Schwarze [Mon, 2 Feb 2015 15:02:49 +0000 (15:02 +0000)]
Get rid of all remaining calls to rew_sub() where the target block
is known.  This only leaves three that do actual searching.
No functional change, minus 30 lines of code.

9 years agoGet rid of all calls to rew_sub() in blk_exp_close(); only ten calls
Ingo Schwarze [Mon, 2 Feb 2015 04:26:44 +0000 (04:26 +0000)]
Get rid of all calls to rew_sub() in blk_exp_close(); only ten calls
remain in other functions.  As a bonus, this fixes an assertion failure
jsg@ found some time ago with afl (test case 982) and improves minor
details in error reporting.

9 years agoWhen a full block macro gets closed out by a mismatching
Ingo Schwarze [Mon, 2 Feb 2015 04:04:45 +0000 (04:04 +0000)]
When a full block macro gets closed out by a mismatching
block closure macro it calls, do not attempt to open its body.
This can for example happen for (nonsensical) constructions like
.Fo
.Nm Fc
in the SYNOPSIS.  Fixing an assertion failure jsg@ found with afl
some time ago (test case number 731).

9 years agoget rid of rew_sub() in blk_part_imp(); no functional change
Ingo Schwarze [Sun, 1 Feb 2015 23:56:37 +0000 (23:56 +0000)]
get rid of rew_sub() in blk_part_imp(); no functional change

9 years agofix .Eo/.Ec spacing
Ingo Schwarze [Sun, 1 Feb 2015 23:10:35 +0000 (23:10 +0000)]
fix .Eo/.Ec spacing

9 years agoSimplify blk_part_exp(), no functional change.
Ingo Schwarze [Sun, 1 Feb 2015 17:30:45 +0000 (17:30 +0000)]
Simplify blk_part_exp(), no functional change.
* Replace calls to rew_sub() with rew_last() - two less out of 18.
* No need to keep track of the body, it's always opened right after
the head and never used for anything in this function.

9 years agoThe function rew_sub() tries to rewind any all all kinds of blocks
Ingo Schwarze [Sun, 1 Feb 2015 16:47:39 +0000 (16:47 +0000)]
The function rew_sub() tries to rewind any all all kinds of blocks
and elements under any and all circumstances, even handling some
bad block nesting now and then.  Little surprisingly, this ends up
in excessive complexity and has caused many bugs in the past.
Start to slowly disentangle this mess by replacing calls to rew_sub()
immediately following mdoc_head_alloc() by the much simpler rew_last().
Gets rid of the first two rew_sub() calls out of twenty.
No functional change.

9 years agoUse relative offsets instead of absolute pointers for the terminal
Ingo Schwarze [Sat, 31 Jan 2015 00:12:41 +0000 (00:12 +0000)]
Use relative offsets instead of absolute pointers for the terminal
font stack.  The latter fail after the stack is grown with realloc().
Fixing an assertion failure found by jsg@ with afl some time ago
(test case number 51).

9 years agoHave pity on the poor stack.
Ingo Schwarze [Fri, 30 Jan 2015 22:04:44 +0000 (22:04 +0000)]
Have pity on the poor stack.
Replace tail recursion by iteration when walking the syntax trees.
No functional change.

9 years agostarting a tbl(7) breaks man(7) next-line scope;
Ingo Schwarze [Fri, 30 Jan 2015 21:28:46 +0000 (21:28 +0000)]
starting a tbl(7) breaks man(7) next-line scope;
triggered by a bug report from jsg@

9 years agoDelete the redundant tbl span flags, just inspect the actual data
Ingo Schwarze [Fri, 30 Jan 2015 17:32:16 +0000 (17:32 +0000)]
Delete the redundant tbl span flags, just inspect the actual data
where needed, which is less fragile.
This fixes a subtle NULL pointer access to tp->tbl.cols:
Due to a bug in the man(7) parser, the first span of a table can
end up in a .TP head, in which case tblcalc() was never called.
Found by jsg@ with afl.

9 years agoAbolish struct tbl_head and replace it by an "int col" member in
Ingo Schwarze [Fri, 30 Jan 2015 04:11:50 +0000 (04:11 +0000)]
Abolish struct tbl_head and replace it by an "int col" member in
struct tbl_cell.  No functional change, minus 40 lines of code.

9 years agoAuditing the tbl(7) code for more NULL pointer accesses, i came out
Ingo Schwarze [Fri, 30 Jan 2015 02:09:04 +0000 (02:09 +0000)]
Auditing the tbl(7) code for more NULL pointer accesses, i came out
empty-handed; so this is just KNF and some code simplifications,
no functional change.

9 years agoMake sure every layout line contains at least one cell;
Ingo Schwarze [Fri, 30 Jan 2015 00:29:30 +0000 (00:29 +0000)]
Make sure every layout line contains at least one cell;
fixing a NULL pointer access in term_tbl() that jsg@ found with afl.

9 years agocorrectly handle table layout lines starting with a dot
Ingo Schwarze [Fri, 30 Jan 2015 00:19:46 +0000 (00:19 +0000)]
correctly handle table layout lines starting with a dot

9 years agoRadical cleanup of COMPATIBILITY sections:
Ingo Schwarze [Thu, 29 Jan 2015 00:33:57 +0000 (00:33 +0000)]
Radical cleanup of COMPATIBILITY sections:
Remove lots of lies, dozens of irrelevant implementation details,
and all references to groff versions older than 1.17.  Move relevant
information to the pages where it belongs, and out of mandoc(1) in
particular.  Add some missing general remarks to roff(7), where it
fits the character and purpose of the page much better.

9 years agoClean up eqn(7) error handling:
Ingo Schwarze [Wed, 28 Jan 2015 21:11:53 +0000 (21:11 +0000)]
Clean up eqn(7) error handling:
* When "define" fails, do not drop the whole equation.
* Free memory after "undef".
* Use standard mandoc error types instead of rolling our own.
* Delete obfuscating EQN_MSG() macro.
* Add function prototypes while here.

9 years ago* Polish tbl(7) error reporting.
Ingo Schwarze [Wed, 28 Jan 2015 17:32:07 +0000 (17:32 +0000)]
* Polish tbl(7) error reporting.
* Do not print out macro names in tbl(7) data blocks.
* Like with GNU tbl, let empty tables cause a blank line.
* Avoid producing empty tables in -Tman.

9 years agoFor now, it can't be helped that mandoc tbl(7) ignores high-level macros,
Ingo Schwarze [Wed, 28 Jan 2015 15:03:45 +0000 (15:03 +0000)]
For now, it can't be helped that mandoc tbl(7) ignores high-level macros,
but stop throwing away their arguments.  This fixes information loss in a
handful of Xenocara manuals, at the price of a small amount of formatting
noise creeping through.

9 years agoimplement the tbl(7) "center" layout option
Ingo Schwarze [Wed, 28 Jan 2015 04:19:35 +0000 (04:19 +0000)]
implement the tbl(7) "center" layout option

9 years agoadjust formatting for the tbl(7) layout 'x' modifier (maximize column)
Ingo Schwarze [Wed, 28 Jan 2015 02:23:49 +0000 (02:23 +0000)]
adjust formatting for the tbl(7) layout 'x' modifier (maximize column)
to match groff for up to six maximized columns

9 years agoMultiple parser and formatter fixes for line drawing in tbl(7).
Ingo Schwarze [Tue, 27 Jan 2015 05:21:44 +0000 (05:21 +0000)]
Multiple parser and formatter fixes for line drawing in tbl(7).
* Allow mixing vertical line bars with the layout options
of the preceding layout cell.
* Correctly combine box options with layout lines.
* Correctly print vertical lines in data rows, with the right spacing.
* Correctly print cross markers and left and right ends of
horizontal lines even if vertical lines differ above and below.
* Avoid the bogus error message "no table data cells"
when a table data section starts with a horizontal line.
No increase in code size.

9 years agoRework tbl(7) layout parsing:
Ingo Schwarze [Mon, 26 Jan 2015 18:42:30 +0000 (18:42 +0000)]
Rework tbl(7) layout parsing:
* Continue parsing even if part of the input is invalid.
* Do not require whitespace between cell specifications.
* Allow tabs as well as blanks between modifiers.
* Mark the 'm' modifier as unsupported.
* Parse and ignore the 'p' and 'v' modifiers.
* Better warning and error messages.
* Get rid of a static buffer.
Improved functionality but minus 50 lines of code.

9 years agoMore improvements regarding tbl(7) options.
Ingo Schwarze [Mon, 26 Jan 2015 13:03:48 +0000 (13:03 +0000)]
More improvements regarding tbl(7) options.
* Treat "allbox" as an alias for "box" for now.
* Parse and ignore the GNU tbl "nowarn" option.
* For separation, allow spaces, tabs, and commas only.
* Mark eqn(7) within tbl(7) as unsupported.
* Simplify the option table.
* Improve and sort documentation.

9 years agoImprove (or rather, rewrite) tbl(7) option parsing.
Ingo Schwarze [Mon, 26 Jan 2015 00:57:22 +0000 (00:57 +0000)]
Improve (or rather, rewrite) tbl(7) option parsing.
* Allow the layout to start after the semicolon on the options line.
* Ignore leading commas.
* Option arguments cannot contain closing parentheses.
* Avoid needless UNSUPP messages.
* Better ERROR reporting.
* Delete unused "linesize" field in struct tbl_opts.
* No need for static buffers.
* Garbage collect one almost empty wrapper function.
Improved functionality, but minus 40 lines of code.

9 years agopreserve .PP before .RE; effect found in audio/pms(1)
Ingo Schwarze [Sat, 24 Jan 2015 10:08:53 +0000 (10:08 +0000)]
preserve .PP before .RE; effect found in audio/pms(1)

9 years agoStrangely, ignoring the roff(7) .na request was implemented in the man(7)
Ingo Schwarze [Sat, 24 Jan 2015 02:41:49 +0000 (02:41 +0000)]
Strangely, ignoring the roff(7) .na request was implemented in the man(7)
parser.  Simplify the code by moving it into the roff(7) parser, also
making it work for mdoc(7).

9 years agochange .Cm to .Ar for macro arguments
Ingo Schwarze [Sat, 24 Jan 2015 02:14:46 +0000 (02:14 +0000)]
change .Cm to .Ar for macro arguments

9 years agoSupport .RE with an argument; needed for audio/pms(1).
Ingo Schwarze [Sat, 24 Jan 2015 01:58:33 +0000 (01:58 +0000)]
Support .RE with an argument; needed for audio/pms(1).

9 years agonew task: escape blank at the beginning of a line
Ingo Schwarze [Sat, 24 Jan 2015 01:45:21 +0000 (01:45 +0000)]
new task: escape blank at the beginning of a line

9 years agoimprove homebrew cellar config example
Ingo Schwarze [Fri, 23 Jan 2015 21:59:31 +0000 (21:59 +0000)]
improve homebrew cellar config example

9 years agoWhile ignoring the .ta (set tab stops) and .ti (temp indent) requests
Ingo Schwarze [Fri, 23 Jan 2015 20:18:40 +0000 (20:18 +0000)]
While ignoring the .ta (set tab stops) and .ti (temp indent) requests
is sometimes harmless, it often causes seriously ugly output,
so flag these requests as unsupported rather than ignoring them.
Discussed with naddy@.

9 years agoLet .Aq/.Ao/.Ac print "<>" instead of the normal "\(la\(ra"
Ingo Schwarze [Fri, 23 Jan 2015 14:21:01 +0000 (14:21 +0000)]
Let .Aq/.Ao/.Ac print "<>" instead of the normal "\(la\(ra"
when the only child is .Mt, not when the preceding node is .An,
to improve robustness.  Triggered by a question from Svyatoslav
Mishyn <juef at openmailbox dot org> (Crux Linux).

9 years agoWonders of roff(7): Integer numbers in numerical expressions can carry
Ingo Schwarze [Fri, 23 Jan 2015 00:42:00 +0000 (00:42 +0000)]
Wonders of roff(7): Integer numbers in numerical expressions can carry
scaling units, and some manuals (e.g. in devel/grcs) actually use that,
so let's support it.  Missing feature reported by naddy@.

9 years agoSlightly improve \w width measurements:
Ingo Schwarze [Thu, 22 Jan 2015 22:51:43 +0000 (22:51 +0000)]
Slightly improve \w width measurements:
Count special characters with the same width as ASCII characters
and treat all other escape sequences as if they had a width of 0.
Certainly not perfect, but a bit better.
For example, GNU RCS ci(1) needs this; reported by naddy@.

9 years agoTraditional roff(7) explicitly allows certain control characters
Ingo Schwarze [Thu, 22 Jan 2015 21:38:16 +0000 (21:38 +0000)]
Traditional roff(7) explicitly allows certain control characters
in the input stream (SOH, STX, ETX, ENQ, ACK, BEL, BS) for specific
purposes (leaders, backspace, delimiters, .tr), but making sure
these don't leak through to the output is tricky, so mark them as
unsupported for now.

9 years agoDon't let a failing mparse_open() clobber the filename pointer;
Ingo Schwarze [Thu, 22 Jan 2015 19:26:50 +0000 (19:26 +0000)]
Don't let a failing mparse_open() clobber the filename pointer;
fixes error message content and a use after free
for .so with non-existent target when -Wall or -Tlint is given.

9 years agoimprove wording; patch from jmc@
Ingo Schwarze [Thu, 22 Jan 2015 00:09:03 +0000 (00:09 +0000)]
improve wording; patch from jmc@

9 years agoSupport homebrew-style linking on Mac OS X.
Ingo Schwarze [Wed, 21 Jan 2015 22:41:49 +0000 (22:41 +0000)]
Support homebrew-style linking on Mac OS X.
Idea found together with Alexis Hildebrandt <surryhill at gmail dot com>.

9 years agoRudimentary implementation of the roff(7) \o escape sequence (overstrike).
Ingo Schwarze [Wed, 21 Jan 2015 20:33:25 +0000 (20:33 +0000)]
Rudimentary implementation of the roff(7) \o escape sequence (overstrike).
This is of some relevance because the pod2man(1) preamble abuses it
for the icelandic letter Thorn, instead of simply using \(TP and \(Tp.
Missing feature found by sthen@ in DateTime::Locale::is_IS(3p).

9 years agoImprove overstriking. When overstriking a wider character with a
Ingo Schwarze [Wed, 21 Jan 2015 19:40:54 +0000 (19:40 +0000)]
Improve overstriking.  When overstriking a wider character with a
narrower one, center the latter horizontally.  After a group of
characters printed in the same position, advance by the width of
the widest one among them.

9 years agopass empty request lines through to tbl(7); sometimes, they end a layout
Ingo Schwarze [Wed, 21 Jan 2015 02:16:52 +0000 (02:16 +0000)]
pass empty request lines through to tbl(7); sometimes, they end a layout

9 years agoblank lines in tables do not need special handling; simplifies code
Ingo Schwarze [Wed, 21 Jan 2015 00:47:04 +0000 (00:47 +0000)]
blank lines in tables do not need special handling; simplifies code
and reduces groff/mandoc differences in OpenBSD base by about 1%

9 years agotypo fixes from jmc@
Ingo Schwarze [Tue, 20 Jan 2015 22:45:07 +0000 (22:45 +0000)]
typo fixes from jmc@

9 years agoSplit the -Werror message level into -Werror (broken manual, probably
Ingo Schwarze [Tue, 20 Jan 2015 21:16:51 +0000 (21:16 +0000)]
Split the -Werror message level into -Werror (broken manual, probably
using mandoc is better than using groff) and -Wunsupp (manual using
unsupported low-level roff(7) feature, probably using groff is better
than using mandoc).  Once this feature is complete, it is intended
to help porting, making the decision whether to USE_GROFF easier.

As a first step, distinguish four classes of roff(7) requests:
1. Supported (currently 24 requests)
2. Currently ignored because unimportant (120)  ->  no message
3. Ignored for good because insecure (14)  ->  -Werror
4. Currently unsupported (68)  ->  these trigger the new -Wunsupp messages

9 years agochange spelling of centre to center: consistent with other man pages
Ingo Schwarze [Tue, 20 Jan 2015 19:39:34 +0000 (19:39 +0000)]
change spelling of centre to center: consistent with other man pages
and the name of the syntax elements being described; from tedu@

9 years agoMake the man(1) and apropos(1) options -s and -S much less expensive:
Ingo Schwarze [Tue, 20 Jan 2015 18:21:18 +0000 (18:21 +0000)]
Make the man(1) and apropos(1) options -s and -S much less expensive:
Do not append an SQL clause looking into the large "keys" table.
Instead, filter the result of the SQL query in buildnames() where
equivalent data from the much smaller "mlinks" table is already
available for free.

This is relevant because man(1) uses the equivalent of "-S ${MACHINE}"
by default since main.c rev. 1.216, to make sure that manuals for
the current architecture are shown.  With many ports installed, this
patch can speed up man(1) by a factor of more than a hundred.

Slowness reported by Theo Buehler <theo at math dot ethz dot ch>, thanks!

10 years agoLet man(1) show manuals for the current architecture by default,
Ingo Schwarze [Fri, 16 Jan 2015 21:15:05 +0000 (21:15 +0000)]
Let man(1) show manuals for the current architecture by default,
and support the MACHINE environment variable as documented in man(1).
Missing feature reported by pascal@.

10 years agoParse and ignore .IX (generate index entry) macros because pod2man(1)
Ingo Schwarze [Fri, 16 Jan 2015 16:53:49 +0000 (16:53 +0000)]
Parse and ignore .IX (generate index entry) macros because pod2man(1)
emits them, by default without defining them, relying on the roff(7)
quirk that undefined macros have no effect.

10 years agoFatal errors no longer exist.
Ingo Schwarze [Thu, 15 Jan 2015 04:26:39 +0000 (04:26 +0000)]
Fatal errors no longer exist.
If a file can be opened, mandoc will produce some output;
at worst, the output may be almost empty.
Simplifies error handling and frees a message type for future use.

10 years agodowngrade .so failure from FATAL to ERROR
Ingo Schwarze [Thu, 15 Jan 2015 02:29:26 +0000 (02:29 +0000)]
downgrade .so failure from FATAL to ERROR

10 years agodowngrade ".so with absolute path" from FATAL to ERROR;
Ingo Schwarze [Wed, 14 Jan 2015 22:58:16 +0000 (22:58 +0000)]
downgrade ".so with absolute path" from FATAL to ERROR;
allows to get rid of ROFF_ERR

10 years agosimplify by getting rid of ROFF_ERR in tbl(7) parsing; no functional change
Ingo Schwarze [Wed, 14 Jan 2015 22:44:55 +0000 (22:44 +0000)]
simplify by getting rid of ROFF_ERR in tbl(7) parsing; no functional change

10 years agoTo get rid of SYSERR entries in enum mandocerr, downgrade problems with
Ingo Schwarze [Wed, 14 Jan 2015 22:02:49 +0000 (22:02 +0000)]
To get rid of SYSERR entries in enum mandocerr, downgrade problems with
missing and unreadable files from SYSERR to ERROR.
Needed for upcoming work.
As a bonus, this minimally simplifies code and documentation.

10 years agoif earlier files set a non-zero exit status,
Ingo Schwarze [Wed, 14 Jan 2015 21:27:17 +0000 (21:27 +0000)]
if earlier files set a non-zero exit status,
do not allow later files to reset it to zero

10 years agoSimplify handling of system errors: just exit(3).
Ingo Schwarze [Wed, 14 Jan 2015 17:49:15 +0000 (17:49 +0000)]
Simplify handling of system errors: just exit(3).
We already do the same for malloc(3) failure.
The is no virtue in trying to survive failure of fork(2) and the like.

10 years agoBe developer-friendly, 'cause OpenBSD devs like to:
Ingo Schwarze [Tue, 13 Jan 2015 23:17:52 +0000 (23:17 +0000)]
Be developer-friendly, 'cause OpenBSD devs like to:
cd /usr/src/share/man/man4; vi newdev.4 Makefile; make install; man newdev

When a manual is missing from an outdated database, let man(1)
show it anyway, using a KISS file system lookup as a fallback.
Requested by deraadt@.

87 new lines of code doesn't seem too much bloat to me.

Of course, keeping your mandoc.db(5) files up to date with makewhatis(8)
or weekly(8) is still required for apropos(1) to find your new pages.

10 years agodo not spawn a pager when there is no output; issue pointed out by deraadt@
Ingo Schwarze [Tue, 13 Jan 2015 13:22:22 +0000 (13:22 +0000)]
do not spawn a pager when there is no output; issue pointed out by deraadt@

10 years agoBugfix: When the invocation of a user-defined macro follows a roff
Ingo Schwarze [Wed, 7 Jan 2015 12:19:46 +0000 (12:19 +0000)]
Bugfix: When the invocation of a user-defined macro follows a roff
conditional request on the same input line, don't skip the first few
bytes of its content.

10 years agoFix a potential NULL pointer access in an error message after waitpid()
Ingo Schwarze [Sat, 3 Jan 2015 12:55:25 +0000 (12:55 +0000)]
Fix a potential NULL pointer access in an error message after waitpid()
failure; found using detailed information provided by Ulrich Spoerlein
<uqs at FreeBSD> about FreeBSD Coverity CID 1261304.

10 years agoGiven the excessively technical description in the old mdoc_samples(7)
Ingo Schwarze [Sat, 3 Jan 2015 00:59:13 +0000 (00:59 +0000)]
Given the excessively technical description in the old mdoc_samples(7)
manual and its successor groff_mdoc(7), i always considered .Ql as
purely physical markup, but it turns out describing it better allows
to give it a semantic meaning (in-line literal display) that doesn't
contradict existing usage.  One less physical, one more semantic
macro, yay!

Found in a discussion with Steffen Nurpmeso <sdaoden at yandex dot com>.

10 years agoExplicitly set the *data member of struct ohash_info to NULL.
Ingo Schwarze [Fri, 2 Jan 2015 17:02:19 +0000 (17:02 +0000)]
Explicitly set the *data member of struct ohash_info to NULL.
It is never dereferenced, but it gets copied around, which worries
static analysis tools and might also confuse human auditors.
FreeBSD Coverity CID 126129812612991261300, reported by
Pedro Giffuni and Ulrich Spörlein <pfg@ and uqs@ at FreeBSD>.

10 years agoFix a buffer overrun triggered by a trailing backslash at EOF in
Ingo Schwarze [Thu, 1 Jan 2015 19:28:49 +0000 (19:28 +0000)]
Fix a buffer overrun triggered by a trailing backslash at EOF in
an unclosed conditional body.  If the memory contained the byte
sequence "\}" after the end of the buffer before the next NUL, this
could even write beyond the end of the buffer, specifically '&' to
the location of the '}'.  Found by jsg@ with afl.

10 years agoFix a read buffer overrun triggered by trailing \s- or trailing \s+
Ingo Schwarze [Thu, 1 Jan 2015 18:11:45 +0000 (18:11 +0000)]
Fix a read buffer overrun triggered by trailing \s- or trailing \s+
without the required subsequent argument; found by jsg@ with afl.

10 years agoDon't dereference NULL pointers when formatting missing denominators,
Ingo Schwarze [Thu, 1 Jan 2015 15:36:08 +0000 (15:36 +0000)]
Don't dereference NULL pointers when formatting missing denominators,
subscripts, superscripts, or "from" or "to" arguments.
Found by jsg@ with afl.

10 years agoIf man(1) only has one single argument, always interpret it as a name,
Ingo Schwarze [Thu, 1 Jan 2015 13:20:38 +0000 (13:20 +0000)]
If man(1) only has one single argument, always interpret it as a name,
never as a section.  Who would have thought that people call their
manual pages 7z(1), 9c(1), 9p(1), and 9p(3)...
Patch from Sebastien Marie <semarie dash openbsd at latrappe dot fr>.

10 years agodescribe .Ql more precisely;
Ingo Schwarze [Wed, 31 Dec 2014 20:42:31 +0000 (20:42 +0000)]
describe .Ql more precisely;
defect pointed out by Steffen Nurpmeso <sdaoden at yandex dot com>

10 years agoWhen showing more than one formatted manual page, insert horizontal lines
Ingo Schwarze [Wed, 31 Dec 2014 16:52:39 +0000 (16:52 +0000)]
When showing more than one formatted manual page, insert horizontal lines
between pages.  Suggested by Theo Buehler <theo at math dot ethz dot ch>.
Even in UTF-8 output mode, do not use fancy line drawing characters such
that you can easily use /^--- to skip to the next manual in your pager.

10 years agofix wrong paths below FILES; from Theo Buehler <theo at math dot ethz dot ch>
Ingo Schwarze [Tue, 30 Dec 2014 21:34:57 +0000 (21:34 +0000)]
fix wrong paths below FILES; from Theo Buehler <theo at math dot ethz dot ch>

10 years agoWhen a file is given on the command line, actually exists, and its name
Ingo Schwarze [Tue, 30 Dec 2014 20:41:00 +0000 (20:41 +0000)]
When a file is given on the command line, actually exists, and its name
relative to the respective manual tree is longer than PATH_MAX, do not
leak the memory allocated to hold the name.  Not sure that can actually
happen, but better safe than sorry.
FreeBSD Coverity Scan CID 1261303, reported by Pedro Giffuni <pfg@>.

10 years agoImprove documentation of the header/footer macros .Dt, .Os, .TH:
Ingo Schwarze [Sun, 28 Dec 2014 15:23:33 +0000 (15:23 +0000)]
Improve documentation of the header/footer macros .Dt, .Os, .TH:
* State the defaults for .Os and the fourth .TH argument.
* Sync the section titles, and stop advertising obscure sections that
aren't actually fully supported and certainly not recommended for use.

10 years agomdoc(7) already uses the mandoc(1) -Ios argument in the footer line
Ingo Schwarze [Sun, 28 Dec 2014 14:42:27 +0000 (14:42 +0000)]
mdoc(7) already uses the mandoc(1) -Ios argument in the footer line
when .Os has no argument, so do the same for man(7) when .TH has less
than four arguments; there is no reason to treat both differently.
Issue found following a question from Thomas Klausner <wiz at NetBSD>.

10 years agoimprove previous: do the size check up front to avoid leaking memory
Ingo Schwarze [Sun, 28 Dec 2014 14:16:26 +0000 (14:16 +0000)]
improve previous: do the size check up front to avoid leaking memory

10 years agoReduce memory and time consumption on certain malformed input files
Ingo Schwarze [Thu, 25 Dec 2014 17:23:32 +0000 (17:23 +0000)]
Reduce memory and time consumption on certain malformed input files
by limiting the length of expanded input lines during the
(usually recursive) expansion of user defined strings.
Resource hogging found by jsg@ with afl.

10 years agoSupport negative indentations for mdoc(7) displays and lists.
Ingo Schwarze [Wed, 24 Dec 2014 23:32:42 +0000 (23:32 +0000)]
Support negative indentations for mdoc(7) displays and lists.
Not exactly recommended for use, rather for groff compatibility.
While here, introduce similar SHRT_MAX limits as in man(7),
fixing a few cases of infinite output found by jsg@ with afl.

10 years agoFor .RS, we need to save the information how much we actually indented
Ingo Schwarze [Wed, 24 Dec 2014 18:04:10 +0000 (18:04 +0000)]
For .RS, we need to save the information how much we actually indented
because negative indents can get truncated, in which case we no longer
know how to restore the original indent at the end of the block.
This also solves another case of effectively infinite output found
by jsg@ with afl, triggered by very large negative indents.

10 years agoPrevent unsigned integer underflow when a number is too wide
Ingo Schwarze [Wed, 24 Dec 2014 15:38:55 +0000 (15:38 +0000)]
Prevent unsigned integer underflow when a number is too wide
for a table cell with an "nz" layout specification,
causing essentially infinite output as found by jsg@ with afl.

10 years agoWhen a man(7) document contains unreasonably large numbers for
Ingo Schwarze [Wed, 24 Dec 2014 09:58:35 +0000 (09:58 +0000)]
When a man(7) document contains unreasonably large numbers for
indentations or paragraph distances, large output may be generated,
which is practically the same as an endless loop; found by jsg@
with afl.
Reject such unreasonably large numbers beyond arbitrary limits
similar to those used by groff (max. 65 blank lines between paragraphs
and max. SHRT_MAX characters per output line) and fall back to
defaults when exceeded.  Having the limits behave in exactly the
same way is not relevant.

10 years agosupport negative horizontal widths in man(7);
Ingo Schwarze [Tue, 23 Dec 2014 13:48:57 +0000 (13:48 +0000)]
support negative horizontal widths in man(7);
minus twenty lines of code in spite of enhanced functionality

10 years agofix typo in previous
Ingo Schwarze [Tue, 23 Dec 2014 10:09:44 +0000 (10:09 +0000)]
fix typo in previous

10 years agosome scaling unit fixes:
Ingo Schwarze [Tue, 23 Dec 2014 09:31:46 +0000 (09:31 +0000)]
some scaling unit fixes:
- .sp with an invalid argument is .sp 1v, not .sp 0v
- in man(1), trailing garbage doesn't make scaling units invalid

10 years agoeven if the second argument to .IP is invalid, don't print it
Ingo Schwarze [Tue, 23 Dec 2014 08:15:53 +0000 (08:15 +0000)]
even if the second argument to .IP is invalid, don't print it

10 years agoFix vertical scaling. Obviously, nobody ever had a serious look at this.
Ingo Schwarze [Tue, 23 Dec 2014 06:16:46 +0000 (06:16 +0000)]
Fix vertical scaling.  Obviously, nobody ever had a serious look at this.
Basic units, centimeters, points, ens, ems, and the rounding algorithm
were all wrong, only inches, pica, and the default vertical span worked.

10 years agoIn a2roffsu(), do not parse the number twice.
Ingo Schwarze [Tue, 23 Dec 2014 03:28:01 +0000 (03:28 +0000)]
In a2roffsu(), do not parse the number twice.
Gets rid of 25 lines of code and one static buffer.
No functional change for numbers shorter than BUFSIZ characters.

10 years agocorrectly handle scaling units after .PD
Ingo Schwarze [Tue, 23 Dec 2014 01:57:35 +0000 (01:57 +0000)]
correctly handle scaling units after .PD

10 years agoThe code already pays attention not to close the same block twice.
Ingo Schwarze [Mon, 22 Dec 2014 23:27:32 +0000 (23:27 +0000)]
The code already pays attention not to close the same block twice.
Similarly, avoid having the same block break two other blocks.
In some situations, this could lead to an endless loop in rew_sub()
found by jsg@ with afl.
Minimal example:  .Po Ao Pc Bo Pc Ac Bc

10 years agoUse -m for macro set selection in mandoc(1) mode only, not in man(1)
Ingo Schwarze [Sun, 21 Dec 2014 14:49:28 +0000 (14:49 +0000)]
Use -m for macro set selection in mandoc(1) mode only, not in man(1)
and apropos(1) mode.  While here, put a space character between
options and option arguments in error messages.
Both reported by Alessandro DE LAURENZIS <just22 dot adl at gmail dot com>.

10 years agoISO C99 explicitly forbids forward references to enum types (6.7.2.3.3.);
Ingo Schwarze [Sun, 21 Dec 2014 14:14:35 +0000 (14:14 +0000)]
ISO C99 explicitly forbids forward references to enum types (6.7.2.3.3.);
patch from daniel@

10 years agoFix two issues causing a class of assertion failures found by jsg@ with afl.
Ingo Schwarze [Sat, 20 Dec 2014 02:26:57 +0000 (02:26 +0000)]
Fix two issues causing a class of assertion failures found by jsg@ with afl.
1) rew_sub(): Make sure REWIND_MORE is acted upon even when followed by
REWIND_NONE.  This prevents .It from ending up inside other children of .Bl.
2) blk_exp_close(): Only allow extension of .Bl when it has at least
one .It.  Otherwise, a broken child block could be moved in front of
the .Bl, effectively resulting in a .Bl that ended before it began.

10 years agoresolve some code duplication; no functional change
Ingo Schwarze [Sat, 20 Dec 2014 00:20:11 +0000 (00:20 +0000)]
resolve some code duplication; no functional change

10 years agoEnforcing an arbitrary, implementation dependent, undocumented limit
Ingo Schwarze [Fri, 19 Dec 2014 17:12:04 +0000 (17:12 +0000)]
Enforcing an arbitrary, implementation dependent, undocumented limit
by calling assert() when valid user input exceeds it is a bad idea.
Allocate the terminal font stack dynamically instead of crashing
above 10 entries.  Issue found by jsg@ with afl.

10 years agoRewrite the low-level UTF-8 parser from scratch.
Ingo Schwarze [Fri, 19 Dec 2014 04:58:35 +0000 (04:58 +0000)]
Rewrite the low-level UTF-8 parser from scratch.
It accepted invalid byte sequences like 0xc080-c1bf, 0xe08080-e09fbf,
0xeda080-edbfbf, and 0xf0808080-f08fbfbf, produced valid roff Unicode
escape sequences from them, and the algorithm contained strong
defenses against any attempt to fix it.

This cures an assertion failure in the terminal formatter caused
by sneaking in ASCII 0x08 (backspace) by "encoding" it as an (invalid)
multibyte UTF-8 sequence, found by jsg@ with afl.

As a bonus, the new algorithm also reduces the code in the function
by about 20%.

10 years agoupdate usage() and the list of non-standard (i.e. non-posix) options;
Ingo Schwarze [Thu, 18 Dec 2014 21:11:46 +0000 (21:11 +0000)]
update usage() and the list of non-standard (i.e. non-posix) options;
from jmc@

10 years agoDon't let .Ta creep into an already-closed list; same as for .It.
Ingo Schwarze [Thu, 18 Dec 2014 20:58:32 +0000 (20:58 +0000)]
Don't let .Ta creep into an already-closed list; same as for .It.
Fixes an assertion found by jsg@ with afl.

10 years agoOnly keep leading .Sm inside a list when it immediately precedes
Ingo Schwarze [Thu, 18 Dec 2014 20:15:56 +0000 (20:15 +0000)]
Only keep leading .Sm inside a list when it immediately precedes
the first .It.  Otherwise, move it out together with whatever
follows.  Fixing an assertion failure found by jsg@ with afl.

10 years agoWhen the head of a list item is extended with a partial explicit
Ingo Schwarze [Thu, 18 Dec 2014 19:23:41 +0000 (19:23 +0000)]
When the head of a list item is extended with a partial explicit
macro (for example .Xo) and never closed again, the item ends up
without a body block.  This can even happen for list types that
usually don't have heads in the first place.  So even in this
case, check for the existence of the body before accessing it.
NULL pointer access found by jsg@ with afl.

10 years agoDon't let the modulo operator divide by zero.
Ingo Schwarze [Thu, 18 Dec 2014 17:43:41 +0000 (17:43 +0000)]
Don't let the modulo operator divide by zero.
Found by jsg@ with afl.