groff
[Top][All Lists]
Advanced

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

[PATCH 3/4] src/: Remove redundant checks after strtol(3).


From: Alejandro Colomar
Subject: [PATCH 3/4] src/: Remove redundant checks after strtol(3).
Date: Mon, 15 Jan 2024 00:51:01 +0100

`str == end` can only happen if strtol(3) returns 0.

Signed-off-by: Alejandro Colomar <alx@kernel.org>
---
 src/devices/grodvi/dvi.cpp      | 4 ++--
 src/devices/grolbp/lbp.cpp      | 2 +-
 src/devices/grolj4/lj4.cpp      | 6 +++---
 src/devices/grops/ps.cpp        | 4 ++--
 src/devices/grops/psrm.cpp      | 2 +-
 src/libs/libgroff/font.cpp      | 2 +-
 src/preproc/eqn/lex.cpp         | 2 +-
 src/preproc/pic/tex.cpp         | 2 +-
 src/preproc/refer/command.cpp   | 3 +--
 src/preproc/refer/ref.cpp       | 2 +-
 src/preproc/refer/refer.cpp     | 6 +++---
 src/utils/indxbib/indxbib.cpp   | 2 +-
 src/utils/lkbib/lkbib.cpp       | 2 +-
 src/utils/lookbib/lookbib.cpp   | 2 +-
 src/utils/tfmtodit/tfmtodit.cpp | 5 +----
 15 files changed, 21 insertions(+), 25 deletions(-)

