aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPaul Eggert <eggert@cs.ucla.edu>2023-11-14 20:35:56 -0800
committerPaul Eggert <eggert@cs.ucla.edu>2023-11-14 20:38:24 -0800
commit23e26ed972fa157d5188d860545ea67037fc1935 (patch)
treeadb35a187d1dcf31000eb0d0faa72e523ec58ea2
parentpinky: fix string size calculation (diff)
downloadcoreutils-23e26ed972fa157d5188d860545ea67037fc1935.tar.gz
coreutils-23e26ed972fa157d5188d860545ea67037fc1935.zip
maint: DECIMAL_DIGIT_ACCUMULATE uses stdckdint.h
* src/system.h: Include <stdckdint.h>, since the new DECIMAL_DIGIT_ACCUMULATE uses it. Do not include stdckdint.h from files that also include system.h. (DECIMAL_DIGIT_ACCUMULATE): Omit last arg, which is no longer needed. Reimplement by using C23-style stdckdint.h’s ckd_mul and ckd_add, as that’s more standard and is more likely to generate better code.
-rw-r--r--src/cat.c1
-rw-r--r--src/copy.c1
-rw-r--r--src/csplit.c1
-rw-r--r--src/dd.c1
-rw-r--r--src/expand-common.c2
-rw-r--r--src/kill.c1
-rw-r--r--src/nl.c1
-rw-r--r--src/numfmt.c1
-rw-r--r--src/od.c1
-rw-r--r--src/pinky.c1
-rw-r--r--src/pr.c1
-rw-r--r--src/set-fields.c2
-rw-r--r--src/split.c1
-rw-r--r--src/system.h28
-rw-r--r--src/truncate.c1
-rw-r--r--src/unexpand.c2
-rw-r--r--src/uniq.c2
-rw-r--r--src/uptime.c1
-rw-r--r--src/wc.c1
-rw-r--r--src/who.c1
20 files changed, 12 insertions, 39 deletions
diff --git a/src/cat.c b/src/cat.c
index 9820b169b..e019faa8a 100644
--- a/src/cat.c
+++ b/src/cat.c
@@ -23,7 +23,6 @@
#include <config.h>
-#include <stdckdint.h>
#include <stdio.h>
#include <getopt.h>
#include <sys/types.h>
diff --git a/src/copy.c b/src/copy.c
index e9924fb49..f54253e5b 100644
--- a/src/copy.c
+++ b/src/copy.c
@@ -17,7 +17,6 @@
/* Extracted from cp.c and librarified by Jim Meyering. */
#include <config.h>
-#include <stdckdint.h>
#include <stdio.h>
#include <sys/ioctl.h>
#include <sys/types.h>
diff --git a/src/csplit.c b/src/csplit.c
index 32fb96bca..a5fd3f050 100644
--- a/src/csplit.c
+++ b/src/csplit.c
@@ -23,7 +23,6 @@
#include <getopt.h>
#include <sys/types.h>
#include <signal.h>
-#include <stdckdint.h>
#include "system.h"
diff --git a/src/dd.c b/src/dd.c
index 85ea26a3f..25e05b932 100644
--- a/src/dd.c
+++ b/src/dd.c
@@ -21,7 +21,6 @@
#include <ctype.h>
#include <sys/types.h>
#include <signal.h>
-#include <stdckdint.h>
#include "system.h"
#include "alignalloc.h"
diff --git a/src/expand-common.c b/src/expand-common.c
index 16240802d..7f2020278 100644
--- a/src/expand-common.c
+++ b/src/expand-common.c
@@ -194,7 +194,7 @@ parse_tab_stops (char const *stops)
}
/* Detect overflow. */
- if (!DECIMAL_DIGIT_ACCUMULATE (tabval, *stops - '0', uintmax_t))
+ if (!DECIMAL_DIGIT_ACCUMULATE (tabval, *stops - '0'))
{
size_t len = strspn (num_start, "0123456789");
char *bad_num = ximemdup0 (num_start, len);
diff --git a/src/kill.c b/src/kill.c
index 7eb5ef57a..2b463b310 100644
--- a/src/kill.c
+++ b/src/kill.c
@@ -17,7 +17,6 @@
/* Written by Paul Eggert. */
#include <config.h>
-#include <stdckdint.h>
#include <stdio.h>
#include <getopt.h>
#include <sys/types.h>
diff --git a/src/nl.c b/src/nl.c
index 539c53f08..7845efb6a 100644
--- a/src/nl.c
+++ b/src/nl.c
@@ -19,7 +19,6 @@
#include <config.h>
-#include <stdckdint.h>
#include <stdio.h>
#include <sys/types.h>
#include <getopt.h>
diff --git a/src/numfmt.c b/src/numfmt.c
index 7b53c87e4..a5bdd2f4f 100644
--- a/src/numfmt.c
+++ b/src/numfmt.c
@@ -18,7 +18,6 @@
#include <ctype.h>
#include <float.h>
#include <getopt.h>
-#include <stdckdint.h>
#include <stdio.h>
#include <sys/types.h>
#include <langinfo.h>
diff --git a/src/od.c b/src/od.c
index 951e88652..8a976aaf2 100644
--- a/src/od.c
+++ b/src/od.c
@@ -19,7 +19,6 @@
#include <config.h>
#include <ctype.h>
-#include <stdckdint.h>
#include <stdio.h>
#include <getopt.h>
#include <sys/types.h>
diff --git a/src/pinky.c b/src/pinky.c
index 82b2d842e..d1917acd7 100644
--- a/src/pinky.c
+++ b/src/pinky.c
@@ -20,7 +20,6 @@
#include <ctype.h>
#include <getopt.h>
#include <pwd.h>
-#include <stdckdint.h>
#include <stdio.h>
#include <sys/types.h>
diff --git a/src/pr.c b/src/pr.c
index 7e680e23c..c9ffa2c75 100644
--- a/src/pr.c
+++ b/src/pr.c
@@ -311,7 +311,6 @@
#include <ctype.h>
#include <getopt.h>
-#include <stdckdint.h>
#include <sys/types.h>
#include "system.h"
#include "fadvise.h"
diff --git a/src/set-fields.c b/src/set-fields.c
index a524b7fa4..1433e4fd9 100644
--- a/src/set-fields.c
+++ b/src/set-fields.c
@@ -245,7 +245,7 @@ set_fields (char const *fieldstr, unsigned int options)
lhs_specified = 1;
/* Detect overflow. */
- if (!DECIMAL_DIGIT_ACCUMULATE (value, *fieldstr - '0', uintmax_t)
+ if (!DECIMAL_DIGIT_ACCUMULATE (value, *fieldstr - '0')
|| value == UINTMAX_MAX)
{
/* In case the user specified -c$(echo 2^64|bc),22,
diff --git a/src/split.c b/src/split.c
index f56a144a6..868d94b41 100644
--- a/src/split.c
+++ b/src/split.c
@@ -22,7 +22,6 @@
#include <config.h>
#include <ctype.h>
-#include <stdckdint.h>
#include <stdio.h>
#include <getopt.h>
#include <signal.h>
diff --git a/src/system.h b/src/system.h
index 8c2a4fd8b..c5556ba39 100644
--- a/src/system.h
+++ b/src/system.h
@@ -67,6 +67,7 @@
# define makedev(maj, min) mkdev (maj, min)
#endif
+#include <stdckdint.h>
#include <stddef.h>
#include <string.h>
#include <errno.h>
@@ -544,26 +545,13 @@ is_nul (void const *buf, size_t length)
return memcmp (buf, p, length) == 0;
}
-/* If 10*Accum + Digit_val is larger than the maximum value for Type,
- then don't update Accum and return false to indicate it would
- overflow. Otherwise, set Accum to that new value and return true.
- Verify at compile-time that Type is Accum's type, and that Type is
- unsigned. Accum must be an object, so that we can take its
- address. Accum and Digit_val may be evaluated multiple times.
-
- The "Added check" below is not strictly required, but it causes GCC
- to return a nonzero exit status instead of merely a warning
- diagnostic, and that is more useful. */
-
-#define DECIMAL_DIGIT_ACCUMULATE(Accum, Digit_val, Type) \
- ( \
- (void) (&(Accum) == (Type *) nullptr), /* The type matches. */ \
- verify_expr (! TYPE_SIGNED (Type), /* The type is unsigned. */ \
- (((Type) -1 / 10 < (Accum) \
- || (Type) ((Accum) * 10 + (Digit_val)) < (Accum)) \
- ? false \
- : (((Accum) = (Accum) * 10 + (Digit_val)), true))) \
- )
+/* Set Accum = 10*Accum + Digit_val and return true, where Accum is an
+ integer object and Digit_val an integer expression. However, if
+ the result overflows, set Accum to an unspecified value and return
+ false. Accum and Digit_val may be evaluated multiple times. */
+
+#define DECIMAL_DIGIT_ACCUMULATE(Accum, Digit_val) \
+ (!ckd_mul (&(Accum), Accum, 10) && !ckd_add (&(Accum), Accum, Digit_val))
static inline void
emit_stdin_note (void)
diff --git a/src/truncate.c b/src/truncate.c
index 040172c4d..84d9f9791 100644
--- a/src/truncate.c
+++ b/src/truncate.c
@@ -22,7 +22,6 @@
#include <config.h> /* sets _FILE_OFFSET_BITS=64 etc. */
#include <ctype.h>
-#include <stdckdint.h>
#include <stdio.h>
#include <getopt.h>
#include <sys/types.h>
diff --git a/src/unexpand.c b/src/unexpand.c
index 46e943365..279c600b0 100644
--- a/src/unexpand.c
+++ b/src/unexpand.c
@@ -300,7 +300,7 @@ main (int argc, char **argv)
tabval = 0;
have_tabval = true;
}
- if (!DECIMAL_DIGIT_ACCUMULATE (tabval, c - '0', uintmax_t))
+ if (!DECIMAL_DIGIT_ACCUMULATE (tabval, c - '0'))
error (EXIT_FAILURE, 0, _("tab stop value is too large"));
break;
}
diff --git a/src/uniq.c b/src/uniq.c
index 7dc0c999a..9d013db68 100644
--- a/src/uniq.c
+++ b/src/uniq.c
@@ -565,7 +565,7 @@ main (int argc, char **argv)
if (skip_field_option_type == SFO_NEW)
skip_fields = 0;
- if (!DECIMAL_DIGIT_ACCUMULATE (skip_fields, optc - '0', size_t))
+ if (!DECIMAL_DIGIT_ACCUMULATE (skip_fields, optc - '0'))
skip_fields = SIZE_MAX;
skip_field_option_type = SFO_OBSOLETE;
diff --git a/src/uptime.c b/src/uptime.c
index 01b69d164..55ef2d436 100644
--- a/src/uptime.c
+++ b/src/uptime.c
@@ -18,7 +18,6 @@
#include <config.h>
-#include <stdckdint.h>
#include <stdio.h>
#include <sys/types.h>
diff --git a/src/wc.c b/src/wc.c
index 43170cf9b..5542ea8fe 100644
--- a/src/wc.c
+++ b/src/wc.c
@@ -20,7 +20,6 @@
#include <config.h>
#include <ctype.h>
-#include <stdckdint.h>
#include <stdio.h>
#include <getopt.h>
#include <sys/types.h>
diff --git a/src/who.c b/src/who.c
index c235f943d..1440e9b7e 100644
--- a/src/who.c
+++ b/src/who.c
@@ -25,7 +25,6 @@
#include <config.h>
#include <getopt.h>
-#include <stdckdint.h>
#include <stdio.h>
#include <sys/types.h>