summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJim Meyering <jim@meyering.net>1994-12-31 17:33:56 +0000
committerJim Meyering <jim@meyering.net>1994-12-31 17:33:56 +0000
commit3de797b535609850203124b2d63c257517f97b13 (patch)
treed159881a1d87abd91c52b6a9cbf17802d8b1f463 /src
parent14842c9a59f38ed2a47a271b8b3c5818e72f5055 (diff)
downloadcoreutils-3de797b535609850203124b2d63c257517f97b13.tar.xz
Indent.
Add deactivated assertions.
Diffstat (limited to 'src')
-rw-r--r--src/factor.c24
1 files changed, 18 insertions, 6 deletions
diff --git a/src/factor.c b/src/factor.c
index 21495c00d..f2d26976d 100644
--- a/src/factor.c
+++ b/src/factor.c
@@ -20,6 +20,9 @@
#include <config.h>
#include <stdio.h>
#include <sys/types.h>
+#include <assert.h>
+
+#define NDEBUG 1
#include "system.h"
#include "version.h"
@@ -27,9 +30,13 @@
#include "error.h"
#include "readtokens.h"
-/* FIXME */
+/* Token delimiters when reading from a file. */
#define DELIM "\n\t "
+/* FIXME: if this program is ever modified to factor integers larger
+ than 2^128, this (and the algorithm :-) will have to change. */
+#define MAX_N_FACTORS 128
+
/* The name this program was run with. */
char *program_name;
@@ -70,6 +77,7 @@ factor (n0, max_n_factors, factors)
while (n % 2 == 0)
{
+ assert (n_factors < max_n_factors);
factors[n_factors++] = 2;
n /= 2;
}
@@ -85,12 +93,16 @@ factor (n0, max_n_factors, factors)
{
while (n % d == 0)
{
+ assert (n_factors < max_n_factors);
factors[n_factors++] = d;
n /= d;
}
}
if (n != 1 || n0 == 1)
- factors[n_factors++] = n;
+ {
+ assert (n_factors < max_n_factors);
+ factors[n_factors++] = n;
+ }
return n_factors;
}
@@ -99,12 +111,12 @@ static void
print_factors (n)
unsigned long int n;
{
- unsigned long int factors[64];
+ unsigned long int factors[MAX_N_FACTORS];
int n_factors;
int i;
- n_factors = factor (n, 64, factors);
- for (i=0; i<n_factors; i++)
+ n_factors = factor (n, MAX_N_FACTORS, factors);
+ for (i = 0; i < n_factors; i++)
printf (" %lu\n", factors[i]);
putchar ('\n');
}
@@ -124,7 +136,7 @@ do_stdin ()
&tokenbuffer);
if (token_length < 0)
break;
- /* FIXME: Use strtoul. */
+ /* FIXME: Use strtoul, not atoi. */
print_factors ((unsigned long) atoi (tokenbuffer.buffer));
}
free (tokenbuffer.buffer);