summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJim Meyering <meyering@redhat.com>2012-10-04 20:27:31 +0200
committerJim Meyering <meyering@redhat.com>2012-10-04 21:33:06 +0200
commitd836ea73400d66ecfa5ecf1287b983976342c4c4 (patch)
tree737b3b6651634bb02f02b38c45752c421b5625c3 /src
parentc6369e9004be56d427f0cc0d51d7009d727e061c (diff)
downloadcoreutils-d836ea73400d66ecfa5ecf1287b983976342c4c4.tar.xz
maint: make-prime-list: syntax conventions; be robust for large N
* src/make-prime-list.c: Insert spaces before parens. (main): Abort if the 8-delta value ever exceeds 255.
Diffstat (limited to 'src')
-rw-r--r--src/make-prime-list.c18
1 files changed, 10 insertions, 8 deletions
diff --git a/src/make-prime-list.c b/src/make-prime-list.c
index b18b0e5f0..49db2bac0 100644
--- a/src/make-prime-list.c
+++ b/src/make-prime-list.c
@@ -64,9 +64,9 @@ output_primes (const struct prime *primes, unsigned nprimes)
puts ("/* Generated file -- DO NOT EDIT */\n");
- if (sizeof(uintmax_t) <= sizeof(unsigned long))
+ if (sizeof (uintmax_t) <= sizeof (unsigned long))
suffix = "UL";
- else if (sizeof(uintmax_t) <= sizeof(unsigned long long))
+ else if (sizeof (uintmax_t) <= sizeof (unsigned long long))
suffix = "ULL";
else
{
@@ -74,13 +74,15 @@ output_primes (const struct prime *primes, unsigned nprimes)
exit (EXIT_FAILURE);
}
-#define SZ (int)(2*sizeof(uintmax_t))
+#define SZ (int)(2*sizeof (uintmax_t))
for (i = 0, p = 2; i < nprimes; i++)
{
- printf ("P(%2u, %3u, 0x%0*jx%s, 0x%0*jx%s) /* %d */\n",
- primes[i].p - p,
- (i + 8 < nprimes) ? primes[i + 8].p - primes[i].p : 0xff,
+ 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%0*jx%s, 0x%0*jx%s) /* %d */\n",
+ primes[i].p - p, d8,
SZ, primes[i].pinv, suffix,
SZ, primes[i].lim, suffix, primes[i].p);
p = primes[i].p;
@@ -111,7 +113,7 @@ output_primes (const struct prime *primes, unsigned nprimes)
static void *
xalloc (size_t s)
{
- void *p = malloc(s);
+ void *p = malloc (s);
if (p)
return p;
@@ -136,7 +138,7 @@ main (int argc, char **argv)
"Produces a list of odd primes <= LIMIT\n", argv[0]);
return EXIT_FAILURE;
}
- limit = atoi(argv[1]);
+ limit = atoi (argv[1]);
if (limit < 3)
exit (EXIT_SUCCESS);