From 3de797b535609850203124b2d63c257517f97b13 Mon Sep 17 00:00:00 2001 From: Jim Meyering Date: Sat, 31 Dec 1994 17:33:56 +0000 Subject: Indent. Add deactivated assertions. --- src/factor.c | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) (limited to 'src/factor.c') 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 #include #include +#include + +#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