diff --git a/src/devices/grodvi/dvi.cpp b/src/devices/grodvi/dvi.cpp
index 1dac6d88f..dfd8f00d0 100644
--- a/src/devices/grodvi/dvi.cpp
+++ b/src/devices/grodvi/dvi.cpp
@@ -92,7 +92,7 @@ void dvi_font::handle_unknown_font_command(const char 
*command,
       fatal_with_file_and_line(filename, lineno,
                               "'checksum' command requires an argument");
     checksum = int(strtol(arg, &ptr, 10));
-    if (checksum == 0 && ptr == arg) {
+    if (ptr == arg) {
       fatal_with_file_and_line(filename, lineno, "bad checksum");
     }
   }
@@ -101,7 +101,7 @@ void dvi_font::handle_unknown_font_command(const char 
*command,
       fatal_with_file_and_line(filename, lineno,
                               "'designsize' command requires an argument");
     design_size = int(strtol(arg, &ptr, 10));
-    if (design_size == 0 && ptr == arg) {
+    if (ptr == arg) {
       fatal_with_file_and_line(filename, lineno, "bad design size");
     }
   }
diff --git a/src/devices/grolbp/lbp.cpp b/src/devices/grolbp/lbp.cpp
index b37c90055..9b061f9ad 100644
--- a/src/devices/grolbp/lbp.cpp
+++ b/src/devices/grolbp/lbp.cpp
@@ -707,7 +707,7 @@ int main(int argc, char **argv)
       {
        char *ptr;
        long n = strtol(optarg, &ptr, 10);
-       if (n == 0 && ptr == optarg)
+       if (ptr == optarg)
          error("argument for -w must be a non-negative integer");
        else if (n < 0 || n > INT_MAX)
          error("out of range argument for -w");
diff --git a/src/devices/grolj4/lj4.cpp b/src/devices/grolj4/lj4.cpp
index 1a238ae4e..0f7a28782 100644
--- a/src/devices/grolj4/lj4.cpp
+++ b/src/devices/grolj4/lj4.cpp
@@ -140,7 +140,7 @@ void lj4_font::handle_unknown_font_command(const char 
*command,
                                 command);
       char *ptr;
       long n = strtol(arg, &ptr, 10);
-      if (n == 0 && ptr == arg)
+      if (ptr == arg)
        fatal_with_file_and_line(filename, lineno,
                                 "'%1' command requires numeric argument",
                                 command);
@@ -661,7 +661,7 @@ int main(int argc, char **argv)
       {
        char *ptr;
        long n = strtol(optarg, &ptr, 10);
-       if (n == 0 && ptr == optarg)
+       if (ptr == optarg)
          error("argument for -c must be a positive integer");
        else if (n <= 0 || n > 32767)
          error("out of range argument for -c");
@@ -673,7 +673,7 @@ int main(int argc, char **argv)
       {
        char *ptr;
        long n = strtol(optarg, &ptr, 10);
-       if (n == 0 && ptr == optarg)
+       if (ptr == optarg)
          error("argument for -w must be a non-negative integer");
        else if (n < 0 || n > INT_MAX)
          error("out of range argument for -w");
diff --git a/src/devices/grops/ps.cpp b/src/devices/grops/ps.cpp
index e047fa85c..35fad8a5b 100644
--- a/src/devices/grops/ps.cpp
+++ b/src/devices/grops/ps.cpp
@@ -1659,7 +1659,7 @@ void ps_printer::do_mdef(char *arg, const environment *)
 {
   char *p;
   int n = (int)strtol(arg, &p, 10);
-  if (n == 0 && p == arg) {
+  if (p == arg) {
     error("first argument to X mdef must be an integer");
     return;
   }
@@ -1693,7 +1693,7 @@ void ps_printer::do_import(char *arg, const environment 
*env)
   while (nparms < 6) {
     char *end;
     long n = strtol(p, &end, 10);
-    if (n == 0 && end == p)
+    if (end == p)
       break;
     parms[nparms++] = int(n);
     p = end;
diff --git a/src/devices/grops/psrm.cpp b/src/devices/grops/psrm.cpp
index 226375085..d6108f268 100644
--- a/src/devices/grops/psrm.cpp
+++ b/src/devices/grops/psrm.cpp
@@ -110,7 +110,7 @@ static int read_uint_arg(const char **pp, unsigned *res)
   const char *start = *pp;
   // XXX use strtoul
   long n = strtol(start, (char **)pp, 10);
-  if (n == 0 && *pp == start) {
+  if (*pp == start) {
     error("not an integer");
     return 0;
   }
diff --git a/src/libs/libgroff/font.cpp b/src/libs/libgroff/font.cpp
index d19f3d0ca..e5d834998 100644
--- a/src/libs/libgroff/font.cpp
+++ b/src/libs/libgroff/font.cpp
@@ -988,7 +988,7 @@ bool font::load(bool load_header_only)
          }
          char *ptr;
          metric.code = (int)strtol(p, &ptr, 0);
-         if (metric.code == 0 && ptr == p) {
+         if (ptr == p) {
            t.error("invalid code '%1' for character '%2'", p, nm);
            return false;
          }
diff --git a/src/preproc/eqn/lex.cpp b/src/preproc/eqn/lex.cpp
index 03fb753e7..eec664e6f 100644
--- a/src/preproc/eqn/lex.cpp
+++ b/src/preproc/eqn/lex.cpp
@@ -1060,7 +1060,7 @@ void do_space()
   token_buffer += '\0';
   char *ptr;
   long n = strtol(token_buffer.contents(), &ptr, 10);
-  if (n == 0 && ptr == token_buffer.contents())
+  if (ptr == token_buffer.contents())
     lex_error("invalid argument '%1' to space primitive",
              token_buffer.contents());
   else
diff --git a/src/preproc/pic/tex.cpp b/src/preproc/pic/tex.cpp
index c6071af36..0b7a03d6c 100644
--- a/src/preproc/pic/tex.cpp
+++ b/src/preproc/pic/tex.cpp
@@ -426,7 +426,7 @@ void tpic_output::command(const char *s, const char 
*filename, int lineno)
     else {
       char *ptr;
       int temp = (int)strtol(p, &ptr, 10);
-      if (temp == 0 && ptr == p)
+      if (ptr == p)
        error_with_file_and_line(filename, lineno,
                                 "argument to '.ps' not an integer");
       else if (temp < 0)
diff --git a/src/preproc/refer/command.cpp b/src/preproc/refer/command.cpp
index b49e2be6f..56957c951 100644
--- a/src/preproc/refer/command.cpp
+++ b/src/preproc/refer/command.cpp
@@ -708,8 +708,7 @@ static int check_args(const char *types, const char *name,
       {
        char *ptr;
        long n = strtol(argv->s, &ptr, 10);
-       if ((n == 0 && ptr == argv->s)
-           || *ptr != '\0') {
+       if (ptr == argv->s || *ptr != '\0') {
          input_stack::error("argument %1 for command '%2' must be an integer",
                             argno + 1, name);
          return 0;
diff --git a/src/preproc/refer/ref.cpp b/src/preproc/refer/ref.cpp
index 80c63d7bd..5f6d5c63a 100644
--- a/src/preproc/refer/ref.cpp
+++ b/src/preproc/refer/ref.cpp
@@ -432,7 +432,7 @@ void reference::compute_sort_key()
     else if (csdigit(*sf)) {
       char *ptr;
       long l = strtol(sf, &ptr, 10);
-      if (l == 0 && ptr == sf)
+      if (ptr == sf)
        ;
       else {
        sf = ptr;
diff --git a/src/preproc/refer/refer.cpp b/src/preproc/refer/refer.cpp
index a5c291e3e..3f441a438 100644
--- a/src/preproc/refer/refer.cpp
+++ b/src/preproc/refer/refer.cpp
@@ -258,7 +258,7 @@ int main(int argc, char **argv)
          if (*++opt != '\0' && *opt != ',') {
            char *ptr;
            long n = strtol(opt, &ptr, 10);
-           if (n == 0 && ptr == opt) {
+           if (ptr == opt) {
              error("invalid integer '%1' in 'l' option argument", opt);
              opt = 0;
              break;
@@ -274,7 +274,7 @@ int main(int argc, char **argv)
          if (*opt != '\0') {
            char *ptr;
            long n = strtol(opt, &ptr, 10);
-           if (n == 0 && ptr == opt) {
+           if (ptr == opt) {
              error("invalid integer '%1' in 'l' option argument", opt);
              opt = 0;
              break;
@@ -330,7 +330,7 @@ int main(int argc, char **argv)
        {
          char *ptr;
          long n = strtol(opt, &ptr, 10);
-         if (n == 0 && ptr == opt) {
+         if (ptr == opt) {
            error("invalid integer '%1' in 't' option argument", opt);
            opt = 0;
            break;
diff --git a/src/utils/indxbib/indxbib.cpp b/src/utils/indxbib/indxbib.cpp
index 59c266780..956b85700 100644
--- a/src/utils/indxbib/indxbib.cpp
+++ b/src/utils/indxbib/indxbib.cpp
@@ -343,7 +343,7 @@ static void check_integer_arg(char opt, const char *arg, 
int min, int *res)
 {
   char *ptr;
   long n = strtol(arg, &ptr, 10);
-  if (n == 0 && ptr == arg)
+  if (ptr == arg)
     error("argument to -%1 not an integer", opt);
   else if (n < min)
     error("argument to -%1 must not be less than %2", opt, min);
diff --git a/src/utils/lkbib/lkbib.cpp b/src/utils/lkbib/lkbib.cpp
index 7bdf6cc24..8eb5195b7 100644
--- a/src/utils/lkbib/lkbib.cpp
+++ b/src/utils/lkbib/lkbib.cpp
@@ -73,7 +73,7 @@ int main(int argc, char **argv)
       {
        char *ptr;
        long n = strtol(optarg, &ptr, 10);
-       if (n == 0 && ptr == optarg) {
+       if (ptr == optarg) {
          error("bad integer '%1' in 't' option", optarg);
          break;
        }
diff --git a/src/utils/lookbib/lookbib.cpp b/src/utils/lookbib/lookbib.cpp
index 6469b313b..6071e6e5c 100644
--- a/src/utils/lookbib/lookbib.cpp
+++ b/src/utils/lookbib/lookbib.cpp
@@ -71,7 +71,7 @@ int main(int argc, char **argv)
       {
        char *ptr;
        long n = strtol(optarg, &ptr, 10);
-       if (n == 0 && ptr == optarg) {
+       if (ptr == optarg) {
          error("bad integer '%1' in 't' option", optarg);
          break;
        }
diff --git a/src/utils/tfmtodit/tfmtodit.cpp b/src/utils/tfmtodit/tfmtodit.cpp
index b5967963d..2d259b057 100644
--- a/src/utils/tfmtodit/tfmtodit.cpp
+++ b/src/utils/tfmtodit/tfmtodit.cpp
@@ -713,10 +713,7 @@ int main(int argc, char **argv)
       {
        char *ptr;
        long n = strtol(optarg, &ptr, 0);
-       if ((n == 0 && ptr == optarg)
-           || *ptr != '\0'
-           || n < 0
-           || n > UCHAR_MAX)
+       if (ptr == optarg || *ptr != '\0' || n < 0 || n > UCHAR_MAX)
          error("invalid skew character position '%1'", optarg);
        else
          skewchar = (int)n;
-- 
2.43.0

Attachment: signature.asc
Description: PGP signature


reply via email to

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