]> git.ipfire.org Git - thirdparty/coreutils.git/commitdiff
od: check sign bit more often
authorPaul Eggert <eggert@cs.ucla.edu>
Sat, 28 Jun 2025 22:04:30 +0000 (15:04 -0700)
committerPaul Eggert <eggert@cs.ucla.edu>
Sun, 29 Jun 2025 04:00:41 +0000 (21:00 -0700)
* src/od.c (read_char, dump_strings, main):
Instead of testing for an exact negative number,
just look at the sign bit.  This is a very minor tweak.

src/od.c

index 847eb6d74353a72863a3e986c3f6afc34f018521..6d9c5d06977b831356293f2f340568096d0d1f5a 100644 (file)
--- a/src/od.c
+++ b/src/od.c
@@ -1314,15 +1314,9 @@ read_char (int *c)
 
   *c = EOF;
 
-  while (in_stream != nullptr) /* EOF.  */
+  while (in_stream && (*c = fgetc (in_stream)) < 0)
     {
-      *c = fgetc (in_stream);
-
-      if (*c != EOF)
-        break;
-
       ok &= check_and_close (errno);
-
       ok &= open_next_file ();
     }
 
@@ -1568,7 +1562,7 @@ dump_strings (void)
             }
         }
 
-      if (c == -1 || i - !c < string_min)
+      if (c < 0 || i - !c < string_min)
         continue;
 
       buf[i] = 0;
@@ -2009,7 +2003,7 @@ main (int argc, char **argv)
 
 cleanup:
 
-  if (have_read_stdin && fclose (stdin) == EOF)
+  if (have_read_stdin && fclose (stdin) < 0)
     error (EXIT_FAILURE, errno, _("standard input"));
 
   return ok ? EXIT_SUCCESS : EXIT_FAILURE;