* src/system.h: Include stdcountof.h
* src/diff.c (main, compare_prepped_files): Use it.
* src/sdiff.c: Likewise.
---
 src/diff.c   | 6 +++---
 src/sdiff.c  | 2 +-
 src/system.h | 1 +
 3 files changed, 5 insertions(+), 4 deletions(-)

diff --git a/src/diff.c b/src/diff.c
index a765e31..002a22d 100644
--- a/src/diff.c
+++ b/src/diff.c
@@ -656,7 +656,7 @@ main (int argc, char **argv)
 
       case LINE_FORMAT_OPTION:
        specify_style (OUTPUT_IFDEF);
-       for (int i = 0; i < sizeof line_format / sizeof line_format[0]; i++)
+       for (int i = 0; i < countof (line_format); i++)
          specify_value (&line_format[i], optarg, "--line-format");
        break;
 
@@ -824,7 +824,7 @@ main (int argc, char **argv)
 
   if (output_style == OUTPUT_IFDEF)
     {
-      for (int i = 0; i < sizeof line_format / sizeof line_format[0]; i++)
+      for (int i = 0; i < countof (line_format); i++)
         if (!line_format[i])
           line_format[i] = "%l\n";
       if (!group_format[OLD])
@@ -1323,7 +1323,7 @@ compare_prepped_files (struct comparison const *parent,
        major (cmp->file[1].stat.st_rdev),
        minor (cmp->file[1].stat.st_rdev)
       };
-      enum { n_num = sizeof num / sizeof *num };
+      enum { n_num = countof (num) };
       char numbuf[n_num][INT_BUFSIZE_BOUND (intmax_t)];
       for (int i = 0; i < n_num; i++)
        sprintf (numbuf[i], "%"PRIdMAX, num[i]);
diff --git a/src/sdiff.c b/src/sdiff.c
index 786d904..e593f7a 100644
--- a/src/sdiff.c
+++ b/src/sdiff.c
@@ -93,7 +93,7 @@ static int const sigs[] = {
 };
 enum
   {
-    NUM_SIGS = sizeof sigs / sizeof *sigs,
+    NUM_SIGS = countof (sigs),
     handler_index_of_SIGINT = NUM_SIGS - 1
   };
 
diff --git a/src/system.h b/src/system.h
index c118339..98aee12 100644
--- a/src/system.h
+++ b/src/system.h
@@ -49,6 +49,7 @@
 #include <locale.h>
 #include <stdbit.h>
 #include <stdckdint.h>
+#include <stdcountof.h>
 #include <stddef.h>
 #include <string.h>
 
-- 
2.55.0




Reply via email to