groff-commit
[Top][All Lists]
Advanced

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

[groff] 09/26: [libgroff,troff]: Trivially refactor (1/5).


From: G. Branden Robinson
Subject: [groff] 09/26: [libgroff,troff]: Trivially refactor (1/5).
Date: Sat, 13 Jul 2024 16:20:50 -0400 (EDT)

gbranden pushed a commit to branch master
in repository groff.

commit ad19d006e5bf07af2f838da311ba735d7d360b41
Author: G. Branden Robinson <g.branden.robinson@gmail.com>
AuthorDate: Sat Jul 13 11:52:12 2024 -0500

    [libgroff,troff]: Trivially refactor (1/5).
    
    * src/libs/libgroff/font.cpp (text_file::~text_file, font::extend_ch)
      (font::load, font::load_desc):
    * src/libs/libgroff/searchpath.cpp (search_path::open_file_cautious):
    * src/roff/troff/env.cpp (hyphen_trie::read_patterns_file): Reorder
      comparisons with null pointers to avoid inadvertent lvalue assignment.
---
 ChangeLog                        | 10 ++++++++++
 src/libs/libgroff/font.cpp       | 18 +++++++++---------
 src/libs/libgroff/searchpath.cpp |  2 +-
 src/roff/troff/env.cpp           |  2 +-
 4 files changed, 21 insertions(+), 11 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 1eaaba6f4..3f1cb0f3b 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,13 @@
+2024-07-13  G. Branden Robinson <g.branden.robinson@gmail.com>
+
+       * src/libs/libgroff/font.cpp (text_file::~text_file)
+       (font::extend_ch, font::load, font::load_desc):
+       * src/libs/libgroff/searchpath.cpp
+       (search_path::open_file_cautious):
+       * src/roff/troff/env.cpp (hyphen_trie::read_patterns_file):
+       Reorder comparisons with null pointers to avoid inadvertent
+       lvalue assignment.
+
 2024-07-13  G. Branden Robinson <g.branden.robinson@gmail.com>
 
        * src/libs/libgroff/font.cpp (font::load, font::load_desc):
diff --git a/src/libs/libgroff/font.cpp b/src/libs/libgroff/font.cpp
index a0e9bc2c2..c58efce49 100644
--- a/src/libs/libgroff/font.cpp
+++ b/src/libs/libgroff/font.cpp
@@ -105,9 +105,9 @@ text_file::~text_file()
 
 bool text_file::next_line()
 {
-  if (fp == 0)
+  if (0 == fp)
     return false;
-  if (buf == 0)
+  if (0 == buf)
     buf = new char[linebufsize];
   for (;;) {
     lineno++;
@@ -644,7 +644,7 @@ void font::alloc_ch_index(int idx)
 
 void font::extend_ch()
 {
-  if (ch == 0)
+  if (0 == ch)
     ch = new font_char_metric[ch_size = 16];
   else {
     int old_ch_size = ch_size;
@@ -784,7 +784,7 @@ bool font::load(bool load_header_only)
 {
   char *path;
   FILE *fp = open_file(name, &path);
-  if (fp == 0)
+  if (0 == fp)
     return false;
   text_file t(fp, path);
   t.silent = load_header_only;
@@ -936,7 +936,7 @@ bool font::load(bool load_header_only)
          break;
        }
        if (p[0] == '"') {
-         if (last_glyph == 0) {
+         if (0 == last_glyph) {
            t.error("the first entry ('%1') in 'charset' subsection"
                    " cannot be an alias", nm);
            return false;
@@ -1073,7 +1073,7 @@ const char *font::load_desc()
   int nfonts = 0;
   char *path;
   FILE *fp = open_file("DESC", &path);
-  if (fp == 0)
+  if (0 == fp)
     return 0 /* nullptr */;
   text_file t(fp, path);
   while (t.next_line()) {
@@ -1286,7 +1286,7 @@ const char *font::load_desc()
     }
   }
   t.lineno = 0;
-  if (res == 0) {
+  if (0 == res) {
     t.error("device description file missing 'res' directive");
     return 0 /* nullptr */;
   }
@@ -1294,11 +1294,11 @@ const char *font::load_desc()
     t.error("device description file missing 'unitwidth' directive");
     return 0 /* nullptr */;
   }
-  if (font_name_table == 0) {
+  if (0 == font_name_table) {
     t.error("device description file missing 'fonts' directive");
     return 0 /* nullptr */;
   }
-  if (sizes == 0) {
+  if (0 == sizes) {
     t.error("device description file missing 'sizes' directive");
     return 0 /* nullptr */;
   }
diff --git a/src/libs/libgroff/searchpath.cpp b/src/libs/libgroff/searchpath.cpp
index 2042218d8..d276a4a94 100644
--- a/src/libs/libgroff/searchpath.cpp
+++ b/src/libs/libgroff/searchpath.cpp
@@ -154,7 +154,7 @@ FILE *search_path::open_file_cautious(const char *name, 
char **pathp,
   if (!mode)
     mode = "r";
   bool reading = (strchr(mode, 'r') != 0);
-  if (name == 0 || strcmp(name, "-") == 0) {
+  if (0 == name || strcmp(name, "-") == 0) {
     if (pathp)
       *pathp = strsave(reading ? "stdin" : "stdout");
     return (reading ? stdin : stdout);
diff --git a/src/roff/troff/env.cpp b/src/roff/troff/env.cpp
index 543ed44f1..e01d29aa2 100644
--- a/src/roff/troff/env.cpp
+++ b/src/roff/troff/env.cpp
@@ -3945,7 +3945,7 @@ void hyphen_trie::read_patterns_file(const char *name, 
int append,
   errno = 0;
   char *path = 0;
   FILE *fp = mac_path->open_file(name, &path);
-  if (fp == 0 /* nullptr */) {
+  if (0 /* nullptr */ == fp) {
     error("can't find hyphenation patterns file '%1'", name);
     return;
   }



reply via email to

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