groff-commit
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[groff] 08/50: [grotty]: Do more input validation.


From: G. Branden Robinson
Subject: [groff] 08/50: [grotty]: Do more input validation.
Date: Sat, 21 May 2022 12:17:23 -0400 (EDT)

gbranden pushed a commit to branch master
in repository groff.

commit f72bd479555b15947728a4977e661a35516dba3d
Author: G. Branden Robinson <g.branden.robinson@gmail.com>
AuthorDate: Mon May 16 20:40:55 2022 -0500

    [grotty]: Do more input validation.
    
    * src/devices/grotty/tty.cpp (tty_printer::draw): Throw warning if an
      unsupported geometric primitive is encountered.
    
      (tty_printer::line): Throw warning if a line is diagonal.  Die if
      length of a horizontal or vertical line is not a multiple of the
      appropriate motion quantum of the device (troff should never emit such
      nonsense, and currently doesn't appear to).
---
 ChangeLog                  | 11 +++++++++++
 src/devices/grotty/tty.cpp | 21 ++++++++++++++++++++-
 2 files changed, 31 insertions(+), 1 deletion(-)

diff --git a/ChangeLog b/ChangeLog
index 83d321c1..d028a2e2 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,14 @@
+2022-05-16  G. Branden Robinson <g.branden.robinson@gmail.com>
+
+       [grotty]: Do more input validation.
+
+       * src/devices/grotty/tty.cpp (tty_printer::draw): Throw warning
+       if an unsupported geometric primitive is encountered.
+       (tty_printer::line): Throw warning if a line is diagonal.  Die
+       if length of a horizontal or vertical line is not a multiple of
+       the appropriate motion quantum of the device (troff should never
+       emit such nonsense, and currently doesn't appear to).
+
 2022-05-16  G. Branden Robinson <g.branden.robinson@gmail.com>
 
        * src/preproc/tbl/tbl.1.man (Miscellaneous): Document GNU tbl's
diff --git a/src/devices/grotty/tty.cpp b/src/devices/grotty/tty.cpp
index eced8e60..787fd33b 100644
--- a/src/devices/grotty/tty.cpp
+++ b/src/devices/grotty/tty.cpp
@@ -537,8 +537,10 @@ void tty_printer::draw(int code, int *p, int np, const 
environment *env)
     return;
   if (code == 'l')
     draw_line(p, np, env);
-  if (code == 'p')
+  else if (code == 'p')
     draw_polygon(p, np, env);
+  else
+    warning("ignoring unsupported drawing command '%1'", char(code));
 }
 
 void tty_printer::draw_polygon(int *p, int np, const environment *env)
@@ -588,6 +590,23 @@ void tty_printer::draw_line(int *p, int np, const 
environment *env)
 void tty_printer::line(int hpos, int vpos, int dx, int dy,
                       color *col, color *fill)
 {
+  // XXX: zero-length lines get drawn as '+' crossings in nroff, even
+  // when there is no crossing, but they nevertheless occur frequently
+  // in input.  Does tbl produce them?
+#if 0
+  if (0 == dx)
+    fatal("cannot draw zero-length horizontal line");
+  if (0 == dy)
+    fatal("cannot draw zero-length vertical line");
+#endif
+  if ((dx != 0) && (dy != 0))
+    warning("cannot draw diagonal line");
+  if (dx % font::hor != 0)
+    fatal("length of horizontal line %1 is not a multiple of horizontal"
+       " motion quantum %2", dx, font::hor);
+  if (dy % font::vert != 0)
+    fatal("length of vertical line %1 is not a multiple of vertical"
+       " motion quantum %2", dy, font::vert);
   if (dx == 0) {
     // vertical line
     int v = vpos;



reply via email to

[Prev in Thread] Current Thread [Next in Thread]