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. I wasn't sure how to
handle errors, so they're just ignored for now.


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:
                        /*

Reply via email to