groff-commit
[Top][All Lists]
Advanced

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

[groff] 07/13: [troff]: Clamp negative tab stop positions to 0.


From: G. Branden Robinson
Subject: [groff] 07/13: [troff]: Clamp negative tab stop positions to 0.
Date: Sat, 11 Sep 2021 16:20:12 -0400 (EDT)

gbranden pushed a commit to branch master
in repository groff.

commit 6692653f7cae4116d4e70318f71b3d0808f2261f
Author: G. Branden Robinson <g.branden.robinson@gmail.com>
AuthorDate: Sat Sep 11 07:02:07 2021 +1000

    [troff]: Clamp negative tab stop positions to 0.
    
    ...instead of throwing an assertion failure.
    
    * src/roff/troff/env.cpp (tab_stops::distance_to_next_tab): Replace
      `assert` with clamping logic, ensuring that `lastpos` can never be
      negative.  While negative tab stop positions don't make much sense
      (they result in zero horizontal motion), user input like `.ta T -5`
      should never provoke an assertion failure.
    
      (set_tabs): Throw range warning in additional scenario, viz., if a
      repeating tab offset is negative.
    
    Fixes <https://bugs.debian.org/990406>.  Thanks to наб for the report.
    
    Also wrap nearby long source lines.
---
 ChangeLog              | 17 +++++++++++++++++
 src/roff/troff/env.cpp | 11 +++++++----
 2 files changed, 24 insertions(+), 4 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index e147ac0..648f7a1 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,22 @@
 2021-09-11  G. Branden Robinson <g.branden.robinson@gmail.com>
 
+       [troff]: Clamp negative tab stop positions to zero instead of
+       throwing an assertion failure.
+
+       * src/roff/troff/env.cpp (tab_stops::distance_to_next_tab):
+       Replace `assert` with clamping logic, ensuring that `lastpos`
+       can never be negative.  While negative tab stop positions don't
+       make much sense (they result in zero horizontal motion), user
+       input like `.ta T -5` should never provoke an assertion failure.
+
+       (set_tabs): Throw range warning in additional scenario, viz., if
+       a repeating tab offset is negative.
+
+       Fixes <https://bugs.debian.org/990406>.  Thanks to наб for the
+       report.
+
+2021-09-11  G. Branden Robinson <g.branden.robinson@gmail.com>
+
        [troff]: Boolify `set_tabs` function.
 
        * src/roff/troff/env.cpp (set_tabs): Demote local variables from
diff --git a/src/roff/troff/env.cpp b/src/roff/troff/env.cpp
index 22754b3..624c2fe 100644
--- a/src/roff/troff/env.cpp
+++ b/src/roff/troff/env.cpp
@@ -2594,7 +2594,8 @@ tab_type tab_stops::distance_to_next_tab(hunits curpos, 
hunits *distance)
   return distance_to_next_tab(curpos, distance, &nextpos);
 }
 
-tab_type tab_stops::distance_to_next_tab(hunits curpos, hunits *distance,
+tab_type tab_stops::distance_to_next_tab(hunits curpos,
+                                        hunits *distance,
                                         hunits *nextpos)
 {
   hunits lastpos = 0;
@@ -2610,14 +2611,16 @@ tab_type tab_stops::distance_to_next_tab(hunits curpos, 
hunits *distance,
     return TAB_NONE;
   hunits base = lastpos;
   for (;;) {
-    for (tem = repeated_list; tem && tem->pos + base <= curpos; tem = 
tem->next)
+    for (tem = repeated_list; tem && tem->pos + base <= curpos;
+        tem = tem->next)
       lastpos = tem->pos;
     if (tem) {
       *distance = tem->pos + base - curpos;
       *nextpos  = tem->pos + base;
       return tem->type;
     }
-    assert(lastpos > 0);
+    if (lastpos < 0)
+      lastpos = 0;
     base += lastpos;
   }
   return TAB_NONE;
@@ -2779,7 +2782,7 @@ void set_tabs()
     else if (tok.ch() == 'L') {
       tok.next();
     }
-    if (pos <= prev_pos && !is_first_stop)
+    if (pos <= prev_pos && ((!is_first_stop) || is_repeating_stop))
       warning(WARN_RANGE,
              "positions of tab stops must be strictly increasing");
     else {



reply via email to

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