summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRoland McGrath <roland@gnu.org>1994-06-28 22:12:24 +0000
committerRoland McGrath <roland@gnu.org>1994-06-28 22:12:24 +0000
commita5875dbe1e5a0d7e1722ab1b47390f2227820731 (patch)
tree81804826b96b24abbe55fe545e017a308b630234
parent02c37e74a1eac5eb4c3d122e01ca2b2a69441b25 (diff)
Formerly primes.c.~10~
-rw-r--r--proc/primes.c10
1 files changed, 7 insertions, 3 deletions
diff --git a/proc/primes.c b/proc/primes.c
index a0be5acb..8ba433d6 100644
--- a/proc/primes.c
+++ b/proc/primes.c
@@ -17,6 +17,7 @@
#include <stdlib.h>
#include <string.h>
+#include <assert.h>
/* Return the next prime greater than or equal to N. */
int
@@ -49,9 +50,9 @@ nextprime (int n)
/* Alloc */
p = q[l-1] * q[l-1];
- m = alloca (sizeof (int) * p);
- bzero (m, sizeof (int) * p);
-
+ m = calloc (p, sizeof (int));
+ assert (m);
+
/* Sieve */
for (i = 0; i < l; i++)
for (j = q[i] * 2; j < p; j += q[i])
@@ -63,11 +64,14 @@ nextprime (int n)
if (l == k)
{
q = realloc (q, k * sizeof (int) * 2);
+ assert (q);
k *= 2;
}
if (!m[i])
q[l++] = i;
}
+
+ free (m);
}
/* Search */