groff-commit
[Top][All Lists]
Advanced

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

[groff] 20/21: src/roff/troff/env.cpp: Add some paranoia.


From: G. Branden Robinson
Subject: [groff] 20/21: src/roff/troff/env.cpp: Add some paranoia.
Date: Tue, 23 Aug 2022 14:18:43 -0400 (EDT)

gbranden pushed a commit to branch master
in repository groff.

commit be53ed3db8b4bd550b76d3b02a5755519e3e0c50
Author: G. Branden Robinson <g.branden.robinson@gmail.com>
AuthorDate: Tue Aug 23 09:13:13 2022 -0500

    src/roff/troff/env.cpp: Add some paranoia.
    
    * src/roff/troff/env.cpp (environment::set_family): Add some paranoia.
      Add `assert()`s on the previous font mounting position still being
      valid and the font family dictionary lookup not returning a null
      pointer.  Add an early return for the latter case (which should be
      impossible).
---
 ChangeLog              |  8 ++++++++
 src/roff/troff/env.cpp | 11 ++++++++++-
 2 files changed, 18 insertions(+), 1 deletion(-)

diff --git a/ChangeLog b/ChangeLog
index e704ebfd5..d9f6c3d3c 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+2022-08-23  G. Branden Robinson <g.branden.robinson@gmail.com>
+
+       * src/roff/troff/env.cpp (environment::set_family): Add some
+       paranoia.  Add `assert()`s on the previous font mounting
+       position still being valid and the font family dictionary lookup
+       not returning a null pointer.  Add an early return for the
+       latter case (which should be impossible).
+
 2022-08-23  G. Branden Robinson <g.branden.robinson@gmail.com>
 
        * src/roff/troff/node.cpp (font_family::make_definite):
diff --git a/src/roff/troff/env.cpp b/src/roff/troff/env.cpp
index a56f07b3a..160c1378a 100644
--- a/src/roff/troff/env.cpp
+++ b/src/roff/troff/env.cpp
@@ -550,7 +550,9 @@ void environment::set_family(symbol fam)
   if (interrupted)
     return;
   if (fam.is_null() || fam.is_empty()) {
-    if (prev_family->make_definite(fontno) < 0)
+    int previous_mounting_position = prev_family->make_definite(fontno);
+    assert(previous_mounting_position >= 0);
+    if (previous_mounting_position < 0)
       return;
     font_family *tem = family;
     family = prev_family;
@@ -558,6 +560,13 @@ void environment::set_family(symbol fam)
   }
   else {
     font_family *f = lookup_family(fam);
+    // If the family isn't already in the dictionary, looking it up will
+    // create an entry for it.  That doesn't mean that it will be
+    // resolvable to a real font when combined with a style name.
+    assert((f != 0 /* nullptr */) &&
+          (0 != "font family dictionary lookup"));
+    if (0 /* nullptr */ == f)
+      return;
     if (f->make_definite(fontno) < 0)
       return;
     prev_family = family;



reply via email to

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