diff options
author | Pádraig Brady <P@draigBrady.com> | 2012-10-30 02:15:36 +0000 |
---|---|---|
committer | Pádraig Brady <P@draigBrady.com> | 2012-11-04 00:49:04 +0000 |
commit | 6108baa47e90aaefb83eb230e2e063906ca14e87 (patch) | |
tree | c05898f88e424ba2d4c2fd01ec0584255ea205c0 /src | |
parent | 1411022cf23d81bac8176b06008898439a2c1a59 (diff) | |
download | coreutils-6108baa47e90aaefb83eb230e2e063906ca14e87.tar.xz |
build: don't assume uintmax_t is 64 bits
This was not seen to be an issue in practise,
but to make the code more robust, don't assume
uintmax_t is 64 bits.
* src/factor.c (W_TYPE_SIZE): Define based on integer limits.
* src/make-prime-list.c (output_primes): Define format width
based on integer limits.
Diffstat (limited to 'src')
-rw-r--r-- | src/factor.c | 11 | ||||
-rw-r--r-- | src/make-prime-list.c | 10 |
2 files changed, 19 insertions, 2 deletions
diff --git a/src/factor.c b/src/factor.c index be5a36cd5..1d667175a 100644 --- a/src/factor.c +++ b/src/factor.c @@ -124,7 +124,16 @@ #if USE_LONGLONG_H /* Make definitions for longlong.h to make it do what it can do for us */ -# define W_TYPE_SIZE 64 /* bitcount for uintmax_t */ + +/* bitcount for uintmax_t */ +#if UINTMAX_MAX == UINT32_MAX +# define W_TYPE_SIZE 32 +#elif UINTMAX_MAX == UINT64_MAX +# define W_TYPE_SIZE 64 +#elif UINTMAX_MAX == UINT128_MAX +# define W_TYPE_SIZE 128 +#endif + # define UWtype uintmax_t # define UHWtype unsigned long int # undef UDWtype diff --git a/src/make-prime-list.c b/src/make-prime-list.c index 98eef8f59..a4c0a3b7b 100644 --- a/src/make-prime-list.c +++ b/src/make-prime-list.c @@ -78,12 +78,20 @@ output_primes (const struct prime *primes, unsigned nprimes) exit (EXIT_FAILURE); } +#if UINTMAX_MAX == UINT32_MAX +# define SZ "8" /* 8 hex digits. */ +#elif UINTMAX_MAX == UINT64_MAX +# define SZ "16" /* 16 hex digits. */ +#elif UINTMAX_MAX == UINT128_MAX +# define SZ "32" /* 32 hex digits. */ +#endif + for (i = 0, p = 2; i < nprimes; i++) { unsigned int d8 = i + 8 < nprimes ? primes[i + 8].p - primes[i].p : 0xff; if (255 < d8) /* this happens at 668221 */ abort (); - printf ("P (%2u, %3u, 0x%016"PRIxMAX"%s, 0x%016"PRIxMAX"%s) /* %d */\n", + printf ("P (%2u, %3u, 0x%0"SZ PRIxMAX"%s, 0x%0"SZ PRIxMAX"%s) /* %d */\n", primes[i].p - p, d8, primes[i].pinv, suffix, primes[i].lim, suffix, primes[i].p); |