Hi Ted,
Ted Unangst wrote on Sun, Feb 15, 2015 at 06:53:10AM -0500:
> In trying to set man up to use my current terminal width $(($COLUMNS-2))
> I discovered that COLUMNS isn't exported to subshells. mandoc itself
> seems to go crazy when run with -O width=-2.
>
> Clamp width and indent settings to sensible values.
OK schwarze@ for your patch, it clearly improves the situation.
Once your patch will be in, i'll look into changing all the atoi()
and strto*() in mandoc to strtonum(). There may be more similar
problems elsewhere.
> I wasn't sure how to handle errors,
Indeed, the command line option parsers for -O are ill-designed
in so far as they don't allow reasonable error handling.
At some point, i will have to redesign the -O handling, but not
before release.
> so they're just ignored for now.
I agree with that, for now.
Yours,
Ingo
> Index: term_ascii.c
> ===================================================================
> RCS file: /cvs/src/usr.bin/mandoc/term_ascii.c,v
> retrieving revision 1.29
> diff -u -p -r1.29 term_ascii.c
> --- term_ascii.c 31 Dec 2014 16:50:54 -0000 1.29
> +++ term_ascii.c 15 Feb 2015 11:48:23 -0000
> @@ -55,6 +55,8 @@ ascii_init(enum termenc enc, const struc
> const char *toks[5];
> char *v;
> struct termp *p;
> + const char *errstr;
> + int num;
>
> p = mandoc_calloc(1, sizeof(struct termp));
>
> @@ -99,10 +101,14 @@ ascii_init(enum termenc enc, const struc
> while (outopts && *outopts)
> switch (getsubopt(&outopts, UNCONST(toks), &v)) {
> case 0:
> - p->defindent = (size_t)atoi(v);
> + num = strtonum(v, 0, 1000, &errstr);
> + if (!errstr)
> + p->defindent = num;
> break;
> case 1:
> - p->defrmargin = (size_t)atoi(v);
> + num = strtonum(v, 0, 1000, &errstr);
> + if (!errstr)
> + p->defrmargin = num;
> break;
> case 2:
> /*