aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/term_ascii.c
diff options
context:
space:
mode:
authorIngo Schwarze <schwarze@openbsd.org>2014-11-20 13:56:20 +0000
committerIngo Schwarze <schwarze@openbsd.org>2014-11-20 13:56:20 +0000
commitb300a4ff9ca15ee75ac8b05afd9d5817390384ae (patch)
tree4f00a927805ad8f4235e0cfd84d45384d664aae2 /term_ascii.c
parentf6678df24821d82cd83677550831b7542c29a741 (diff)
downloadmandoc-b300a4ff9ca15ee75ac8b05afd9d5817390384ae.tar.gz
mandoc-b300a4ff9ca15ee75ac8b05afd9d5817390384ae.tar.zst
mandoc-b300a4ff9ca15ee75ac8b05afd9d5817390384ae.zip
Prevent negative arguments to the .ll request from causing integer
underflow. Found while preparing an audit of termp.rmargin. Overflow can also happen, but i see no sane way to deal with it, so just let it happen. It doesn't happen for any sane input anyway, groff behaviour is undefined, and the resulting values are legal, even though they are useless.
Diffstat (limited to 'term_ascii.c')
-rw-r--r--term_ascii.c10
1 files changed, 6 insertions, 4 deletions
diff --git a/term_ascii.c b/term_ascii.c
index 6c290453..71d8af4c 100644
--- a/term_ascii.c
+++ b/term_ascii.c
@@ -1,4 +1,4 @@
-/* $Id: term_ascii.c,v 1.39 2014/10/28 18:49:33 schwarze Exp $ */
+/* $Id: term_ascii.c,v 1.40 2014/11/20 13:56:20 schwarze Exp $ */
/*
* Copyright (c) 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv>
* Copyright (c) 2014 Ingo Schwarze <schwarze@openbsd.org>
@@ -159,12 +159,14 @@ ascii_setwidth(struct termp *p, int iop, size_t width)
{
p->rmargin = p->defrmargin;
- if (0 < iop)
+ if (iop > 0)
p->defrmargin += width;
- else if (0 > iop)
+ else if (iop == 0)
+ p->defrmargin = width ? width : p->lastrmargin;
+ else if (p->defrmargin > width)
p->defrmargin -= width;
else
- p->defrmargin = width ? width : p->lastrmargin;
+ p->defrmargin = 0;
p->lastrmargin = p->rmargin;
p->rmargin = p->maxrmargin = p->defrmargin;
}