summaryrefslogtreecommitdiff
path: root/usr/src/cmd/mandoc/term_ascii.c
diff options
context:
space:
mode:
Diffstat (limited to 'usr/src/cmd/mandoc/term_ascii.c')
-rw-r--r--usr/src/cmd/mandoc/term_ascii.c32
1 files changed, 26 insertions, 6 deletions
diff --git a/usr/src/cmd/mandoc/term_ascii.c b/usr/src/cmd/mandoc/term_ascii.c
index 368623cac1..bf7e9b639e 100644
--- a/usr/src/cmd/mandoc/term_ascii.c
+++ b/usr/src/cmd/mandoc/term_ascii.c
@@ -1,7 +1,7 @@
-/* $Id: term_ascii.c,v 1.64 2018/11/28 14:23:06 schwarze Exp $ */
+/* $Id: term_ascii.c,v 1.66 2020/09/09 13:45:05 schwarze Exp $ */
/*
* Copyright (c) 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv>
- * Copyright (c) 2014, 2015, 2017, 2018 Ingo Schwarze <schwarze@openbsd.org>
+ * Copyright (c) 2014,2015,2017,2018,2020 Ingo Schwarze <schwarze@openbsd.org>
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
@@ -232,7 +232,10 @@ ascii_endline(struct termp *p)
{
p->line++;
- p->tcol->offset -= p->ti;
+ if ((int)p->tcol->offset > p->ti)
+ p->tcol->offset -= p->ti;
+ else
+ p->tcol->offset = 0;
p->ti = 0;
putchar('\n');
}
@@ -242,7 +245,14 @@ ascii_advance(struct termp *p, size_t len)
{
size_t i;
- assert(len < UINT16_MAX);
+ /*
+ * XXX We used to have "assert(len < UINT16_MAX)" here.
+ * that is not quite right because the input document
+ * can trigger that by merely providing large input.
+ * For now, simply truncate.
+ */
+ if (len > 256)
+ len = 256;
for (i = 0; i < len; i++)
putchar(' ');
}
@@ -380,7 +390,14 @@ locale_advance(struct termp *p, size_t len)
{
size_t i;
- assert(len < UINT16_MAX);
+ /*
+ * XXX We used to have "assert(len < UINT16_MAX)" here.
+ * that is not quite right because the input document
+ * can trigger that by merely providing large input.
+ * For now, simply truncate.
+ */
+ if (len > 256)
+ len = 256;
for (i = 0; i < len; i++)
putwchar(L' ');
}
@@ -390,7 +407,10 @@ locale_endline(struct termp *p)
{
p->line++;
- p->tcol->offset -= p->ti;
+ if ((int)p->tcol->offset > p->ti)
+ p->tcol->offset -= p->ti;
+ else
+ p->tcol->offset = 0;
p->ti = 0;
putwchar(L'\n');
}